rocketlaunchr / dbq Goto Github PK
View Code? Open in Web Editor NEWZero boilerplate database operations for Go
License: Other
Zero boilerplate database operations for Go
License: Other
For JSON columns, give option to unmarshal to map[string]interface{} or custom object.
v3 Relations
"github.com/gin-gonic/gin"
_ "github.com/lib/pq"
"github.com/rocketlaunchr/dbq/v2"
"net/http"
psqlInfo := fmt.Sprintf("%s://%s:%s@%s:%s/%s?sslmode=%s",
"postgres", "postgres", "postgres", "localhost", "5432", "", "disable",
)
db, _ := sql.Open("postgres", psqlInfo)
type Row struct {
Username string
Password string
}
users := []interface{}{
dbq.Struct(Row{"John", "abc123"}),
dbq.Struct(Row{"Mark", "abc123"}),
dbq.Struct(Row{"David", "abc123"}),
}
stmt := dbq.INSERTStmt("accounts", []string{"username", "password"}, len(users))
_, err := dbq.E(ctx, db, stmt, nil, users) // <- always results in syntax error
if err != nil {
panic(err) // <- pq: syntax error at or near ","
return
}
Output: pq: syntax error at or near ","
Consistently results in a syntax error.
If the cause is the above code, let me know ๐
My happiest congratulations on this project! Very good!
Can I ask you for an opinion on this benchmark project?
What do you think about adding dbq
too?
It's very easy, just copy one of these files and edit it with dbq
code.
I found dbq
today and I still need to understand it.
Again, thanks for your amazing project!
PostgreSQL has support for arrays. For example, we have this table:
CREATE TABLE example (
bytes BYTEA -- byte array
);
In order to insert data into it, we need this query:
INSERT INTO example (bytes) VALUES ({0, 1, 2, 3, 4});
or
INSERT INTO example (bytes) VALUES (ARRAY[0, 1, 2, 3, 4]);
Using dbq that code should've looked like:
stmt := dbq.INSERT("example", []string{"bytes"}, 1, dbq.PostgreSQL)
_, _ = dbq.E(context.Background(), db, stmt, nil, []byte{0, 1, 2, 3, 4})
It will create statement
INSERT INTO example (bytes) VALUES ({0, 1, 2, 3, 4});
which will correctly insert array into the table.
It creates statement
INSERT INTO example (bytes) VALUES (0, 1, 2, 3, 4);
which is invalid and doesn't work because each array element is treated like separate field.
I've tried wrapping byte array into []interface{}
and even [][]interface{}
- it doesn't resolve the issue, dbq still treats arrays as lists of fields.
Can you benchmark and check the performance difference between
the speed-up
branch (which will definitely be merged to master)
and return-slice-of-struct
branch (which will probably go to v2).
The difference is that when you provide a ConcreteStruct, the speed-up
branch returns []interface{}
containing *struct
whilst return-slice-of-struct
returns []*struct
return-slice-of-struct
uses fore reflect
pkg and is not backward compatible.
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.