Giter Club home page Giter Club logo

libsql-client-go's Introduction

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/libsql/libsql-client-go

Import the driver into your code using a blank import:

import (
	_ "github.com/libsql/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/libsql/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/libsql/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.

libsql-client-go's People

Contributors

avinassh avatar ch1ffa avatar codingdoug avatar haaawk avatar honzasp avatar mr-destructive avatar penberg avatar rylev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.