This module provides go
bindings for sqlean
. It is compatible with the
popular mattn/go-sqlite3
driver.
All sources from a published release are bundled into sqlean.c
amalgamation file, using tools/amalgamate.go
, and vendored alongside the bindings. This makes
the package go get
-able, though you'd still need to enable cgo
for compilation.
go get -u github.com/riyaz-ali/sqlean.go
Note: The module is intended to be used in an application, and therefore be
statically linked to the sqlite3
library.
To enforce that, there is a default #define SQLITE_CORE
present in sqlean.go
. If you need to load it as an extension,
you are better off using the original sources / releases.
To register sqlean
with an existing database connection, you need to invoke sqlean.Register()
.
The following example shows how to use sqlean.go
with mattn/go-sqlite3
.
import (
"database/sql"
"github.com/mattn/go-sqlite3"
"github.com/riyaz-ali/sqlean.go"
"reflect"
)
func init() {
sql.Register("sqlean", &sqlite3.SQLiteDriver{
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
// use reflection to get access to conn.db private field
// need this until mattn/go-sqlite3#1155 gets resolved
var db = reflect.Indirect(reflect.ValueOf(conn)).FieldByName("db").UnsafePointer()
return sqlean.Register(sqlean.DatabaseConnection(db)) // sqlean.DatabaseConnection() is a type-cast
},
})
}
// you can then do sql.Open("sqlean", "...")
Each extension binding file defines a !sqlean_omit_<name>
build constraint. This creates a default opt-in build where all extensions
are enabled by default. To omit an extension, build with -tags sqlean_omit_<name>
.
sqlean.go
contains the following extensions:
crypto
: Hashing, encoding and decoding datadefine
: User-defined functions and dynamic SQLfileio
: Reading and writing filesipaddr
: IP address manipulationmath
: Math functionsstats
: Math statisticstext
: String functionsunicode
: Unicode supportuuid
: Universally Unique IDentifiersvsv
: CSV files as virtual tables
Newer extensions and / or versions are updated on best-effort basis. To generate new amalgamation source, run:
go run tools/amalgamate.go --version <version>
Code under amalgamation files - sqlean.c
and sqlean.h
- is generated from
source releases and is licensed under MIT License.
Check the original license and copyright at nalgeon/sqlean/LICENSE