LibsqlClient class

A client class to interact with LibSQL/Turso database instance. All variants of database types can be created using this class. Below is supported configuration for each variants

In memory database

final client = LibsqlClient(':memory:');
await client.connect();

Local database

final dir = await getApplicationCacheDirectory();
final path = '${dir.path}/local.db';
final client = LibsqlClient(path, openFlags: libsql.LibsqlOpenFlags.readWrite);
await client.connect();

Remote database

final client = LibsqlClient('<TURSO_OR_LIBSQL_URL>', authToken: '<TOKEN>');
await client.connect();

Embedded replica

final dir = await getApplicationCacheDirectory();
final path = '${dir.path}/replica.db';
final client = LibsqlClient(path, syncUrl: '<TURSO_OR_LIBSQL_URL>', authToken: '<TOKEN>', readYourWrites: true, syncIntervalSeconds: 30);
await client.connect();

Constructors

LibsqlClient(String url, {String? authToken, String? syncUrl, int? syncIntervalSeconds, String? encryptionKey, bool? readYourWrites, LibsqlOpenFlags? openFlags})

Properties

authToken String?
getter/setter pair
encryptionKey String?
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
openFlags ↔ LibsqlOpenFlags?
getter/setter pair
readYourWrites bool?
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
syncIntervalSeconds int?
getter/setter pair
syncUrl String?
getter/setter pair
url String
final

Methods

batch(String sql) Future<void>
Run a batch transaction
connect() Future<void>
Connect the database, must be called first after creation
dispose() Future<void>
Close the database
execute(String sql, {Map<String, dynamic>? named, List? positional}) Future<int>
Execute the statement, you can provide either named or positional parameters
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
prepare(String sql) Future<Statement>
Create a prepared statement
query(String sql, {Map<String, dynamic>? named, List? positional}) Future<List<Map<String, dynamic>>>
Query the database, you can provide either named or positional parameters
sync() Future<void>
toString() String
A string representation of this object.
inherited
transaction({LibsqlTransactionBehavior? behavior}) Future<Transaction>

Operators

operator ==(Object other) bool
The equality operator.
inherited