Skip to content

Drift Example #60

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

Closed
wants to merge 9 commits into from
Closed

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
@arbile26
Copy link

Is this feature abandoned?
I see it has been 4 months since the first alpha version of drift_sqlite_async is published.
Using Drift with PowerSync is revolutionary! We have many apps can benefit from this feature.
Hope you give more attention to this feature.

@rkistner
Copy link
Contributor Author

While it may lack some features, we haven't had any significant issue reports for it yet, which is why there hasn't been any updates since.

Right now we're focusing on getting web support stable. Once that is out, we'll work on getting this package better integrated and part of our standard examples.

@rkistner
Copy link
Contributor Author

rkistner commented Aug 6, 2024

Closing in favor of #134.

@rkistner rkistner closed this Aug 6, 2024
@rkistner rkistner deleted the drift-poc branch August 6, 2024 13:47
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.

3 participants