Skip to content
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

Drift Example #60

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft

Drift Example #60

wants to merge 9 commits into from

Conversation

rkistner
Copy link
Contributor

@rkistner rkistner commented Feb 14, 2024

POC of using Drift as an ORM for the supabase-todolist demo.

The bulk of the integration is in the drift_sqlite_async.dart file, loosely based on the drift_sqflite query executor. The implementation applies to sqlite_async in general - nothing is directly coupled to PowerSync.
Update: Uses the new drift_sqlite_async package.

Tested and working:

  • Querying
  • Watching queries
  • Insert, update and delete
  • Custom queries
  • Transactions, nested transactions
  • Drift migrations (not that relevant when using PowerSync).

@rodydavis
Copy link

rodydavis commented Feb 14, 2024

You can make drift work with concurrency via WAL mode:

Native

...
return NativeDatabase.createInBackground(
     file,
     logStatements: logStatements,
     cachePreparedStatements: true,
     setup: (db) {
       db.execute('PRAGMA journal_mode=WAL');
       db.execute('PRAGMA busy_timeout=100');
     },
);
...

Web (WASM)

...
final result = await WasmDatabase.open(
     databaseName: dbName.replaceAll('.db', ''),
     sqlite3Uri: sqliteUrl,
     driftWorkerUri: Uri.parse('/drift_worker.js'),
     initializeDatabase: preload,
     localSetup: (db) {
       db.execute('PRAGMA journal_mode=WAL');
       db.execute('PRAGMA busy_timeout=100');
     },
);
...

@rkistner
Copy link
Contributor Author

In this case the database is managed by sqlite_async, which already uses WAL mode. The problem is with write we interact with Drift, we need write locks even for select statements (implicit in db.execute), we prevents any actual concurrency.

Also FWIW, no current VFS supports PRAGMA journal_mode=WAL on web/WASM.

@rkistner
Copy link
Contributor Author

Now published as drift_sqlite_async v0.1.0-alpha.1:

https://github.com/powersync-ja/drift_sqlite_async
https://pub.dev/packages/drift_sqlite_async

@rkistner rkistner closed this Feb 20, 2024
@rkistner rkistner deleted the drift-poc branch February 20, 2024 14:58
@rkistner rkistner restored the drift-poc branch February 20, 2024 14:58
@rkistner rkistner reopened this Feb 20, 2024
@benitav benitav changed the title Drift POC Drift Example Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants