-
Notifications
You must be signed in to change notification settings - Fork 11
[Alpha WIP] Web Support #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 49 commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
8214ab1
wip
stevensJourney 7f7a05e
common database types
stevensJourney 9658a6b
added abstractions
stevensJourney 13c6d94
remove test log
stevensJourney 8ae36c8
added web abstractions
stevensJourney 55252e4
abstract factories. Fix tests
stevensJourney e54f9bb
cleanup isolates
stevensJourney e011bd0
loading WASM implementation
stevensJourney f433b23
wip: added synchronous db implementation
stevensJourney 58453ee
bug fixes
stevensJourney 40fbd1d
sqlite version note
stevensJourney c7f22f8
added async DB operations with Drift
stevensJourney 7e406a3
wip: drift
stevensJourney c6f678a
allow multiple web connections (leveraging web worker)
stevensJourney 5246658
wip
stevensJourney 14a3fc7
wip isolate connection factory
stevensJourney b56e64a
wip: organize different implementations
stevensJourney 4327244
cleanup tests
stevensJourney 8e7b1ff
ignore vscode
stevensJourney b033794
cleanup mutexes
stevensJourney 30b6b6c
standard Drift is fine for this lib. Changes are on compiled worker.
stevensJourney 6fc0e10
update sqlite dependency range for test and native compatibility
stevensJourney c2371fc
test sdk 3.2.0
stevensJourney e8b0bf8
lint
stevensJourney 699f3a3
js versions
stevensJourney b841a47
update from main
stevensJourney c2d3e72
update from main
stevensJourney 1283573
added comments
stevensJourney 852633b
added readme note
stevensJourney eff0a10
use mutexes more in abstractions.
stevensJourney 9d3786a
wip: abstract tests. Add Web server for WASM files
stevensJourney 96d67b9
linting fixes
stevensJourney 2892d21
fix tests
stevensJourney 1243a5d
split native and web tests. Add zone gaurds to web connections
stevensJourney 9f16eff
run web tests in CI
stevensJourney 23e211a
test: only compile assets once
stevensJourney e591cdc
compile worker only once
stevensJourney c001b3b
fix compile cmd typo
stevensJourney 6ffb129
cleanup tests
stevensJourney 02c2d9f
improve web locks and transactions according to test spec
stevensJourney 1145db3
Convert Drift SQL exceptions to SQLite exceptions
stevensJourney 70c2324
Allow autocommit on web database connection
stevensJourney 3e4bdd4
remove duplicate test
stevensJourney 5307003
use forked version of Drift
stevensJourney fc4b55d
enable shared watch tests with custom Drift worker
stevensJourney f67d802
migrate from to naming
stevensJourney f946e1a
Use standard Drift package for now. Forked Drift is not published
stevensJourney cd3386b
less strict package version
stevensJourney fdd09c3
code cleanup
stevensJourney ba1622c
improved auto commit check to only conditionally run
stevensJourney af05d85
remove some abstracted classes - replace with factory generators
stevensJourney a35fa43
fix getOptional method to throw expections correctly
stevensJourney ab00e64
cleanup exports
stevensJourney 0263cee
allow creating Mutex class from factory
stevensJourney 3960604
neaten up comments
stevensJourney 9adb4c6
temporarily bump exit-code-threshold to 10. While waiting for depend…
stevensJourney 2275266
bump package version
stevensJourney 99d6289
added changelog entry
stevensJourney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export 'package:sqlite_async/src/update_notification.dart'; | ||
export 'package:sqlite_async/src/sqlite_connection.dart'; | ||
export 'package:sqlite_async/src/sqlite_queries.dart'; | ||
export 'package:sqlite_async/src/sqlite_open_factory.dart'; | ||
export 'package:sqlite_async/src/sqlite_options.dart'; | ||
export 'package:sqlite_async/src/common/abstract_isolate_connection_factory.dart'; | ||
export 'package:sqlite_async/src/common/abstract_open_factory.dart'; | ||
export 'package:sqlite_async/src/common/abstract_sqlite_database.dart'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/// Re-exports [Drift](https://pub.dev/packages/drift) to expose drift without | ||
/// adding it as a direct dependency. | ||
library; | ||
|
||
export 'package:drift/wasm.dart'; | ||
export 'package:sqlite_async/src/web/worker/worker_utils.dart'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Exports common Sqlite3 exports which are available on web and ffi environments | ||
export 'package:sqlite3/common.dart'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import 'dart:async'; | ||
import 'package:sqlite_async/mutex.dart'; | ||
import 'package:sqlite_async/sqlite3_common.dart' as sqlite; | ||
import 'package:sqlite_async/src/sqlite_connection.dart'; | ||
|
||
import 'abstract_open_factory.dart'; | ||
import 'port_channel.dart'; | ||
|
||
/// A connection factory that can be passed to different isolates. | ||
abstract class AbstractIsolateConnectionFactory< | ||
Database extends sqlite.CommonDatabase> { | ||
AbstractDefaultSqliteOpenFactory<Database> get openFactory; | ||
|
||
AbstractMutex get mutex; | ||
|
||
SerializedPortClient get upstreamPort; | ||
|
||
/// Open a new SqliteConnection. | ||
/// | ||
/// This opens a single connection in a background execution isolate. | ||
SqliteConnection open({String? debugName, bool readOnly = false}); | ||
|
||
/// Opens a synchronous sqlite.Database directly in the current isolate. | ||
/// | ||
/// This gives direct access to the database, but: | ||
/// 1. No app-level locking is performed automatically. Transactions may fail | ||
/// with SQLITE_BUSY if another isolate is using the database at the same time. | ||
/// 2. Other connections are not notified of any updates to tables made within | ||
/// this connection. | ||
FutureOr<Database> openRawDatabase({bool readOnly = false}) async { | ||
return openFactory | ||
.open(SqliteOpenOptions(primaryConnection: false, readOnly: readOnly)); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
abstract class AbstractMutex { | ||
/// timeout is a timeout for acquiring the lock, not for the callback | ||
Future<T> lock<T>(Future<T> Function() callback, {Duration? timeout}); | ||
|
||
/// Use [open] to get a [AbstractMutex] instance. | ||
/// This is mainly used for shared mutexes | ||
AbstractMutex open() { | ||
return this; | ||
} | ||
|
||
/// Release resources used by the Mutex. | ||
/// | ||
/// Subsequent calls to [lock] may fail, or may never call the callback. | ||
Future<void> close(); | ||
} | ||
|
||
class LockError extends Error { | ||
final String message; | ||
|
||
LockError(this.message); | ||
|
||
@override | ||
String toString() { | ||
return 'LockError: $message'; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import 'dart:async'; | ||
import 'package:meta/meta.dart'; | ||
|
||
import 'package:sqlite_async/sqlite3_common.dart' as sqlite; | ||
import 'package:sqlite_async/src/sqlite_options.dart'; | ||
|
||
/// Factory to create new SQLite database connections. | ||
/// | ||
/// Since connections are opened in dedicated background isolates, this class | ||
/// must be safe to pass to different isolates. | ||
abstract class SqliteOpenFactory<Database extends sqlite.CommonDatabase> { | ||
String get path; | ||
|
||
FutureOr<Database> open(SqliteOpenOptions options); | ||
} | ||
|
||
class SqliteOpenOptions { | ||
/// Whether this is the primary write connection for the database. | ||
final bool primaryConnection; | ||
|
||
/// Whether this connection is read-only. | ||
final bool readOnly; | ||
|
||
const SqliteOpenOptions( | ||
{required this.primaryConnection, required this.readOnly}); | ||
|
||
sqlite.OpenMode get openMode { | ||
if (primaryConnection) { | ||
return sqlite.OpenMode.readWriteCreate; | ||
} else if (readOnly) { | ||
return sqlite.OpenMode.readOnly; | ||
} else { | ||
return sqlite.OpenMode.readWrite; | ||
} | ||
} | ||
} | ||
|
||
/// The default database factory. | ||
/// | ||
/// This takes care of opening the database, and running PRAGMA statements | ||
/// to configure the connection. | ||
/// | ||
/// Override the [open] method to customize the process. | ||
abstract class AbstractDefaultSqliteOpenFactory< | ||
Database extends sqlite.CommonDatabase> | ||
implements SqliteOpenFactory<Database> { | ||
@override | ||
final String path; | ||
final SqliteOptions sqliteOptions; | ||
|
||
const AbstractDefaultSqliteOpenFactory( | ||
{required this.path, | ||
this.sqliteOptions = const SqliteOptions.defaults()}); | ||
|
||
List<String> pragmaStatements(SqliteOpenOptions options); | ||
|
||
@protected | ||
FutureOr<Database> openDB(SqliteOpenOptions options); | ||
|
||
@override | ||
FutureOr<Database> open(SqliteOpenOptions options) async { | ||
var db = await openDB(options); | ||
|
||
for (var statement in pragmaStatements(options)) { | ||
db.execute(statement); | ||
} | ||
return db; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:sqlite_async/src/common/abstract_isolate_connection_factory.dart'; | ||
import 'package:sqlite_async/src/common/abstract_open_factory.dart'; | ||
import 'package:sqlite_async/src/sqlite_queries.dart'; | ||
import 'package:sqlite_async/src/update_notification.dart'; | ||
import 'package:sqlite_async/src/sqlite_connection.dart'; | ||
|
||
/// A SQLite database instance. | ||
/// | ||
/// Use one instance per database file. If multiple instances are used, update | ||
/// notifications may not trigger, and calls may fail with "SQLITE_BUSY" errors. | ||
abstract class AbstractSqliteDatabase extends SqliteConnection | ||
with SqliteQueries { | ||
/// The maximum number of concurrent read transactions if not explicitly specified. | ||
static const int defaultMaxReaders = 5; | ||
|
||
/// Maximum number of concurrent read transactions. | ||
int get maxReaders; | ||
|
||
/// Factory that opens a raw database connection in each isolate. | ||
/// | ||
/// This must be safe to pass to different isolates. | ||
/// | ||
/// Use a custom class for this to customize the open process. | ||
AbstractDefaultSqliteOpenFactory get openFactory; | ||
|
||
/// Use this stream to subscribe to notifications of updates to tables. | ||
@override | ||
Stream<UpdateNotification> get updates; | ||
|
||
final StreamController<UpdateNotification> updatesController = | ||
StreamController.broadcast(); | ||
|
||
Future<void> get isInitialized; | ||
|
||
/// Wait for initialization to complete. | ||
/// | ||
/// While initializing is automatic, this helps to catch and report initialization errors. | ||
Future<void> initialize() async { | ||
await isInitialized; | ||
} | ||
|
||
/// A connection factory that can be passed to different isolates. | ||
/// | ||
/// Use this to access the database in background isolates. | ||
AbstractIsolateConnectionFactory isolateConnectionFactory(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.