File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
packages/powersync/lib/src/database Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -78,11 +78,42 @@ mixin PowerSyncDatabaseMixin implements SqliteConnection {
7878 .cast <UpdateNotification >();
7979
8080 await database.initialize ();
81+ await _checkVersion ();
8182 await database.execute ('SELECT powersync_init()' );
8283 await updateSchema (schema);
8384 await _updateHasSynced ();
8485 }
8586
87+ /// Check that a supported version of the powersync extension is loaded.
88+ Future <void > _checkVersion () async {
89+ // Get version
90+ String version;
91+ try {
92+ final row =
93+ await database.get ('SELECT powersync_rs_version() as version' );
94+ version = row['version' ];
95+ } catch (e) {
96+ throw SqliteException (
97+ 1 , 'The powersync extension is not loaded correctly. Details: $e ' );
98+ }
99+
100+ // Parse version
101+ List <int > versionInts;
102+ try {
103+ versionInts =
104+ version.split (RegExp (r'[./]' )).take (3 ).map (int .parse).toList ();
105+ } catch (e) {
106+ throw SqliteException (1 ,
107+ 'Unsupported powersync extension version. Need ^0.2.0, got: $version . Details: $e ' );
108+ }
109+
110+ // Validate ^0.2.0
111+ if (versionInts[0 ] != 0 || versionInts[1 ] != 2 || versionInts[2 ] < 0 ) {
112+ throw SqliteException (1 ,
113+ 'Unsupported powersync extension version. Need ^0.2.0, got: $version ' );
114+ }
115+ }
116+
86117 /// Wait for initialization to complete.
87118 ///
88119 /// While initializing is automatic, this helps to catch and report initialization errors.
You can’t perform that action at this time.
0 commit comments