common topic

Definitions and common interfaces that are implemented by both the native and the web-specific bindings to SQLite.

Restricting your usage of the sqlite3 package to package:sqlite3/common.dart means that your code can run on all platforms. However, this doesn't give you access to the actual implementations that are part of the native and web implementations. You can write most of your database code with the common definitions and then use conditional imports to make an implementation available. For this, create three files:

  1. database_stub.dart.
  2. database_native.dart.
  3. datbaase_web.dart.

The content of these files depends on your needs, but could look like this:

// database_stub.dart
import 'package:sqlite3/common.dart';

Future<CommonDatabase> openDatabase() async {
  throw UnsupportedError('Unknown platform');
}
// database_native.dart
import 'package:sqlite3/sqlite3.dart';

Future<CommonDatabase> openDatabase() async {
  final path = await pickDatabasePath(); // e.g. with package:path_provider
  return sqlite3.open(path);
}
// database_web.dart
import 'package:sqlite3/wasm.dart';

Future<CommonDatabase> openDatabase() async {
  final sqlite = await WasmSqlite3.loadFromUrl(Uri.parse('sqlite3.wasm'));
  final fs = await IndexedDbFileSystem.open(dbName: 'app.db');
  sqlite.registerVirtualFileSystem(fs, makeDefault: true);
  return sqlite.open('/app.db');
}

With those files, you can use a conditional imports to support both web and native platforms:

import 'database_stub.dart'
    if (dart.library.io) 'database_native.dart'
    if (dart.library.js_interop) 'database_web.dart';

Libraries

common common
Exports common interfaces that are implemented by both the dart:ffi and the dart:js WASM version of this library.

Classes

AggregateContext<V> common
Application-defined context used to compute results in aggregate functions.
AggregateContext<V> common
Application-defined context used to compute results in aggregate functions.
AggregateContext<V> common
Application-defined context used to compute results in aggregate functions.
AggregateFunction<V> common
Interface for application-defined aggregate functions.
AggregateFunction<V> common
Interface for application-defined aggregate functions.
AggregateFunction<V> common
Interface for application-defined aggregate functions.
AllowedArgumentCount common
Describes how many arguments an application-defined sql function can take.
AllowedArgumentCount common
Describes how many arguments an application-defined sql function can take.
AllowedArgumentCount common
Describes how many arguments an application-defined sql function can take.
BaseVfsFile common
A VirtualFileSystemFile base class that implements xRead to zero-fill the buffer in case of short reads.
BaseVfsFile common
A VirtualFileSystemFile base class that implements xRead to zero-fill the buffer in case of short reads.
BaseVfsFile common
A VirtualFileSystemFile base class that implements xRead to zero-fill the buffer in case of short reads.
BaseVirtualFileSystem common
A VirtualFileSystem implementation that uses a Random instance for xRandomness and DateTime.now for xCurrentTime.
BaseVirtualFileSystem common
A VirtualFileSystem implementation that uses a Random instance for xRandomness and DateTime.now for xCurrentTime.
BaseVirtualFileSystem common
A VirtualFileSystem implementation that uses a Random instance for xRandomness and DateTime.now for xCurrentTime.
CommonDatabase common
An opened sqlite3 database.
CommonDatabase common
An opened sqlite3 database.
CommonPreparedStatement common
A prepared statement.
CommonPreparedStatement common
A prepared statement.
CommonSqlite3 common
Provides access to sqlite3 functions, such as opening new databases.
CommonSqlite3 common
Provides access to sqlite3 functions, such as opening new databases.
CommonSqlite3 common
Provides access to sqlite3 functions, such as opening new databases.
Cursor common
Base class for result sets.
Cursor common
Base class for result sets.
Cursor common
Base class for result sets.
CustomStatementParameter common
A parameter passed to prepared statements that decides how it gets mapped to SQL in applyTo.
CustomStatementParameter common
A parameter passed to prepared statements that decides how it gets mapped to SQL in applyTo.
CustomStatementParameter common
A parameter passed to prepared statements that decides how it gets mapped to SQL in applyTo.
DatabaseConfig common
Make configuration changes to the database connection.
DatabaseConfig common
Make configuration changes to the database connection.
DatabaseConfig common
Make configuration changes to the database connection.
InMemoryFileSystem common
A virtual file system implementation that stores all files in memory.
InMemoryFileSystem common
A virtual file system implementation that stores all files in memory.
InMemoryFileSystem common
A virtual file system implementation that stores all files in memory.
IteratingCursor common
A Cursor that can only be read once, obtaining rows from the database "on the fly" as moveNext is called.
IteratingCursor common
A Cursor that can only be read once, obtaining rows from the database "on the fly" as moveNext is called.
IteratingCursor common
A Cursor that can only be read once, obtaining rows from the database "on the fly" as moveNext is called.
ResultSet common
Stores the full result of a select statement.
ResultSet common
Stores the full result of a select statement.
ResultSet common
Stores the full result of a select statement.
Row common
A single row in the result of a select statement.
Row common
A single row in the result of a select statement.
Row common
A single row in the result of a select statement.
SqlError common
Common result codes, https://www.sqlite.org/rescode.html Result Codes
SqlError common
Common result codes, https://www.sqlite.org/rescode.html Result Codes
SqlError common
Common result codes, https://www.sqlite.org/rescode.html Result Codes
SqlExtendedError common
Extended Result Codes, https://www.sqlite.org/rescode.html
SqlExtendedError common
Extended Result Codes, https://www.sqlite.org/rescode.html
SqlExtendedError common
Extended Result Codes, https://www.sqlite.org/rescode.html
SqlFileLockingLevels common
File lock levels, https://www.sqlite.org/c3ref/c_lock_exclusive.html
SqlFileLockingLevels common
File lock levels, https://www.sqlite.org/c3ref/c_lock_exclusive.html
SqlFileLockingLevels common
File lock levels, https://www.sqlite.org/c3ref/c_lock_exclusive.html
SqlFlag common
Flags for file open operations, https://www.sqlite.org/c3ref/c_open_autoproxy.html Flags For File Open Operations
SqlFlag common
Flags for file open operations, https://www.sqlite.org/c3ref/c_open_autoproxy.html Flags For File Open Operations
SqlFlag common
Flags for file open operations, https://www.sqlite.org/c3ref/c_open_autoproxy.html Flags For File Open Operations
SqlFunctionFlag common
Function flags, https://www.sqlite.org/c3ref/c_deterministic.html
SqlFunctionFlag common
Function flags, https://www.sqlite.org/c3ref/c_deterministic.html
SqlFunctionFlag common
Function flags, https://www.sqlite.org/c3ref/c_deterministic.html
Sqlite3Filename common
A filename passed to VirtualFileSystem.xOpen.
Sqlite3Filename common
A filename passed to VirtualFileSystem.xOpen.
Sqlite3Filename common
A filename passed to VirtualFileSystem.xOpen.
SqliteUpdate common
A data change notification from sqlite.
SqliteUpdate common
A data change notification from sqlite.
SqliteUpdate common
A data change notification from sqlite.
SqlPrepareFlag common
Prepare flags, https://www.sqlite.org/c3ref/c_prepare_normalize.html
SqlPrepareFlag common
Prepare flags, https://www.sqlite.org/c3ref/c_prepare_normalize.html
SqlPrepareFlag common
Prepare flags, https://www.sqlite.org/c3ref/c_prepare_normalize.html
SqlSpecialDestructor common
Special destructors, https://www.sqlite.org/c3ref/c_static.html
SqlSpecialDestructor common
Special destructors, https://www.sqlite.org/c3ref/c_static.html
SqlSpecialDestructor common
Special destructors, https://www.sqlite.org/c3ref/c_static.html
SqlTextEncoding common
Text Encodings, https://www.sqlite.org/c3ref/c_any.html These constant define integer codes that represent the various text encodings supported by SQLite.
SqlTextEncoding common
Text Encodings, https://www.sqlite.org/c3ref/c_any.html These constant define integer codes that represent the various text encodings supported by SQLite.
SqlTextEncoding common
Text Encodings, https://www.sqlite.org/c3ref/c_any.html These constant define integer codes that represent the various text encodings supported by SQLite.
SqlType common
Datatypes, https://sqlite.org/c3ref/c_blob.html
SqlType common
Datatypes, https://sqlite.org/c3ref/c_blob.html
SqlType common
Datatypes, https://sqlite.org/c3ref/c_blob.html
StatementParameters common
A set of values that can be used to bind parameters in a SQL query.
StatementParameters common
A set of values that can be used to bind parameters in a SQL query.
StatementParameters common
A set of values that can be used to bind parameters in a SQL query.
VirtualFileSystem common
A virtual filesystem used by sqlite3 to access the current I/O environment.
VirtualFileSystem common
A virtual filesystem used by sqlite3 to access the current I/O environment.
VirtualFileSystem common
A virtual filesystem used by sqlite3 to access the current I/O environment.
VirtualFileSystemFile common
A file implemented by a VFS author and returned by VirtualFileSystem.xOpen.
VirtualFileSystemFile common
A file implemented by a VFS author and returned by VirtualFileSystem.xOpen.
VirtualFileSystemFile common
A file implemented by a VFS author and returned by VirtualFileSystem.xOpen.
WindowFunction<V> common
A window function for sqlite3.
WindowFunction<V> common
A window function for sqlite3.
WindowFunction<V> common
A window function for sqlite3.

Constants

jsonb → const Codec<Object?, Uint8List> common
A Codec capable of converting Dart objects from and to the JSONB format used by sqlite3.
jsonb → const Codec<Object?, Uint8List> common
A Codec capable of converting Dart objects from and to the JSONB format used by sqlite3.
jsonb → const Codec<Object?, Uint8List> common
A Codec capable of converting Dart objects from and to the JSONB format used by sqlite3.

Enums

SqliteUpdateKind common
The kind of an SqliteUpdate received through a CommonDatabase.updates stream.
SqliteUpdateKind common
The kind of an SqliteUpdate received through a CommonDatabase.updates stream.
SqliteUpdateKind common
The kind of an SqliteUpdate received through a CommonDatabase.updates stream.

Exceptions / Errors

SqliteException common
Thrown by sqlite methods.
SqliteException common
Thrown by sqlite methods.
SqliteException common
Thrown by sqlite methods.
VfsException common
An exception thrown by VirtualFileSystem implementations written in Dart to signal that an operation could not be completed.
VfsException common
An exception thrown by VirtualFileSystem implementations written in Dart to signal that an operation could not be completed.
VfsException common
An exception thrown by VirtualFileSystem implementations written in Dart to signal that an operation could not be completed.