Early preview of a DB driver for SQLite without CGO
Sqinn-Go is a Go (Golang) library for accessing SQLite databases in pure Go. It uses Sqinn GitHub - cvilsmeier/sqinn: SQLite over stdin/stdout under the hood. It starts Sqinn as a child process (os/exec) and communicates with Sqinn over stdin/stdout/stderr. The Sqinn child process then does the SQLite work.
If you want SQLite but do not want cgo, Sqinn-Go can be a solution.
Usage
$ go get -u github.com/cvilsmeier/sqinn-go/sqinn
import "github.com/cvilsmeier/sqinn-go/sqinn"
// Simple sqinn-go usage. Error handling is left out for brevity.
func main() {
// Launch sqinn. Terminate at program exit.
sq, _ := sqinn.Launch(sqinn.Options{})
defer sq.Terminate()
// Open database. Close when we're done.
sq.Open("./users.db")
defer sq.Close()
// Create a table.
sq.ExecOne("CREATE TABLE users (id INTEGER PRIMARY KEY NOT NULL, name VARCHAR)")
// Insert users.
sq.ExecOne("INSERT INTO users (id, name) VALUES (1, 'Alice')")
sq.ExecOne("INSERT INTO users (id, name) VALUES (2, 'Bob')")
// Query users.
rows, _ := sq.Query("SELECT id, name FROM users ORDER BY id", nil, []byte{sqinn.ValInt, sqinn.ValText})
for _, row := range rows {
fmt.Printf("id=%d, name=%s\n", row.Values[0].AsInt(), row.Values[1].AsString())
}
// Output:
// id=1, name=Alice
// id=2, name=Bob
}