Skip to content

Commit

Permalink
hard fork
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Cheong committed Nov 3, 2023
1 parent ac30c67 commit c4daaae
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 55 deletions.
57 changes: 28 additions & 29 deletions README.md
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

Expand All @@ -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 = `
Expand Down Expand Up @@ -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]")
Expand Down Expand Up @@ -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}
Expand All @@ -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}
Expand All @@ -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",
Expand All @@ -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]"},
Expand Down
2 changes: 1 addition & 1 deletion bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion go.mod
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

Expand Down
2 changes: 1 addition & 1 deletion named.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion reflectx/reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions sqlx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions sqlx_context_test.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions sqlx_test.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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"
)
Expand Down

0 comments on commit c4daaae

Please sign in to comment.