@@ -60,6 +60,7 @@ private RequiredMDSQLiteOptions ResolveMDSQLiteOptions(MDSQLiteOptions? options)
6060 LockTimeoutMs = options ? . LockTimeoutMs ?? defaults . LockTimeoutMs ,
6161 EncryptionKey = options ? . EncryptionKey ?? defaults . EncryptionKey ,
6262 Extensions = options ? . Extensions ?? defaults . Extensions ,
63+ LoadPowerSyncExtension = options ? . LoadPowerSyncExtension ?? defaults . LoadPowerSyncExtension ,
6364 ReadPoolSize = options ? . ReadPoolSize ?? defaults . ReadPoolSize ,
6465 } ;
6566 }
@@ -105,7 +106,7 @@ private async Task Init()
105106 }
106107 return readConnection ;
107108 } ;
108- readPool = new MDSQLiteConnectionPool ( resolvedOptions , readConnectionFactory ) ;
109+ readPool = new MDSQLiteConnectionPool ( resolvedOptions . ReadPoolSize , readConnectionFactory ) ;
109110 await readPool . Init ( ) ;
110111
111112 // Register TablesUpdated listener
@@ -144,12 +145,27 @@ private static SqliteConnection OpenDatabase(string dbFilename)
144145 protected virtual void LoadExtensions ( SqliteConnection db )
145146 {
146147 db . EnableExtensions ( true ) ;
148+ if ( resolvedOptions . LoadPowerSyncExtension )
149+ {
150+ LoadDefaultPowerSyncExtension ( db ) ;
151+ }
147152 foreach ( var extension in resolvedOptions . Extensions )
148153 {
149154 db . LoadExtension ( extension . Path , extension . EntryPoint ) ;
150155 }
151156 }
152157
158+ /// <summary>
159+ /// Loads the bundled PowerSync core SQLite extension. Override on
160+ /// platform-specific adapters (e.g. MAUI iOS/Android) where the native library
161+ /// lives outside the desktop runtime path.
162+ /// </summary>
163+ protected virtual void LoadDefaultPowerSyncExtension ( SqliteConnection db )
164+ {
165+ var path = PowerSyncPathResolver . GetNativeLibraryPath ( AppContext . BaseDirectory ) ;
166+ db . LoadExtension ( path , "sqlite3_powersync_init" ) ;
167+ }
168+
153169 public async Task Close ( )
154170 {
155171 tablesUpdatedCts ? . Cancel ( ) ;
@@ -303,18 +319,16 @@ await readPool.LeaseAll(async (connections) =>
303319
304320class MDSQLiteConnectionPool
305321{
306- private readonly RequiredMDSQLiteOptions _options ;
307322 private readonly Channel < MDSQLiteConnection > _channel ;
308323 private readonly int _poolSize ;
309324 private readonly Func < Task < MDSQLiteConnection > > _connectionFactory ;
310325
311326 private readonly Task _initialized ;
312327
313- public MDSQLiteConnectionPool ( RequiredMDSQLiteOptions options , Func < Task < MDSQLiteConnection > > connectionFactory )
328+ public MDSQLiteConnectionPool ( int poolSize , Func < Task < MDSQLiteConnection > > connectionFactory )
314329 {
315- _options = options ;
316- _channel = Channel . CreateBounded < MDSQLiteConnection > ( options . ReadPoolSize ) ;
317- _poolSize = options . ReadPoolSize ;
330+ _channel = Channel . CreateBounded < MDSQLiteConnection > ( poolSize ) ;
331+ _poolSize = poolSize ;
318332 _connectionFactory = connectionFactory ;
319333 _initialized = Initialize ( ) ;
320334 }
@@ -366,34 +380,6 @@ public async Task LeaseAll(Func<List<MDSQLiteConnection>, Task> callback)
366380 }
367381 }
368382
369- private async Task < MDSQLiteConnection > OpenConnection ( string dbFilename )
370- {
371- var db = OpenDatabase ( dbFilename ) ;
372- LoadExtensions ( db ) ;
373-
374- var connection = new MDSQLiteConnection ( new MDSQLiteConnectionOptions ( db ) ) ;
375- await connection . Execute ( "SELECT powersync_init()" ) ;
376-
377- return connection ;
378- }
379-
380- private static SqliteConnection OpenDatabase ( string dbFilename )
381- {
382- string connectionString = $ "Data Source={ dbFilename } ;Pooling=False;";
383- var connection = new SqliteConnection ( connectionString ) ;
384- connection . Open ( ) ;
385- return connection ;
386- }
387-
388- private void LoadExtensions ( SqliteConnection db )
389- {
390- db . EnableExtensions ( true ) ;
391- foreach ( var extension in _options . Extensions )
392- {
393- db . LoadExtension ( extension . Path , extension . EntryPoint ) ;
394- }
395- }
396-
397383 public async Task Close ( )
398384 {
399385 await LeaseAll ( ( connections ) =>
0 commit comments