v0.1.0
The first release of dbimp. It holds one driver, for Couchbase, and the code that every later driver shares.
The Couchbase driver
github.com/xo/dbimp/couchbase is a database/sql driver for the Couchbase query service and SQL++. It replaces github.com/couchbase/go_n1ql and xo/n1ql. It uses the Go standard library and github.com/cockroachdb/apd/v3, and it needs no cgo.
import (
"database/sql"
_ "github.com/xo/dbimp/couchbase"
)
db, err := sql.Open("couchbase", "couchbase://user:pass@localhost:8093/")- It registers one name,
couchbase, and takes only acouchbase://URL. The keys of the URL aretls,query_context,scan_consistency,timeout,durability_levelandtxtimeout. An unknown key or a repeated key is an error. - The server binds each argument.
?,$1andsql.Namedall work. - A row keeps the order of the columns that the server sends, and each value is a Go value:
int64,float64,string,bool,[]any,map[string]any, ornilfor NULL and MISSING. An integer too large for anint64is a*apd.Decimal. - A string scans into a
[]byteas base64, and as its own bytes when it is not base64. - It reads a result one token at a time as it arrives, and it never holds the whole result in memory.
database/sqltransactions map onto the transactions of the query service. On a server with one node, setdurability_level=none, because the default durability cannot commit there. The server ends a transaction after 15 seconds unlesstxtimeoutis longer.WithOptionsand theOptionfunctions set the options of one statement or one transaction.WithParametersets any parameter of the request by its name.- A failed response is a
*couchbase.ResponseError, anderrors.Asfinds eachcouchbase.Errorin it, with its code. - It stops a query when its context ends.
It is tested on Couchbase 7.2.9, 7.6.12 and 8.0.3, as an administrator and as an ordinary user. The tests cover CRUD, each native type, and each feature in testdata/couchbase/features.json. docs/COUCHBASE.md holds every fact that was measured.
What a consumer changes
- The scheme is
couchbase, notn1ql.dburlkeepsn1qlas an alias. - A value is a decoded Go value, not JSON text, so code that called
strconv.Unquoteon a value no longer needs it. - The columns keep the order that the server sends. Couchbase 7.2 sends them in the order of their names.
LastInsertIdreturns an error, andRowsAffectedreturns the count of mutations.
For the authors of drivers
- The root package
dbimpholds the HTTP client, the readers of rows, the decoders of values and the parser of placeholders. dbimptestholds the helpers for the tests of a driver: recorded exchanges, the contract suite, the round trip of a type, and the survey of features.docs/DRIVER.mdholds every step to add a driver, and the gates ingates_test.gohold the steps.