limbo/bindings/go
2025-05-06 20:44:02 -07:00
..
libs change to address CI failure. libs dir must exist with at least one file during build time. Add libs/.gitkeep as placeholder. Update .gitignore to exclude built libs but keep placeholder. This change is for CI purposes only 2025-05-02 13:02:52 -07:00
rs_src clippy 2025-03-29 22:04:08 +01:00
.gitignore change to address CI failure. libs dir must exist with at least one file during build time. Add libs/.gitkeep as placeholder. Update .gitignore to exclude built libs but keep placeholder. This change is for CI purposes only 2025-05-02 13:02:52 -07:00
build_lib.sh accept debug or release parameter - default to release 2025-05-06 20:44:02 -07:00
Cargo.toml build: Don't publish some bindings crates 2025-02-18 19:00:11 +02:00
connection.go bindings/go: Add error propagation from bindings lib 2025-02-02 07:40:28 -05:00
embedded.go embeds and extracts platform-specific libraries at runtime using Go's embed package 2025-05-02 12:43:36 -07: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 remove TestTransactions that was being skipped. added back in second PR 2025-05-02 14:44:49 -07:00
limbo_unix.go Update library loading mechanism to first attempt using the embedded library before falling back to traditional LD_LIBRARY_PATH lookup 2025-05-02 12:44:24 -07:00
limbo_windows.go Update Windows library loading to prioritize the embedded library while maintaining compatibility with PATH-based lookup 2025-05-02 12:44:46 -07:00
README.md add documentation for new embedded library feature, including usage instructions and implementation notes 2025-05-02 12:45:30 -07: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.

Embedded Library Support

This driver now includes an embedded library feature that allows you to distribute a single binary without requiring users to set environment variables. The library for your platform is automatically embedded, extracted at runtime, and loaded dynamically.

To build with embedded library support:

# From the bindings/go directory
./build_lib.sh

If the embedded library cannot be found or extracted, the driver will fall back to the traditional method of finding the library in the system paths.

To use: (UNSTABLE testing or development purposes only)

Build the driver with the embedded library as described above, then simply import and use. No environment variables needed!

Option 2: Manual library setup

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)
    }
}

Implementation Notes

The embedded library feature was inspired by projects like go-embed-python, which uses a similar approach for embedding and distributing native libraries with Go applications.