Skip to content
Merged
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
3 changes: 2 additions & 1 deletion packages/celest/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## 1.0.5
## 1.0.5-wip

- chore: Remove GCP mentions
- chore: Update analyzer plugin to v2 model
- chore: Add `logStatements` parameter to `connect` method

## 1.0.4

Expand Down
14 changes: 12 additions & 2 deletions packages/celest/lib/src/runtime/data/connect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Future<Database> connect<Database extends GeneratedDatabase>(
required secret tokenSecret,
void Function(sqlite3.CommonDatabase)? setup,
String? path,
bool logStatements = false,
}) async {
final host = context.get(hostnameVariable);
if (host == null) {
Expand All @@ -36,6 +37,7 @@ Future<Database> connect<Database extends GeneratedDatabase>(
name: name,
path: path,
setup: setup,
logStatements: logStatements,
);
return _checkConnection(factory(executor));
}
Expand All @@ -54,9 +56,17 @@ Future<Database> connect<Database extends GeneratedDatabase>(
final QueryExecutor connector;
switch (hostUri) {
case Uri(scheme: 'file', path: '/:memory:'):
connector = await inMemoryExecutor(setup: setup);
connector = await inMemoryExecutor(
setup: setup,
logStatements: logStatements,
);
case Uri(scheme: 'file', :final path):
connector = await localExecutor(name: name, path: path, setup: setup);
connector = await localExecutor(
name: name,
path: path,
setup: setup,
logStatements: logStatements,
);
case Uri(scheme: 'ws' || 'wss' || 'http' || 'https' || 'libsql'):
final token = context.get(tokenSecret);
if (token == null) {
Expand Down
7 changes: 5 additions & 2 deletions packages/celest/lib/src/runtime/data/connect.io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ final Logger _logger = Logger('Celest.Data');
/// A [QueryExecutor] for an in-memory database.
Future<QueryExecutor> inMemoryExecutor({
void Function(sqlite3.CommonDatabase)? setup,
bool logStatements = false,
}) async {
return NativeDatabase.memory(setup: setup);
return NativeDatabase.memory(setup: setup, logStatements: logStatements);
}

/// A [QueryExecutor] with local persistence.
Future<QueryExecutor> localExecutor({
required String name,
void Function(sqlite3.CommonDatabase)? setup,
String? path,
bool logStatements = false,
}) async {
if (path == null) {
Uri? packageConfig;
Expand All @@ -34,7 +36,7 @@ Future<QueryExecutor> localExecutor({
'Failed to determine package config path. '
'Falling back to in-memory database.',
);
return inMemoryExecutor(setup: setup);
return inMemoryExecutor(setup: setup, logStatements: logStatements);
}
path = p.join(
p.dirname(p.fromUri(packageConfig)),
Expand All @@ -52,5 +54,6 @@ Future<QueryExecutor> localExecutor({
cachePreparedStatements: true,
enableMigrations: true,
setup: setup,
logStatements: logStatements,
);
}
10 changes: 8 additions & 2 deletions packages/celest/lib/src/runtime/data/connect.web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@ import 'package:sqlite3/wasm.dart';
/// A [QueryExecutor] for an in-memory database.
Future<QueryExecutor> inMemoryExecutor({
void Function(sqlite3.CommonDatabase)? setup,
bool logStatements = false,
}) async {
final sqlite3 = await WasmSqlite3.loadFromUrl(Uri.parse('./sqlite3.wasm'));
sqlite3.registerVirtualFileSystem(InMemoryFileSystem(), makeDefault: true);
return WasmDatabase.inMemory(sqlite3, setup: setup);
return WasmDatabase.inMemory(
sqlite3,
setup: setup,
logStatements: logStatements,
);
}

/// A [QueryExecutor] with local persistence.
Future<QueryExecutor> localExecutor({
required String name,
void Function(sqlite3.CommonDatabase)? setup,
bool logStatements = false,
String? path,
}) async {
// TODO(dnys1): We don't have a use case for this yet.
return inMemoryExecutor(setup: setup);
return inMemoryExecutor(setup: setup, logStatements: logStatements);
}