turso_go

package module
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2025 License: MIT Imports: 19 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Turso Database

Turso Database Go Driver

⚠️Warning: This software is in BETA. It may still contain bugs and unexpected behavior. Use caution with production data and ensure you have backups.

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.

Getting Started

Install the Turso Go driver using go get:

go get github.com/tursodatabase/turso-go

Then import it in your Go code:

import (
    "database/sql"
    _ "github.com/tursodatabase/turso-go"
)

The driver includes an embedded library that is automatically extracted and loaded at runtime, so no additional setup or environment variables are required.

Example Usage

package main

import (
	"database/sql"
	"fmt"
	"os"
	_ "github.com/tursodatabase/turso-go"
)

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

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

Embedded Library Support

This driver 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.

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

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.

Contributing

For information on building from source, manual library setup, and development instructions, see CONTRIBUTING.md.

License

This project is licensed under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Turso Database by you, shall be licensed as MIT, without any additional terms or conditions.

Documentation

Overview

Go bindings for the turso database.

This file implements library embedding and extraction at runtime, a pattern also used in several other Go projects that need to distribute native binaries:

  • github.com/kluctl/go-embed-python: Embeds a full Python distribution in Go binaries, extracting to temporary directories at runtime. The approach used here was directly inspired by its embed_util implementation.

  • github.com/kluctl/go-jinja2: Uses the same pattern to embed Jinja2 and related Python libraries, allowing Go applications to use Jinja2 templates without external dependencies.

This approach has several advantages: - Allows distribution of a single, self-contained binary - Eliminates the need for users to set LD_LIBRARY_PATH or other environment variables - Works cross-platform with the same codebase - Preserves backward compatibility with existing methods - Extracts libraries only once per execution via sync.Once

The embedded library is extracted to a user-specific temporary directory and loaded dynamically. If extraction fails, the code falls back to the traditional method of searching system paths.

Index

Constants

View Source
const (
	RowsClosedErr         = "sql: Rows closed"
	FfiDbOpen             = "db_open"
	FfiDbClose            = "db_close"
	FfiDbPrepare          = "db_prepare"
	FfiDbGetError         = "db_get_error"
	FfiConnLastInsertId   = "stmt_last_insert_id"
	FfiConnChanges        = "stmt_changes"
	FfiStmtExec           = "stmt_execute"
	FfiStmtQuery          = "stmt_query"
	FfiStmtReset          = "stmt_reset"
	FfiRowsGetColumnType  = "rows_get_column_type"
	FfiStmtParameterCount = "stmt_parameter_count"
	FfiStmtGetError       = "stmt_get_error"
	FfiStmtClose          = "stmt_close"
	FfiRowsClose          = "rows_close"
	FfiRowsGetColumns     = "rows_get_columns"
	FfiRowsGetColumnName  = "rows_get_column_name"
	FfiRowsNext           = "rows_next"
	FfiRowsGetValue       = "rows_get_value"
	FfiRowsGetError       = "rows_get_error"
	FfiFreeColumns        = "free_columns"
	FfiFreeCString        = "free_string"
	FfiFreeBlob           = "free_blob"
	FfiDbPing             = "db_ping"
)

Variables

This section is empty.

Functions

func CString

func CString(name string) *byte

func GoString

func GoString(c uintptr) string

Types

type Blob

type Blob struct {
	Data uintptr
	Len  int64
}

struct to pass byte slices over FFI

type ResultCode

type ResultCode int32
const (
	Error               ResultCode = -1
	Ok                  ResultCode = 0
	Row                 ResultCode = 1
	Busy                ResultCode = 2
	Io                  ResultCode = 3
	Interrupt           ResultCode = 4
	Invalid             ResultCode = 5
	Null                ResultCode = 6
	NoMem               ResultCode = 7
	ReadOnly            ResultCode = 8
	NoData              ResultCode = 9
	Done                ResultCode = 10
	SyntaxErr           ResultCode = 11
	ConstraintViolation ResultCode = 12
	NoSuchEntity        ResultCode = 13
)

func (ResultCode) String

func (rc ResultCode) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址