Documentation ¶
Overview ¶
Package sqldriver is a wrapper around the ADBC (Arrow Database Connectivity) interfaces to support the standard golang database/sql package, described here: https://go.dev/src/database/sql/doc.txt
This allows any ADBC driver implementation to also be used as-is with the database/sql package of the standard library rather than having to implement drivers for both separately.
Registering the driver can be done by importing this and then running
sql.Register("drivername", sqldriver.Driver{adbcdriver})
Additionally, the sqldriver/flightsql package simplifies registration of the FlightSQL ADBC driver implementation, so that only a single import statement is needed. See the example in that package.
EXPERIMENTAL. The ADBC interfaces are subject to change and as such this wrapper is also subject to change based on that.
Example ¶
package main import ( "database/sql" "fmt" "github.com/apache/arrow-adbc/go/adbc/drivermgr" "github.com/apache/arrow-adbc/go/adbc/sqldriver" ) func main() { sql.Register("adbc", sqldriver.Driver{&drivermgr.Driver{}}) // AdbcDriverInit is the assumed entrypoint by default, but i'll keep // it specified explicitly here for demonstration purposes. // this also assumes that libadbc_driver_sqlite.so is on your LD_LIBRARY_PATH db, err := sql.Open("adbc", "driver=adbc_driver_sqlite;entrypoint=AdbcDriverInit") if err != nil { panic(err) } rows, err := db.Query("SELECT ?", 1) if err != nil { panic(err) } defer rows.Close() colNames, err := rows.Columns() if err != nil { panic(err) } fmt.Println(colNames) cols, err := rows.ColumnTypes() if err != nil { panic(err) } fmt.Println(cols[0].Name()) fmt.Println(cols[0].Nullable()) for rows.Next() { var v int64 if err := rows.Scan(&v); err != nil { panic(err) } fmt.Println(v) } }
Output: [?] ? true true 1
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Driver ¶
func (Driver) Open ¶
Open returns a new connection to the database. The name should be semi-colon separated key-value pairs of the form: key=value;key2=value2;.....
Open may return a cached connection (one previously closed), but doing so is unnecessary; the sql package maintains a pool of idle connections for efficient re-use.
The returned connection is only used by one goroutine at a time.