Documentation Index
Fetch the complete documentation index at: https://docs.turso.tech/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
Before you start, make sure you:
Add packages to your project
flutter pub add drift_libsql drift drift_flutter dev:build_runner dev:drift_dev
Retrieve database credentials
Get the database URL:turso db show --url <database-name>
Get the database authentication token:turso db tokens create <database-name>
Assign credentials to the environment variables inside .env.TURSO_DATABASE_URL=
TURSO_AUTH_TOKEN=
Create a table schema
class TaskTable extends Table {
IntColumn get id => integer().autoIncrement()();
TextColumn get title => text()();
TextColumn get description => text()();
BoolColumn get completed => boolean()();
}
Create db class
@DriftDatabase(tables: [TaskTable])
class AppDatabase extends _$AppDatabase {
AppDatabase(super.e);
@override
int get schemaVersion => 1;
}
Run build runner
dart run build_runner build
Create the db
final db = AppDatabase(DriftLibsqlDatabase(
"${dir.path}/replica.db",
syncUrl: url,
authToken: token,
readYourWrites: true,
syncIntervalSeconds: 3,
));
Perform SQL operations
await db.into(db.taskTable).insert(TaskTableCompanion.insert(
title: task.title,
description: task.description,
completed: task.completed));