Turso Database: A Rust-Based SQLite-Compatible Engine

7月10日 Published inDatabase Tools

Turso Database is an in-process database engine built from the ground up using Rust. Designed for full compatibility with SQLite, it supports the same SQL dialect and file format, while also implementing key portions of the SQLite C API.

Key features:

  • SQL syntax, file format, and C API compatibility with SQLite (refer to the documentation).
  • Language bindings for JavaScript/WebAssembly, Rust, Go, Python, and Java.
  • Asynchronous I/O powered by io_uring on Linux.
  • Cross-platform support for Linux, macOS, and Windows.

Command-line tool

To install the latest turso CLI, execute the following command:

curl --proto '=https' --tlsv1.2 -LsSf \
  https://github.com/tursodatabase/turso/releases/latest/download/turso_cli-installer.sh | sh

Once installed, you can launch the shell to run SQL queries:

Turso

Enter ".help" for usage hints.

Connected to a transient in-memory database.

Use ".open FILENAME" to reopen on a persistent database

turso> CREATE TABLE users (id INT, username TEXT);

turso> INSERT INTO users VALUES (1, 'alice');

turso> INSERT INTO users VALUES (2, 'bob');

turso> SELECT * FROM users;

1|alice
2|bob

To build and run the latest development version from source:

cargo run

Rust

Add the dependency to your project:

cargo add turso

Usage example:

let db = Builder::new_local("sqlite.db").build().await?;
let conn = db.connect()?;
let res = conn.query("SELECT * FROM users", ()).await?;

JavaScript

Install the package via npm:

npm i @tursodatabase/turso

Example usage:

import { Database } from '@tursodatabase/turso';

const db = new Database('sqlite.db');
const stmt = db.prepare('SELECT * FROM users');
const users = stmt.all();
console.log(users);

Python

Install the library using pip:

pip install pyturso

Example usage:

import turso

con = turso.connect("sqlite.db")
cur = con.cursor()

res = cur.execute("SELECT * FROM users")
print(res.fetchone())

Go

  1. Clone the repository.
  2. Build the library and update your LD_LIBRARY_PATH to include the Turso target directory:
cargo build --package limbo-go
export LD_LIBRARY_PATH=/path/to/limbo/target/debug:$LD_LIBRARY_PATH
  1. Install the driver:
go get github.com/tursodatabase/turso
go install github.com/tursodatabase/turso

Example usage:

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

conn, _ = sql.Open("sqlite3", "sqlite.db")
defer conn.Close()

stmt, _ := conn.Prepare("select * from users")
defer stmt.Close()

rows, _ = stmt.Query()

for rows.Next() {
    var id int
    var username string
    _ := rows.Scan(&id, &username)
    fmt.Printf("User: ID: %d, Username: %s\n", id, username)
}

Java

Turso Database provides integration via JDBC. For detailed setup and usage instructions, please refer to bindings/java/README.md.

How does Turso Database differ from Turso’s libSQL?

While both projects aim to modernize the SQLite ecosystem, they use different approaches. Turso Database is a complete rewrite of SQLite in Rust. This allows for a next-generation engine designed for open contributions and future-facing features like native asynchronous support and vector search. In contrast, libSQL evolves the SQLite platform by forking the original C codebase rather than rebuilding it.