Skip to content

tomcorkhill/libsql-client-go

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go SDK for libSQL

License

This module implements a libSQL driver for the standard Go database/sql package. You can use it to interact with the following types of databases:

Installation

Install the driver into your module:

go get github.com/tomcorkhill/libsql-client-go

Import the driver into your code using a blank import:

import (
	_ "github.com/tomcorkhill/libsql-client-go/libsql"
)

Ensure all the module requirements are up to date:

go mod tidy

Add support for sqlite3 database files

To use a sqlite3 database file, you must also install and import one of the following SQLite drivers:

This enables the use of file: URLs with this driver.

Open a connection to sqld

Specify the "libsql" driver and a database URL in your call to sql.Open:

import (
	"database/sql"
	"fmt"
	"os"

	_ "github.com/tomcorkhill/libsql-client-go/libsql"
)

var dbUrl = "http://127.0.0.1:8080"
db, err := sql.Open("libsql", dbUrl)
if err != nil {
    fmt.Fprintf(os.Stderr, "failed to open db %s: %s", dbUrl, err)
    os.Exit(1)
}

If your sqld instance is managed by Turso, the database URL must contain a valid database auth token in the query string:

var dbUrl = "libsql://[your-database].turso.io?authToken=[your-auth-token]"

Open a connection to a local sqlite3 database file

You can use a file: URL to locate a sqlite3 database file for use with this driver. The example below assumes that the package modernc.org/sqlite is installed:

import (
	"database/sql"
	"fmt"
	"os"

	_ "github.com/tomcorkhill/libsql-client-go/libsql"
	_ "modernc.org/sqlite"
)

var dbUrl = "file:path/to/file.db"
db, err := sql.Open("libsql", dbUrl)
if err != nil {
    fmt.Fprintf(os.Stderr, "failed to open db %s: %s", dbUrl, err)
    os.Exit(1)
}

Compatibility with database/sql

This driver currently does not support prepared statements using db.Prepare() when querying sqld over HTTP.

License

This project is licensed under the MIT license.

Contribution

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

About

Go client API for libSQL

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%