limbo/bindings/go
2025-02-09 18:08:29 +02:00
..
rs_src Fix a handful of typos 2025-02-09 18:08:29 +02:00
Cargo.toml bindings: select io_uring feature from limbo_core explicitly as it will be made non-default 2025-02-09 01:10:35 +01:00
connection.go bindings/go: Add error propagation from bindings lib 2025-02-02 07:40:28 -05:00
go.mod bindings/go: update readme with example, change module name 2025-01-31 19:22:21 -05:00
go.sum Progress on Go bindings, add prepare + query statement 2025-01-25 23:01:46 -05:00
limbo_test.go Fix a handful of typos 2025-02-09 18:08:29 +02:00
limbo_unix.go bindings/go: enable multiple connections, register all symbols at library load 2025-01-31 13:28:05 -05:00
limbo_windows.go bindings/go: enable multiple connections, register all symbols at library load 2025-01-31 13:28:05 -05:00
README.md bindings/go: update readme with example, change module name 2025-01-31 19:22:21 -05:00
rows.go bindings/go: Add error propagation from bindings lib 2025-02-02 07:40:28 -05:00
stmt.go bindings/go: Add error propagation from bindings lib 2025-02-02 07:40:28 -05:00
types.go bindings/go: Add error propagation from bindings lib 2025-02-02 07:40:28 -05:00

Limbo driver for Go's database/sql library

NOTE: this is currently heavily W.I.P and is not yet in a usable state.

This driver uses the awesome purego library to call C (in this case Rust with C ABI) functions from Go without the use of CGO.

To use: (UNSTABLE testing or development purposes only)

Linux | MacOS

All commands listed are relative to the bindings/go directory in the limbo repository

cargo build --package limbo-go

# Your LD_LIBRARY_PATH environment variable must include limbo's `target/debug` directory

export LD_LIBRARY_PATH="/path/to/limbo/target/debug:$LD_LIBRARY_PATH"

Windows

cargo build --package limbo-go

# You must add limbo's `target/debug` directory to your PATH
# or you could built + copy the .dll to a location in your PATH
# or just the CWD of your go module

cp path\to\limbo\target\debug\lib_limbo_go.dll .

go test

Temporarily you may have to clone the limbo repository and run:

go mod edit -replace github.com/tursodatabase/limbo=/path/to/limbo/bindings/go

import (
    "fmt"
    "database/sql"
    _"github.com/tursodatabase/limbo"
)

func main() {
	conn, err := sql.Open("sqlite3", ":memory:")
	if err != nil {
        fmt.Printf("Error: %v\n", err)
        os.Exit(1)
	}
    sql := "CREATE table go_limbo (foo INTEGER, bar TEXT)"
    _ = conn.Exec(sql)

    sql = "INSERT INTO go_limbo (foo, bar) values (?, ?)"
    stmt, _ := conn.Prepare(sql)
    defer stmt.Close()
    _  = stmt.Exec(42, "limbo")
    rows, _ := conn.Query("SELECT * from go_limbo")
    defer rows.Close()
    for rows.Next() {
        var a int
        var b string
		_ = rows.Scan(&a, &b)
        fmt.Printf("%d, %s", a, b)
    }
}