mailru / dbr Goto Github PK
View Code? Open in Web Editor NEWAdditions to Go's database/sql for super fast performance and convenience. (fork of gocraft/dbr)
License: MIT License
Additions to Go's database/sql for super fast performance and convenience. (fork of gocraft/dbr)
License: MIT License
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?
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.
Could you please create a new GitHub release or just version tag, because dependency managers like the official dep (https://github.com/golang/dep) use those versions by default.
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
Please update the document.
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.
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
The readme mentions it is a fork. It helps if the differences are specified.
I want to get the following data:
Currently, I find no way to do these things.
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
โฆ
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?
The Open interface only has the DSN option, and there is no place to set the header.
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)
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.