File tree Expand file tree Collapse file tree 3 files changed +38
-2
lines changed
packages/web/src/db/adapters Expand file tree Collapse file tree 3 files changed +38
-2
lines changed Original file line number Diff line number Diff line change 1+ import { BatchedUpdateNotification , QueryResult } from '@powersync/common' ;
2+
3+ /**
4+ * Proxied query result does not contain a function for accessing row values
5+ */
6+ export type ProxiedQueryResult = Omit < QueryResult , 'rows' > & {
7+ rows : {
8+ _array : any [ ] ;
9+ length : number ;
10+ } ;
11+ } ;
12+ export type OnTableChangeCallback = ( event : BatchedUpdateNotification ) => void ;
13+
14+ /**
15+ * @internal
16+ * An async Database connection which provides basic async SQL methods.
17+ * This is usually a proxied through a web worker.
18+ */
19+ export interface AsyncDatabaseConnection {
20+ init ( ) : Promise < void > ;
21+ close ( ) : Promise < void > ;
22+ execute ( sql : string , params ?: any [ ] ) : Promise < ProxiedQueryResult > ;
23+ executeBatch ( sql : string , params ?: any [ ] ) : Promise < ProxiedQueryResult > ;
24+ registerOnTableChange ( callback : OnTableChangeCallback ) : ( ) => void ;
25+ }
Original file line number Diff line number Diff line change 1+ import { AsyncDatabaseConnection } from './AsyncDatabaseConnection' ;
2+
3+ export interface ProxiedDatabaseConnection extends AsyncDatabaseConnection {
4+ /**
5+ * Get a MessagePort which can be used to share the internals of this connection.
6+ */
7+ getMessagePort ( ) : MessagePort ;
8+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import * as SQLite from '@journeyapps/wa-sqlite';
22import { BaseObserver , BatchedUpdateNotification } from '@powersync/common' ;
33import { Mutex } from 'async-mutex' ;
44import { OnTableChangeCallback , WASQLExecuteResult } from '../../../shared/types' ;
5+ import { AsyncDatabaseConnection } from '../AsyncDatabaseConnection' ;
56
67/**
78 * List of currently tested virtual filesystems
@@ -95,8 +96,10 @@ export const DEFAULT_MODULE_FACTORIES = {
9596
9697/**
9798 * @internal
99+ * WA-SQLite connection which directly interfaces with WA-SQLite.
100+ * This is usually instantiated inside a worker.
98101 */
99- export class WASqliteConnection extends BaseObserver < WASQLiteConnectionListener > {
102+ export class WASqliteConnection extends BaseObserver < WASQLiteConnectionListener > implements AsyncDatabaseConnection {
100103 private _sqliteAPI : SQLiteAPI | null = null ;
101104 private _dbP : number | null = null ;
102105 private _moduleFactory : WASQLiteModuleFactory ;
@@ -236,7 +239,7 @@ export class WASqliteConnection extends BaseObserver<WASQLiteConnectionListener>
236239 }
237240
238241 async close ( ) {
239- return this . sqliteAPI . close ( this . dbP ) ;
242+ await this . sqliteAPI . close ( this . dbP ) ;
240243 }
241244
242245 registerOnTableChange ( callback : OnTableChangeCallback ) {
You can’t perform that action at this time.
0 commit comments