forked from jmoiron/sqlx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Antonio Cheong
committed
Nov 3, 2023
1 parent
ac30c67
commit c4daaae
Showing
9 changed files
with
53 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,52 @@ | ||
# 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. | ||
|
||
## Recent Changes | ||
|
||
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. | ||
|
||
### 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,27 +57,26 @@ 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 | ||
|
||
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", "[email protected]") | ||
tx.MustExec("INSERT INTO person (first_name, last_name, email) VALUES ($1, $2, $3)", "John", "Doe", "[email protected]") | ||
|
@@ -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: "[email protected]"}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module github.com/jmoiron/sqlx | ||
module github.com/acheong08/squealx | ||
|
||
go 1.19 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters