Skip to main content
Multilingual TursoDB, MVCC & AI Agent database guides Read Engine Guide →
Turso Database Getting Started Connect

Connect to Turso using Dart

Connect to Turso using Dart — Turso documentation.

1. Install

Add the turso_dart package to your pubspec.yaml:

dependencies:
  turso_dart:

Then run:

dart pub get

2. Connect

Create a client connection. You can connect to an in-memory database or a local file:

import 'package:turso_dart/turso_dart.dart';

// In memory
final client = TursoClient.memory();

// Or local file
final client = TursoClient.local('/path/to/local.db');

await client.connect();

3. Create table

Create a table for customers:

await client.execute(
  "CREATE TABLE IF NOT EXISTS customers (id INTEGER PRIMARY KEY, name TEXT)"
);

4. Insert data

Insert some data into the customers table:

await client.query("INSERT INTO customers(name) VALUES ('John Doe')");
await client.query("INSERT INTO customers(name) VALUES ('Jane Smith')");

5. Query data

Query all customers from the table:

final result = await client.query("SELECT * FROM customers");
print(result);

6. Prepared statements

Use prepared statements for better performance and security:

final statement = await client.prepare("SELECT * FROM customers WHERE id = ?");
final result = await statement.query(positional: [1]);
print(result);
Synced from official Turso documentation ( tursodatabase/turso-docs · MIT License) Official Docs ↗
Search
Press Esc to close · Powered by Pagefind