Code Monkey home page Code Monkey logo

dbr's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dbr's Issues

Unmarshaling joins?

Nice work! I was just playing with this and couldn't work out how to unmarshal joined tables. For example, in your example:

sess.Select("*").From("suggestions").
  Join("subdomains", "suggestions.subdomain_id = subdomains.id")

How would you store the query result into a struct using .Load(&suggestions) that contains []subdomain field?

Wrong placeholder count error on INSERT ... FORMAT CSV

Here's the case.

Prepare some db and test if it's working:

create table test (
     date DateTime,
     event String
) engine MergeTree() order by date;

insert into test format CSV
2021-01-01 00:00:00,click
2021-01-01 00:00:00,?

select * from test;

Run go code:

func TestIssue(t *testing.T) {
	conn, _ := dbr.Open("clickhouse", "http://user:pass@localhost:8123/db", nil)

	query := `insert into test (date, event) format CSV
2021-01-01 00:00:00,click
2021-01-01 00:00:00,?`

	_, err := conn.Exec(query)
	fmt.Println(err) //clickhouse: wrong placeholder count

	query = `insert into test (date, event) format CSV
"2021-01-01 00:00:00","click"
"2021-01-01 00:00:00","?"`

	_, err = conn.Exec(query)
	fmt.Println(err) //clickhouse: wrong placeholder count
}

I expect to get no errors here, because every query I run is perfectly valid.

can't use with go modules

When I'll try to get latest stable version of mailru/dbr:

module some/project

require (
	...
	github.com/mailru/dbr v0.0.0-20180825184916-bee39f330c3b
	...
)

Problem is in release-tag naming:

vX.Y with vX.Y.Z

ReturnStrings issue with quoted stings

Prepare db:

create table test
(
    date  DateTime,
    event String
) engine MergeTree() order by date;

Run go code:

func TestIssue2(t *testing.T) {
	conn, _ := dbr.Open("clickhouse", "http://user:pass@localhost:8123/db", nil)

	conn.Exec("truncate table test")

	// 4 rows
	query := `insert into test (date, event) values 
	   ('2021-01-01 00:00:00', 'click'),
       ('2021-01-01 01:00:00', '"" '),
       ('2021-01-01 02:00:00', '"with quotes" 1'),
       ('2021-01-01 02:00:00', '"with quotes" 2')`

	conn.Exec(query)

	sess := conn.NewSession(nil)

	res, err := sess.Select("event").From("test").ReturnStrings()
	fmt.Println(err)
	fmt.Println(len(res))
	// 2 rows
}

I expect that it will be 4 rows in result.

structs one-to-many relation

is it possible to create structures one to many
db: clickhouse 20.3.5.21

example:

type DomainType struct {
	Id        string      `json:"id"`
	Domain    string      `json:"domain"`
	Date      time.Time   `json:"date"`
	Redirects []*Redirect `json:"redirects"`
}

type Redirect struct {
	Id             sql.NullString `json:"id"`
	RedirectDomain sql.NullString `json:"redirect_domain" db:"redirect_domain"`
	Date           sql.NullTime   `json:"redirect_date" db:"date"`
}

end query:

var result []entity.DomainType
query := sess.Select("*").From("domain").LeftJoin("domain_redirect", "domain.id = domain_redirect.id")

query.LoadStructs(&result)

if this is possible then tell me how, I'm begginer to the golang

How to log and get query?

I want to get the following data:

  • Prepared statement.
  • Passed values.
  • Query with bind value.

Currently, I find no way to do these things.

Support for "FOR UPDATE SKIP LOCKED"

Is there any way to use the select builder to do something like:

SELECT *
FROM "mytable"
WHERE "state" = ? AND "queue" = ?
ORDER BY "created_on"
LIMIT 1
FOR UPDATE SKIP LOCKED

The closest I get is:

dbr.From("mytable").
	Where("state = ? and queue = ?", statusQueued, queue).
	OrderBy("created_on").
	Limit(1).
	ForUpdate()

But that misses the last (essential) part SKIP LOCKEDโ€ฆ

Nested Statements

I'm trying to run the following sql query, but want to use the query builder:

SELECT * FROM project_user WHERE project_id IN (SELECT project_id FROM project_user WHERE user_id = 1)

What I have so far:

innerBuilder := sess.Select("project_id").From("project_user").Where("user_id = ?", userID)
builder := sess.Select("*").From("project_user").Where("project_id IN ???")

But I don't know how to put the innerBuilder into the outer statement, how can I do that?

Port 9000 is for clickhouse-client program

Hello guys, I don't understand what I'm doing wrong, this IS a client program after all.
With sqlx I'm using "tcp://host:9000" and it works correctly, we're evaluating using dbr instead but it complains:
unsupported protocol scheme "tcp"

I've tried a bunch of things already, setting only host/default it complains until I call Load:
panic: runtime error: index out of range [0] with length 0
Actually, it doesn't matter what I put as host in Open(), I even tried with foo.var as host and it ran all the way to the call of query.Load() xD

I tried with and without user, different ports, https scheme, I don't know what else to try, I haven't found any different examples here or otherwise.

Any suggestions?

package main

import (
	"log"

	"github.com/mailru/dbr"
	_ "github.com/mailru/go-clickhouse"
)

func main() {
	connect, err := dbr.Open("clickhouse", "http://default@host:9000/default", nil)
	if err != nil {
		log.Fatalln(err)
	}
	sess := connect.NewSession(nil)
	query := sess.Select("start").From("sometable").Where(dbr.Eq("id", 3))

	var result []struct {
		Start string `db:"start"`
	}
	count, err := query.Load(&result)
	if err != nil {
		log.Fatalln(err)
	}

	log.Printf("count %d  select %v\n", count, result)
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.