Giter VIP home page Giter VIP logo

dbq's People

Contributors

cmiksche avatar patrickdappollonio avatar propersam avatar rocketlaunchr-cto avatar

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

dbq's Issues

TODO:

For JSON columns, give option to unmarshal to map[string]interface{} or custom object.

v3 Relations

  1. If struct contains field which is struct (pointer or concrete), then fetch.
  2. If struct contains field which is slice of struct, then fetch from join table
  3. Ability to escape sql injection protection: "Dangerous"

Postgres/pq bulk insert syntax issue

Dependencies:

	"github.com/gin-gonic/gin"
	_ "github.com/lib/pq"
	"github.com/rocketlaunchr/dbq/v2"
	"net/http"

Code of issue:

	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 ๐Ÿ‘

Congratulations and benchmarks project

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!

Add support for PostgreSQL arrays

Problem

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})

Expected behavior of this code

It will create statement

INSERT INTO example (bytes) VALUES ({0, 1, 2, 3, 4});

which will correctly insert array into the table.

Actual behavior

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.

check performance difference

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.

todo

  • add example of how Ph function works
  • add example to readme of how postunmarshaler works. It is currently a "hidden" feature.
  • update godocs links to v2
  • Note that v1 is deprecated and no updates will be done to it

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.