Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/sqlite_async/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.14.4

- Add `SqliteOptions.preparedStatementCacheSize` to cache prepared statements.

## 0.14.3

- Include identifier of mutexes when a navigator lock attempt is aborted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ final class NativeSqliteDatabaseImpl extends SqliteDatabaseImpl {
[
for (var i = 0; i < maxReaders; i++) openConnection(isWriter: false)
],
// TODO: Option to enable prepared statement cache.
preparedStatementCacheSize:
openFactory.sqliteOptions.preparedStatementCacheSize,
);
},
);
Expand Down
14 changes: 14 additions & 0 deletions packages/sqlite_async/lib/src/sqlite_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ final class SqliteOptions {
/// additional readers on the web.
final int maxReaders;

/// The amount of prepared statements to cache.
///
/// For each SQLite connection, up to [preparedStatementCacheSize] statements
/// will be cached in an LRU cache. This allows re-using prepared statements
/// instead of parsing and optimizing them again, which improve performance
/// for frequently-used statements like watched queries.
///
/// Defaults to 16. To disable caching prepared statements, set this to 0.
final int preparedStatementCacheSize;

@Deprecated('Use default SqliteOptions constructor instead')
const factory SqliteOptions.defaults() = SqliteOptions;

Expand All @@ -54,6 +64,7 @@ final class SqliteOptions {
this.lockTimeout = const Duration(seconds: 30),
this.profileQueries = _profileQueriesByDefault,
this.maxReaders = defaultMaxReaders,
this.preparedStatementCacheSize = 16,
});

/// Creates a new options instance by applying overrides from parameters.
Expand All @@ -64,6 +75,7 @@ final class SqliteOptions {
WebSqliteOptions? webSqliteOptions,
bool? profileQueries,
int? maxReaders,
int? preparedStatementCacheSize,
}) {
return SqliteOptions(
journalMode: journalMode,
Expand All @@ -73,6 +85,8 @@ final class SqliteOptions {
lockTimeout: lockTimeout,
profileQueries: profileQueries ?? this.profileQueries,
maxReaders: maxReaders ?? this.maxReaders,
preparedStatementCacheSize:
preparedStatementCacheSize ?? this.preparedStatementCacheSize,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ base class WebSqliteOpenFactory extends InternalOpenFactory {
/// can customize the behavior where needed.
Future<ConnectToRecommendedResult> connectToWorker(
WebSqlite sqlite, String name) {
return sqlite.connectToRecommended(name);
return sqlite.connectToRecommended(name,
preparedStatementCacheSize: sqliteOptions.preparedStatementCacheSize);
}

/// Currently this only uses the SQLite Web WASM implementation.
Expand Down
4 changes: 2 additions & 2 deletions packages/sqlite_async/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ topics:

dependencies:
sqlite3: ^3.2.0
sqlite3_web: '>=0.8.0 <0.10.0'
sqlite3_connection_pool: ^0.2.4
sqlite3_web: ^0.9.2
sqlite3_connection_pool: ^0.2.7
async: ^2.10.0
collection: ^1.17.0
meta: ^1.10.0
Expand Down