diff --git a/README.md b/README.md index 0d71592..91b57d6 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,20 @@ # sqlx -[![Build Status](https://travis-ci.org/jmoiron/sqlx.svg?branch=master)](https://travis-ci.org/jmoiron/sqlx) [![Coverage Status](https://coveralls.io/repos/github/jmoiron/sqlx/badge.svg?branch=master)](https://coveralls.io/github/jmoiron/sqlx?branch=master) [![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/jmoiron/sqlx) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/jmoiron/sqlx/master/LICENSE) +[![Build Status](https://travis-ci.org/jmoiron/sqlx.svg?branch=master)](https://travis-ci.org/jmoiron/sqlx) [![Coverage Status](https://coveralls.io/repos/github/jmoiron/sqlx/badge.svg?branch=master)](https://coveralls.io/github/jmoiron/sqlx?branch=master) [![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/acheong08/squealx) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/jmoiron/sqlx/master/LICENSE) sqlx is a library which provides a set of extensions on go's standard -`database/sql` library. The sqlx versions of `sql.DB`, `sql.TX`, `sql.Stmt`, +`database/sql` library. The sqlx versions of `sql.DB`, `sql.TX`, `sql.Stmt`, et al. all leave the underlying interfaces untouched, so that their interfaces -are a superset on the standard ones. This makes it relatively painless to +are a superset on the standard ones. This makes it relatively painless to integrate existing codebases using database/sql with sqlx. Major additional concepts are: -* Marshal rows into structs (with embedded struct support), maps, and slices -* Named parameter support including prepared statements -* `Get` and `Select` to go quickly from query to struct/slice +- Marshal rows into structs (with embedded struct support), maps, and slices +- Named parameter support including prepared statements +- `Get` and `Select` to go quickly from query to struct/slice -In addition to the [godoc API documentation](http://godoc.org/github.com/jmoiron/sqlx), +In addition to the [godoc API documentation](http://godoc.org/github.com/acheong08/squealx), there is also some [user documentation](http://jmoiron.github.io/sqlx/) that explains how to use `database/sql` along with sqlx. @@ -22,16 +22,16 @@ explains how to use `database/sql` along with sqlx. 1.3.0: -* `sqlx.DB.Connx(context.Context) *sqlx.Conn` -* `sqlx.BindDriver(driverName, bindType)` -* support for `[]map[string]interface{}` to do "batch" insertions -* allocation & perf improvements for `sqlx.In` +- `sqlx.DB.Connx(context.Context) *sqlx.Conn` +- `sqlx.BindDriver(driverName, bindType)` +- support for `[]map[string]interface{}` to do "batch" insertions +- allocation & perf improvements for `sqlx.In` DB.Connx returns an `sqlx.Conn`, which is an `sql.Conn`-alike consistent with sqlx's wrapping of other types. `BindDriver` allows users to control the bindvars that sqlx will use for drivers, -and add new drivers at runtime. This results in a very slight performance hit +and add new drivers at runtime. This results in a very slight performance hit when resolving the driver into a bind type (~40ns per call), but it allows users to specify what bindtype their driver uses even when sqlx has not been updated to know about it by default. @@ -39,14 +39,14 @@ to know about it by default. ### Backwards Compatibility Compatibility with the most recent two versions of Go is a requirement for any -new changes. Compatibility beyond that is not guaranteed. +new changes. Compatibility beyond that is not guaranteed. -Versioning is done with Go modules. Breaking changes (eg. removing deprecated API) +Versioning is done with Go modules. Breaking changes (eg. removing deprecated API) will get major version number bumps. ## install - go get github.com/jmoiron/sqlx + go get github.com/acheong08/squealx ## issues @@ -57,17 +57,16 @@ Row headers can be ambiguous (`SELECT 1 AS a, 2 AS a`), and the result of SELECT a.id, a.name, b.id, b.name FROM foos AS a JOIN foos AS b ON a.parent = b.id; ``` -making a struct or map destination ambiguous. Use `AS` in your queries -to give columns distinct names, `rows.Scan` to scan them manually, or +making a struct or map destination ambiguous. Use `AS` in your queries +to give columns distinct names, `rows.Scan` to scan them manually, or `SliceScan` to get a slice of results. ## usage -Below is an example which shows some common use cases for sqlx. Check -[sqlx_test.go](https://github.com/jmoiron/sqlx/blob/master/sqlx_test.go) for more +Below is an example which shows some common use cases for sqlx. Check +[sqlx_test.go](https://github.com/acheong08/squealx/blob/master/sqlx_test.go) for more usage. - ```go package main @@ -75,9 +74,9 @@ import ( "database/sql" "fmt" "log" - + _ "github.com/lib/pq" - "github.com/jmoiron/sqlx" + "github.com/acheong08/squealx" ) var schema = ` @@ -116,7 +115,7 @@ func main() { // exec the schema or fail; multi-statement Exec behavior varies between // database drivers; pq will exec them all, sqlite3 won't, ymmv db.MustExec(schema) - + tx := db.MustBegin() tx.MustExec("INSERT INTO person (first_name, last_name, email) VALUES ($1, $2, $3)", "Jason", "Moiron", "jmoiron@jmoiron.net") tx.MustExec("INSERT INTO person (first_name, last_name, email) VALUES ($1, $2, $3)", "John", "Doe", "johndoeDNE@gmail.net") @@ -150,7 +149,7 @@ func main() { return } usa, singsing, honkers := places[0], places[1], places[2] - + fmt.Printf("%#v\n%#v\n%#v\n", usa, singsing, honkers) // Place{Country:"United States", City:sql.NullString{String:"New York", Valid:true}, TelCode:1} // Place{Country:"Singapore", City:sql.NullString{String:"", Valid:false}, TelCode:65} @@ -163,7 +162,7 @@ func main() { err := rows.StructScan(&place) if err != nil { log.Fatalln(err) - } + } fmt.Printf("%#v\n", place) } // Place{Country:"United States", City:sql.NullString{String:"New York", Valid:true}, TelCode:1} @@ -172,7 +171,7 @@ func main() { // Named queries, using `:name` as the bindvar. Automatic bindvar support // which takes into account the dbtype based on the driverName on sqlx.Open/Connect - _, err = db.NamedExec(`INSERT INTO person (first_name,last_name,email) VALUES (:first,:last,:email)`, + _, err = db.NamedExec(`INSERT INTO person (first_name,last_name,email) VALUES (:first,:last,:email)`, map[string]interface{}{ "first": "Bin", "last": "Smuth", @@ -186,10 +185,10 @@ func main() { // as the name -> db mapping, so struct fields are lowercased and the `db` tag // is taken into consideration. rows, err = db.NamedQuery(`SELECT * FROM person WHERE first_name=:first_name`, jason) - - + + // batch insert - + // batch insert with structs personStructs := []Person{ {FirstName: "Ardie", LastName: "Savea", Email: "asavea@ab.co.nz"}, diff --git a/bind.go b/bind.go index 21de94b..2c63f19 100644 --- a/bind.go +++ b/bind.go @@ -9,7 +9,7 @@ import ( "strings" "sync" - "github.com/jmoiron/sqlx/reflectx" + "github.com/acheong08/squealx/reflectx" ) // Bindvar types supported by Rebind, BindMap and BindStruct. diff --git a/bind_test.go b/bind_test.go index cce3543..e25558a 100644 --- a/bind_test.go +++ b/bind_test.go @@ -26,7 +26,7 @@ sync.Map implementation: goos: linux goarch: amd64 -pkg: github.com/jmoiron/sqlx +pkg: github.com/acheong08/squealx BenchmarkBindSpeed/old-4 100000000 11.0 ns/op BenchmarkBindSpeed/new-4 24575726 50.8 ns/op @@ -35,7 +35,7 @@ async.Value map implementation: goos: linux goarch: amd64 -pkg: github.com/jmoiron/sqlx +pkg: github.com/acheong08/squealx BenchmarkBindSpeed/old-4 100000000 11.0 ns/op BenchmarkBindSpeed/new-4 42535839 27.5 ns/op */ diff --git a/go.mod b/go.mod index c9a8d10..0d1018e 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/jmoiron/sqlx +module github.com/acheong08/squealx go 1.19 diff --git a/named.go b/named.go index 155a867..3bd93a6 100644 --- a/named.go +++ b/named.go @@ -21,7 +21,7 @@ import ( "strconv" "unicode" - "github.com/jmoiron/sqlx/reflectx" + "github.com/acheong08/squealx/reflectx" ) // NamedStmt is a prepared statement that executes named queries. Prepare it diff --git a/reflectx/reflect_test.go b/reflectx/reflect_test.go index e73af5b..23cb57d 100644 --- a/reflectx/reflect_test.go +++ b/reflectx/reflect_test.go @@ -850,7 +850,7 @@ func TestMustBe(t *testing.T) { t.Error("expected panic with *reflect.ValueError") return } - if valueErr.Method != "github.com/jmoiron/sqlx/reflectx.TestMustBe" { + if valueErr.Method != "github.com/acheong08/squealx/reflectx.TestMustBe" { } if valueErr.Kind != reflect.String { t.Errorf("unexpected Kind: %s", valueErr.Kind) diff --git a/sqlx.go b/sqlx.go index 5056a65..9b3efb8 100644 --- a/sqlx.go +++ b/sqlx.go @@ -12,7 +12,7 @@ import ( "strings" "sync" - "github.com/jmoiron/sqlx/reflectx" + "github.com/acheong08/squealx/reflectx" ) // Although the NameMapper is convenient, in practice it should not @@ -51,9 +51,9 @@ func mapper() *reflectx.Mapper { // isScannable takes the reflect.Type and the actual dest value and returns // whether or not it's Scannable. Something is scannable if: -// * it is not a struct -// * it implements sql.Scanner -// * it has no exported fields +// - it is not a struct +// - it implements sql.Scanner +// - it has no exported fields func isScannable(t reflect.Type) bool { if reflect.PtrTo(t).Implements(_scannerInterface) { return true @@ -887,9 +887,9 @@ func structOnlyError(t reflect.Type) error { // then each row must only have one column which can scan into that type. This // allows you to do something like: // -// rows, _ := db.Query("select id from people;") -// var ids []int -// scanAll(rows, &ids, false) +// rows, _ := db.Query("select id from people;") +// var ids []int +// scanAll(rows, &ids, false) // // and ids will be a list of the id results. I realize that this is a desirable // interface to expose to users, but for now it will only be exposed via changes @@ -938,7 +938,7 @@ func scanAll(rows rowsi, dest interface{}, structOnly bool) error { var values []interface{} var m *reflectx.Mapper - switch rows :=rows.(type) { + switch rows := rows.(type) { case *Rows: m = rows.Mapper default: diff --git a/sqlx_context_test.go b/sqlx_context_test.go index f4e8f20..c045e0f 100644 --- a/sqlx_context_test.go +++ b/sqlx_context_test.go @@ -1,15 +1,15 @@ +//go:build go1.8 // +build go1.8 // The following environment variables, if set, will be used: // -// * SQLX_SQLITE_DSN -// * SQLX_POSTGRES_DSN -// * SQLX_MYSQL_DSN +// - SQLX_SQLITE_DSN +// - SQLX_POSTGRES_DSN +// - SQLX_MYSQL_DSN // // Set any of these variables to 'skip' to skip them. Note that for MySQL, // the string '?parseTime=True' will be appended to the DSN if it's not there // already. -// package sqlx import ( @@ -22,8 +22,8 @@ import ( "testing" "time" + "github.com/acheong08/squealx/reflectx" _ "github.com/go-sql-driver/mysql" - "github.com/jmoiron/sqlx/reflectx" _ "github.com/lib/pq" _ "github.com/mattn/go-sqlite3" ) @@ -674,8 +674,8 @@ func TestNamedQueryContext(t *testing.T) { type Owner struct { Email *string `db:"email"` - FirstName string `db:"first_name"` - LastName string `db:"last_name"` + FirstName string `db:"first_name"` + LastName string `db:"last_name"` } // Test optional nested structs with left join diff --git a/sqlx_test.go b/sqlx_test.go index fd68127..e569c07 100644 --- a/sqlx_test.go +++ b/sqlx_test.go @@ -1,13 +1,12 @@ // The following environment variables, if set, will be used: // -// * SQLX_SQLITE_DSN -// * SQLX_POSTGRES_DSN -// * SQLX_MYSQL_DSN +// - SQLX_SQLITE_DSN +// - SQLX_POSTGRES_DSN +// - SQLX_MYSQL_DSN // // Set any of these variables to 'skip' to skip them. Note that for MySQL, // the string '?parseTime=True' will be appended to the DSN if it's not there // already. -// package sqlx import ( @@ -22,8 +21,8 @@ import ( "testing" "time" + "github.com/acheong08/squealx/reflectx" _ "github.com/go-sql-driver/mysql" - "github.com/jmoiron/sqlx/reflectx" _ "github.com/lib/pq" _ "github.com/mattn/go-sqlite3" )