Skip to content

Commit 515b6fc

Browse files
committed
Added refreshSchema to DBAdapter.
1 parent 7816d88 commit 515b6fc

File tree

7 files changed

+22
-0
lines changed

7 files changed

+22
-0
lines changed

packages/common/src/client/AbstractPowerSyncDatabase.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
362362
this._schema = schema;
363363

364364
await this.database.execute('SELECT powersync_replace_schema(?)', [JSON.stringify(this.schema.toJSON())]);
365+
await this.database.refreshSchema();
365366
this.iterateListeners(async (cb) => cb.schemaChanged?.(schema));
366367
}
367368

packages/common/src/db/DBAdapter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export interface DBAdapter extends BaseObserverInterface<DBAdapterListener>, DBG
101101
readTransaction: <T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions) => Promise<T>;
102102
writeLock: <T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) => Promise<T>;
103103
writeTransaction: <T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions) => Promise<T>;
104+
refreshSchema: () => Promise<void>;
104105
}
105106

106107
export function isBatchedUpdateNotification(

packages/powersync-op-sqlite/src/db/OPSQLiteConnection.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,8 @@ export class OPSQLiteConnection extends BaseObserver<DBAdapterListener> {
7979
}
8080
return result as T;
8181
}
82+
83+
async refreshSchema() {
84+
await this.get("PRAGMA table_info('sqlite_master')");
85+
}
8286
}

packages/powersync-op-sqlite/src/db/OPSqliteAdapter.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,12 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
259259
throw ex;
260260
}
261261
}
262+
263+
async refreshSchema(): Promise<void> {
264+
await this.writeConnection?.refreshSchema();
265+
266+
for (let connection of this.readConnections) {
267+
await connection.refreshSchema();
268+
}
269+
}
262270
}

packages/react-native/src/db/adapters/react-native-quick-sqlite/RNQSDBAdapter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,8 @@ export class RNQSDBAdapter extends BaseObserver<DBAdapterListener> implements DB
124124
}
125125
};
126126
}
127+
128+
async refreshSchema() {
129+
await this.baseDB.refreshSchema();
130+
}
127131
}

packages/web/src/db/adapters/SSRDBAdapter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,6 @@ export class SSRDBAdapter extends BaseObserver<DBAdapterListener> implements DBA
8585
}
8686
};
8787
}
88+
89+
async refreshSchema(): Promise<void> {}
8890
}

packages/web/src/db/adapters/wa-sqlite/WASQLiteDBAdapter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,6 @@ export class WASQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
275275
}
276276
};
277277
}
278+
279+
async refreshSchema(): Promise<void> {}
278280
}

0 commit comments

Comments
 (0)