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 {
78
78
.cast <UpdateNotification >();
79
79
80
80
await database.initialize ();
81
+ await _checkVersion ();
81
82
await database.execute ('SELECT powersync_init()' );
82
83
await updateSchema (schema);
83
84
await _updateHasSynced ();
84
85
}
85
86
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
+
86
117
/// Wait for initialization to complete.
87
118
///
88
119
/// While initializing is automatic, this helps to catch and report initialization errors.
You can’t perform that action at this time.
0 commit comments