bindings/go/go-bindings-sync.mdx
Generate Go functions bindings for the sync engine built on top of Turso - SQLite-compatible embedded database written in Rust. You must use C API bridge implemented in Rust which expose ABI compatible functions to interact with the database.
The main goal is to translate C code to Go-friendly bindings which will have no additional logic, but more ergonomic API:
You must generate bindings for C interface defined in turso_sync.h file.
<File path="../../sync/sdk-kit/turso_sync.h" />Note, that this header file depends on the turso.h definitions for which Go bindings already exists. You MUST just reuse them. DO NOT copy or reimplement these bindings:
<File path="../../sdk-kit/turso.h" /> <File path="./bindings_db.go" />General rules for driver implementation you MUST follow and never go against these rules:
package turso
// define all package level errors here
// define opaque pointers as-is and accept them as exact arguments (e.g. func turso_database_connect(self TursoDatabase) ... - DO NOT add extra indirection)
type TursoSyncDatabase *turso_sync_database_t
// define all public binding types
// the public binding types MUST have fields with native safe go types
type TursoSyncDatabaseConfig struct { ... }
// define all necessary private C structs
// private C structs MUST have fields with low level types (e.g. uintptr, numbers)
type turso_sync_database_config_t struct { ... }
// then, define C extern methods
var (
// always use c_ structs here - never mix them with exported public types
c_turso_sync_database_new func(
dbConfig *c_turso_database_config_t,
syncConfig *c_turso_sync_database_config_t,
database unsafe.Pointer,
errorOptOut unsafe.Pointer,
) c_turso_status_code_t
...
)
// imiplement a function to register extern methods from loaded lib
// DO NOT load lib - as it will be done externally
func register_turso_sync(handle uintptr) error {
purego.RegisterLibFunc(&c_turso_sync_database_new, handle, "turso_sync_database_new")
...
}
// Go wrappers over imported C bindings
// always use exported public types here - never mix them with c_ structs
func turso_sync_database_new(...) ... { ... }
c_ prefix for C extern functionsturso_sync_.*) and have fields with native safe go types (string, slice, etc)c_turso_sync_.*) and have fields with low-level C-compatible go types (uintptr, numbers, etc)turso_status_code_t and out error parameter with proper native golang errorInspect following docstring from the official purego repository in order to understand how marshalling works:
<Link url="https://raw.githubusercontent.com/ebitengine/purego/refs/heads/main/func.go" selector="RegisterFunc#comment" /> <Link url="https://raw.githubusercontent.com/ebitengine/purego/refs/heads/main/func.go" selector="RegisterLibFunc#comment" /> </Code> </Output>