@powersync/op-sqlite 0.0.0-dev-20241014162857
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +54 -0
- package/android/build.gradle +124 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/powersync/opsqlite/PowerSyncOpSqliteModule.kt +25 -0
- package/android/src/main/java/com/powersync/opsqlite/PowerSyncOpSqlitePackage.kt +35 -0
- package/android/src/newarch/PowerSyncOpSqliteSpec.kt +7 -0
- package/android/src/oldarch/PowerSyncOpSqliteSpec.kt +11 -0
- package/ios/PowerSyncOpSqlite.h +5 -0
- package/ios/PowerSyncOpSqlite.mm +11 -0
- package/lib/commonjs/NativePowerSyncOpSqlite.js +9 -0
- package/lib/commonjs/NativePowerSyncOpSqlite.js.map +1 -0
- package/lib/commonjs/db/OPSQLiteConnection.js +77 -0
- package/lib/commonjs/db/OPSQLiteConnection.js.map +1 -0
- package/lib/commonjs/db/OPSqliteAdapter.js +214 -0
- package/lib/commonjs/db/OPSqliteAdapter.js.map +1 -0
- package/lib/commonjs/db/OPSqliteDBOpenFactory.js +26 -0
- package/lib/commonjs/db/OPSqliteDBOpenFactory.js.map +1 -0
- package/lib/commonjs/db/SqliteOptions.js +31 -0
- package/lib/commonjs/db/SqliteOptions.js.map +1 -0
- package/lib/commonjs/index.js +35 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/module/NativePowerSyncOpSqlite.js +5 -0
- package/lib/module/NativePowerSyncOpSqlite.js.map +1 -0
- package/lib/module/db/OPSQLiteConnection.js +72 -0
- package/lib/module/db/OPSQLiteConnection.js.map +1 -0
- package/lib/module/db/OPSqliteAdapter.js +209 -0
- package/lib/module/db/OPSqliteAdapter.js.map +1 -0
- package/lib/module/db/OPSqliteDBOpenFactory.js +21 -0
- package/lib/module/db/OPSqliteDBOpenFactory.js.map +1 -0
- package/lib/module/db/SqliteOptions.js +27 -0
- package/lib/module/db/SqliteOptions.js.map +1 -0
- package/lib/module/index.js +19 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/src/NativePowerSyncOpSqlite.d.ts +7 -0
- package/lib/typescript/src/NativePowerSyncOpSqlite.d.ts.map +1 -0
- package/lib/typescript/src/db/OPSQLiteConnection.d.ts +17 -0
- package/lib/typescript/src/db/OPSQLiteConnection.d.ts.map +1 -0
- package/lib/typescript/src/db/OPSqliteAdapter.d.ts +37 -0
- package/lib/typescript/src/db/OPSqliteAdapter.d.ts.map +1 -0
- package/lib/typescript/src/db/OPSqliteDBOpenFactory.d.ts +12 -0
- package/lib/typescript/src/db/OPSqliteDBOpenFactory.d.ts.map +1 -0
- package/lib/typescript/src/db/SqliteOptions.d.ts +39 -0
- package/lib/typescript/src/db/SqliteOptions.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +3 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +112 -0
- package/powersync-op-sqlite.podspec +26 -0
- package/src/NativePowerSyncOpSqlite.ts +8 -0
- package/src/db/OPSQLiteConnection.ts +82 -0
- package/src/db/OPSqliteAdapter.ts +259 -0
- package/src/db/OPSqliteDBOpenFactory.ts +25 -0
- package/src/db/SqliteOptions.ts +54 -0
- package/src/index.ts +30 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { OPSQLiteDBAdapter } from './OPSqliteAdapter';
|
|
4
|
+
import { DEFAULT_SQLITE_OPTIONS } from './SqliteOptions';
|
|
5
|
+
export class OPSqliteOpenFactory {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.options = options;
|
|
8
|
+
this.sqliteOptions = {
|
|
9
|
+
...DEFAULT_SQLITE_OPTIONS,
|
|
10
|
+
...this.options.sqliteOptions
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
openDB() {
|
|
14
|
+
return new OPSQLiteDBAdapter({
|
|
15
|
+
name: this.options.dbFilename,
|
|
16
|
+
dbLocation: this.options.dbLocation,
|
|
17
|
+
sqliteOptions: this.sqliteOptions
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=OPSqliteDBOpenFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["OPSQLiteDBAdapter","DEFAULT_SQLITE_OPTIONS","OPSqliteOpenFactory","constructor","options","sqliteOptions","openDB","name","dbFilename","dbLocation"],"sourceRoot":"../../../src","sources":["db/OPSqliteDBOpenFactory.ts"],"mappings":";;AACA,SAASA,iBAAiB,QAAQ,mBAAmB;AACrD,SAASC,sBAAsB,QAAuB,iBAAiB;AAKvE,OAAO,MAAMC,mBAAmB,CAA2B;EAGzDC,WAAWA,CAAWC,OAAmC,EAAE;IAAA,KAArCA,OAAmC,GAAnCA,OAAmC;IACvD,IAAI,CAACC,aAAa,GAAG;MACnB,GAAGJ,sBAAsB;MACzB,GAAG,IAAI,CAACG,OAAO,CAACC;IAClB,CAAC;EACH;EAEAC,MAAMA,CAAA,EAAc;IAClB,OAAO,IAAIN,iBAAiB,CAAC;MAC3BO,IAAI,EAAE,IAAI,CAACH,OAAO,CAACI,UAAU;MAC7BC,UAAU,EAAE,IAAI,CAACL,OAAO,CAACK,UAAU;MACnCJ,aAAa,EAAE,IAAI,CAACA;IACtB,CAAC,CAAC;EACJ;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// SQLite journal mode. Set on the primary connection.
|
|
4
|
+
// This library is written with WAL mode in mind - other modes may cause
|
|
5
|
+
// unexpected locking behavior.
|
|
6
|
+
var SqliteJournalMode = /*#__PURE__*/function (SqliteJournalMode) {
|
|
7
|
+
SqliteJournalMode["wal"] = "WAL";
|
|
8
|
+
SqliteJournalMode["delete"] = "DELETE";
|
|
9
|
+
SqliteJournalMode["truncate"] = "TRUNCATE";
|
|
10
|
+
SqliteJournalMode["persist"] = "PERSIST";
|
|
11
|
+
SqliteJournalMode["memory"] = "MEMORY";
|
|
12
|
+
SqliteJournalMode["off"] = "OFF";
|
|
13
|
+
return SqliteJournalMode;
|
|
14
|
+
}(SqliteJournalMode || {}); // SQLite file commit mode.
|
|
15
|
+
var SqliteSynchronous = /*#__PURE__*/function (SqliteSynchronous) {
|
|
16
|
+
SqliteSynchronous["normal"] = "NORMAL";
|
|
17
|
+
SqliteSynchronous["full"] = "FULL";
|
|
18
|
+
SqliteSynchronous["off"] = "OFF";
|
|
19
|
+
return SqliteSynchronous;
|
|
20
|
+
}(SqliteSynchronous || {});
|
|
21
|
+
export const DEFAULT_SQLITE_OPTIONS = {
|
|
22
|
+
journalMode: SqliteJournalMode.wal,
|
|
23
|
+
synchronous: SqliteSynchronous.normal,
|
|
24
|
+
journalSizeLimit: 6 * 1024 * 1024,
|
|
25
|
+
lockTimeoutMs: 30000
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=SqliteOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["SqliteJournalMode","SqliteSynchronous","DEFAULT_SQLITE_OPTIONS","journalMode","wal","synchronous","normal","journalSizeLimit","lockTimeoutMs"],"sourceRoot":"../../../src","sources":["db/SqliteOptions.ts"],"mappings":";;AA2BA;AACA;AACA;AAAA,IACKA,iBAAiB,0BAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAA,OAAjBA,iBAAiB;AAAA,EAAjBA,iBAAiB,SAWtB;AAAA,IACKC,iBAAiB,0BAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAA,OAAjBA,iBAAiB;AAAA,EAAjBA,iBAAiB;AAMtB,OAAO,MAAMC,sBAA+C,GAAG;EAC7DC,WAAW,EAAEH,iBAAiB,CAACI,GAAG;EAClCC,WAAW,EAAEJ,iBAAiB,CAACK,MAAM;EACrCC,gBAAgB,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI;EACjCC,aAAa,EAAE;AACjB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { NativeModules, Platform } from 'react-native';
|
|
4
|
+
const LINKING_ERROR = `The package '@powersync/op-sqlite' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
|
|
5
|
+
ios: "- You have run 'pod install'\n",
|
|
6
|
+
default: ''
|
|
7
|
+
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
|
|
8
|
+
const isTurboModuleEnabled = global.__turboModuleProxy != null;
|
|
9
|
+
const PowerSyncOpSqliteModule = isTurboModuleEnabled ? require('./NativePowerSyncOpSqlite').default : NativeModules.PowerSyncOpSqlite;
|
|
10
|
+
const PowerSyncOpSqlite = PowerSyncOpSqliteModule ? PowerSyncOpSqliteModule : new Proxy({}, {
|
|
11
|
+
get() {
|
|
12
|
+
throw new Error(LINKING_ERROR);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
export function getBundlePath() {
|
|
16
|
+
return PowerSyncOpSqlite.getBundlePath();
|
|
17
|
+
}
|
|
18
|
+
export { OPSqliteOpenFactory, OPSQLiteOpenFactoryOptions } from './db/OPSqliteDBOpenFactory';
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","isTurboModuleEnabled","global","__turboModuleProxy","PowerSyncOpSqliteModule","require","PowerSyncOpSqlite","Proxy","get","Error","getBundlePath","OPSqliteOpenFactory","OPSQLiteOpenFactoryOptions"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEtD,MAAMC,aAAa,GACjB,+EAA+E,GAC/ED,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,oBAAoB,GAAGC,MAAM,CAACC,kBAAkB,IAAI,IAAI;AAE9D,MAAMC,uBAAuB,GAAGH,oBAAoB,GAChDI,OAAO,CAAC,2BAA2B,CAAC,CAACL,OAAO,GAC5CL,aAAa,CAACW,iBAAiB;AAEnC,MAAMA,iBAAiB,GAAGF,uBAAuB,GAC7CA,uBAAuB,GACvB,IAAIG,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACZ,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAEL,OAAO,SAASa,aAAaA,CAAA,EAAW;EACtC,OAAOJ,iBAAiB,CAACI,aAAa,CAAC,CAAC;AAC1C;AAEA,SAASC,mBAAmB,EAAEC,0BAA0B,QAAQ,4BAA4B","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativePowerSyncOpSqlite.d.ts","sourceRoot":"","sources":["../../../src/NativePowerSyncOpSqlite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,aAAa,IAAI,MAAM,CAAC;CACzB;;AAED,wBAA2E"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DB } from '@op-engineering/op-sqlite';
|
|
2
|
+
import { BaseObserver, DBAdapterListener, QueryResult } from '@powersync/common';
|
|
3
|
+
export type OPSQLiteConnectionOptions = {
|
|
4
|
+
baseDB: DB;
|
|
5
|
+
};
|
|
6
|
+
export declare class OPSQLiteConnection extends BaseObserver<DBAdapterListener> {
|
|
7
|
+
protected options: OPSQLiteConnectionOptions;
|
|
8
|
+
protected DB: DB;
|
|
9
|
+
constructor(options: OPSQLiteConnectionOptions);
|
|
10
|
+
close(): void;
|
|
11
|
+
execute(query: string, params?: any[]): Promise<QueryResult>;
|
|
12
|
+
executeBatch(query: string, params?: any[][]): Promise<QueryResult>;
|
|
13
|
+
getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
|
|
14
|
+
getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
|
|
15
|
+
get<T>(sql: string, parameters?: any[]): Promise<T>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=OPSQLiteConnection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OPSQLiteConnection.d.ts","sourceRoot":"","sources":["../../../../src/db/OPSQLiteConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAiB,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAiB,MAAM,mBAAmB,CAAC;AAEhG,MAAM,MAAM,yBAAyB,GAAG;IACtC,MAAM,EAAE,EAAE,CAAC;CACZ,CAAC;AAEF,qBAAa,kBAAmB,SAAQ,YAAY,CAAC,iBAAiB,CAAC;IAEzD,SAAS,CAAC,OAAO,EAAE,yBAAyB;IADxD,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC;gBACK,OAAO,EAAE,yBAAyB;IA4BxD,KAAK;IAIC,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAa5D,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,GAAG,EAAE,EAAO,GAAG,OAAO,CAAC,WAAW,CAAC;IAUvE,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAKxD,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAKlE,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC;CAO1D"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BaseObserver, DBAdapter, DBAdapterListener, DBLockOptions, QueryResult, Transaction } from '@powersync/common';
|
|
2
|
+
import Lock from 'async-lock';
|
|
3
|
+
import { OPSQLiteConnection } from './OPSQLiteConnection';
|
|
4
|
+
import { SqliteOptions } from './SqliteOptions';
|
|
5
|
+
/**
|
|
6
|
+
* Adapter for React Native Quick SQLite
|
|
7
|
+
*/
|
|
8
|
+
export type OPSQLiteAdapterOptions = {
|
|
9
|
+
name: string;
|
|
10
|
+
dbLocation?: string;
|
|
11
|
+
sqliteOptions?: SqliteOptions;
|
|
12
|
+
};
|
|
13
|
+
export declare class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implements DBAdapter {
|
|
14
|
+
protected options: OPSQLiteAdapterOptions;
|
|
15
|
+
name: string;
|
|
16
|
+
protected locks: Lock;
|
|
17
|
+
protected initialized: Promise<void>;
|
|
18
|
+
protected readConnections: OPSQLiteConnection[] | null;
|
|
19
|
+
protected writeConnection: OPSQLiteConnection | null;
|
|
20
|
+
constructor(options: OPSQLiteAdapterOptions);
|
|
21
|
+
protected init(): Promise<void>;
|
|
22
|
+
protected openConnection(dbLocation: string, filenameOverride?: string): Promise<OPSQLiteConnection>;
|
|
23
|
+
private getDbLocation;
|
|
24
|
+
private loadExtension;
|
|
25
|
+
close(): void;
|
|
26
|
+
readLock<T>(fn: (tx: OPSQLiteConnection) => Promise<T>, options?: DBLockOptions): Promise<T>;
|
|
27
|
+
writeLock<T>(fn: (tx: OPSQLiteConnection) => Promise<T>, options?: DBLockOptions): Promise<T>;
|
|
28
|
+
readTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
|
|
29
|
+
writeTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
|
|
30
|
+
getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
|
|
31
|
+
getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
|
|
32
|
+
get<T>(sql: string, parameters?: any[]): Promise<T>;
|
|
33
|
+
execute(query: string, params?: any[]): Promise<QueryResult>;
|
|
34
|
+
executeBatch(query: string, params?: any[][]): Promise<QueryResult>;
|
|
35
|
+
protected internalTransaction<T>(connection: OPSQLiteConnection, fn: (tx: Transaction) => Promise<T>): Promise<T>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=OPSqliteAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OPSqliteAdapter.d.ts","sourceRoot":"","sources":["../../../../src/db/OPSqliteAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,WAAW,EAEX,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAE3B,OAAO,IAAI,MAAM,YAAY,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAA0B,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAExE;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B,CAAC;AASF,qBAAa,iBAAkB,SAAQ,YAAY,CAAC,iBAAiB,CAAE,YAAW,SAAS;IAU7E,SAAS,CAAC,OAAO,EAAE,sBAAsB;IATrD,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC;IAEtB,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAErC,SAAS,CAAC,eAAe,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAAC;IAEvD,SAAS,CAAC,eAAe,EAAE,kBAAkB,GAAG,IAAI,CAAC;gBAE/B,OAAO,EAAE,sBAAsB;cAUrC,IAAI;cAwDJ,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,gBAAgB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAgB1G,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,aAAa;IAUrB,KAAK;IAOC,QAAQ,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,kBAAkB,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC;IA4B5F,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,kBAAkB,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC;IAkBnG,eAAe,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC;IAI5F,gBAAgB,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC;IAI7F,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAIxD,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAIlE,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC;IAInD,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE;IAI/B,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,GAAG,EAAE,EAAO,GAAG,OAAO,CAAC,WAAW,CAAC;cAI7D,mBAAmB,CAAC,CAAC,EACnC,UAAU,EAAE,kBAAkB,EAC9B,EAAE,EAAE,CAAC,EAAE,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GAClC,OAAO,CAAC,CAAC,CAAC;CAiCd"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DBAdapter, SQLOpenFactory, SQLOpenOptions } from '@powersync/common';
|
|
2
|
+
import { SqliteOptions } from './SqliteOptions';
|
|
3
|
+
export interface OPSQLiteOpenFactoryOptions extends SQLOpenOptions {
|
|
4
|
+
sqliteOptions?: SqliteOptions;
|
|
5
|
+
}
|
|
6
|
+
export declare class OPSqliteOpenFactory implements SQLOpenFactory {
|
|
7
|
+
protected options: OPSQLiteOpenFactoryOptions;
|
|
8
|
+
private sqliteOptions;
|
|
9
|
+
constructor(options: OPSQLiteOpenFactoryOptions);
|
|
10
|
+
openDB(): DBAdapter;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=OPSqliteDBOpenFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OPSqliteDBOpenFactory.d.ts","sourceRoot":"","sources":["../../../../src/db/OPSqliteDBOpenFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE9E,OAAO,EAA0B,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAExE,MAAM,WAAW,0BAA2B,SAAQ,cAAc;IAChE,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AACD,qBAAa,mBAAoB,YAAW,cAAc;IAG5C,SAAS,CAAC,OAAO,EAAE,0BAA0B;IAFzD,OAAO,CAAC,aAAa,CAA0B;gBAEzB,OAAO,EAAE,0BAA0B;IAOzD,MAAM,IAAI,SAAS;CAOpB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface SqliteOptions {
|
|
2
|
+
/**
|
|
3
|
+
* SQLite journal mode. Defaults to [SqliteJournalMode.wal].
|
|
4
|
+
*/
|
|
5
|
+
journalMode?: SqliteJournalMode;
|
|
6
|
+
/**
|
|
7
|
+
* SQLite synchronous flag. Defaults to [SqliteSynchronous.normal], which
|
|
8
|
+
* is safe for WAL mode.
|
|
9
|
+
*/
|
|
10
|
+
synchronous?: SqliteSynchronous;
|
|
11
|
+
/**
|
|
12
|
+
* Journal/WAL size limit. Defaults to 6MB.
|
|
13
|
+
* The WAL may grow larger than this limit during writes, but SQLite will
|
|
14
|
+
* attempt to truncate the file afterwards.
|
|
15
|
+
*/
|
|
16
|
+
journalSizeLimit?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Timeout in milliseconds waiting for locks to be released by other connections.
|
|
19
|
+
* Defaults to 30 seconds.
|
|
20
|
+
* Set to null or zero to fail immediately when the database is locked.
|
|
21
|
+
*/
|
|
22
|
+
lockTimeoutMs?: number;
|
|
23
|
+
}
|
|
24
|
+
declare enum SqliteJournalMode {
|
|
25
|
+
wal = "WAL",
|
|
26
|
+
delete = "DELETE",
|
|
27
|
+
truncate = "TRUNCATE",
|
|
28
|
+
persist = "PERSIST",
|
|
29
|
+
memory = "MEMORY",
|
|
30
|
+
off = "OFF"
|
|
31
|
+
}
|
|
32
|
+
declare enum SqliteSynchronous {
|
|
33
|
+
normal = "NORMAL",
|
|
34
|
+
full = "FULL",
|
|
35
|
+
off = "OFF"
|
|
36
|
+
}
|
|
37
|
+
export declare const DEFAULT_SQLITE_OPTIONS: Required<SqliteOptions>;
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=SqliteOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SqliteOptions.d.ts","sourceRoot":"","sources":["../../../../src/db/SqliteOptions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAEhC;;;OAGG;IACH,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAEhC;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAKD,aAAK,iBAAiB;IAGpB,GAAG,QAAQ;IACX,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,GAAG,QAAQ;CACZ;AAGD,aAAK,iBAAiB;IACpB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,GAAG,QAAQ;CACZ;AAED,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,aAAa,CAK1D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAyBA,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED,OAAO,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@powersync/op-sqlite",
|
|
3
|
+
"version": "0.0.0-dev-20241014162857",
|
|
4
|
+
"description": "Powersync",
|
|
5
|
+
"source": "./src/index.ts",
|
|
6
|
+
"main": "./lib/commonjs/index.js",
|
|
7
|
+
"module": "./lib/module/index.js",
|
|
8
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
9
|
+
"react-native": "./src/index",
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"lib",
|
|
13
|
+
"android",
|
|
14
|
+
"ios",
|
|
15
|
+
"cpp",
|
|
16
|
+
"*.podspec",
|
|
17
|
+
"!ios/build",
|
|
18
|
+
"!android/build",
|
|
19
|
+
"!android/gradle",
|
|
20
|
+
"!android/gradlew",
|
|
21
|
+
"!android/gradlew.bat",
|
|
22
|
+
"!android/local.properties",
|
|
23
|
+
"!**/__tests__",
|
|
24
|
+
"!**/__fixtures__",
|
|
25
|
+
"!**/__mocks__",
|
|
26
|
+
"!**/.*"
|
|
27
|
+
],
|
|
28
|
+
"keywords": [
|
|
29
|
+
"react-native",
|
|
30
|
+
"ios",
|
|
31
|
+
"android"
|
|
32
|
+
],
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/powersync-ja/powersync-js.git"
|
|
36
|
+
},
|
|
37
|
+
"author": "PowerSync",
|
|
38
|
+
"license": "Apache-2.0",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/powersync-ja/powersync-js/issues"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://docs.powersync.com/",
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"registry": "https://registry.npmjs.org/",
|
|
45
|
+
"access": "public"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"@op-engineering/op-sqlite": "^9.1.3",
|
|
49
|
+
"@powersync/common": "^1.20.0",
|
|
50
|
+
"react": "*",
|
|
51
|
+
"react-native": "*"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"async-lock": "^1.4.0",
|
|
55
|
+
"@powersync/common": "1.20.0"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@op-engineering/op-sqlite": "^9.1.3",
|
|
59
|
+
"@react-native/eslint-config": "^0.73.1",
|
|
60
|
+
"@types/async-lock": "^1.4.0",
|
|
61
|
+
"@types/react": "^18.2.44",
|
|
62
|
+
"del-cli": "^5.1.0",
|
|
63
|
+
"eslint": "^8.51.0",
|
|
64
|
+
"eslint-config-prettier": "^9.0.0",
|
|
65
|
+
"eslint-plugin-prettier": "^5.0.1",
|
|
66
|
+
"prettier": "^3.0.3",
|
|
67
|
+
"react": "18.3.1",
|
|
68
|
+
"react-native": "0.75.3",
|
|
69
|
+
"react-native-builder-bob": "^0.30.2",
|
|
70
|
+
"turbo": "^1.10.7",
|
|
71
|
+
"typescript": "^5.2.2"
|
|
72
|
+
},
|
|
73
|
+
"eslintIgnore": [
|
|
74
|
+
"node_modules/",
|
|
75
|
+
"lib/"
|
|
76
|
+
],
|
|
77
|
+
"react-native-builder-bob": {
|
|
78
|
+
"source": "src",
|
|
79
|
+
"output": "lib",
|
|
80
|
+
"targets": [
|
|
81
|
+
"codegen",
|
|
82
|
+
"commonjs",
|
|
83
|
+
"module",
|
|
84
|
+
[
|
|
85
|
+
"typescript",
|
|
86
|
+
{
|
|
87
|
+
"project": "tsconfig.build.json",
|
|
88
|
+
"tsc": "../../node_modules/.bin/tsc"
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
]
|
|
92
|
+
},
|
|
93
|
+
"codegenConfig": {
|
|
94
|
+
"name": "RNPowerSyncOpSqliteSpec",
|
|
95
|
+
"type": "modules",
|
|
96
|
+
"jsSrcsDir": "src",
|
|
97
|
+
"outputDir": {
|
|
98
|
+
"ios": "codegen",
|
|
99
|
+
"android": "codegen"
|
|
100
|
+
},
|
|
101
|
+
"android": {
|
|
102
|
+
"javaPackageName": "com.powersync.opsqlite"
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
"scripts": {
|
|
106
|
+
"build": "bob build",
|
|
107
|
+
"build:prod": "bob build",
|
|
108
|
+
"typecheck": "tsc",
|
|
109
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
110
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "powersync-op-sqlite"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
14
|
+
s.source = { :git => "https://github.com/mugikhan/powersync-op-sqlite.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.source_files = "ios/**/*.{h,m,mm,cpp}"
|
|
17
|
+
|
|
18
|
+
s.dependency "React-callinvoker"
|
|
19
|
+
s.dependency "React"
|
|
20
|
+
s.dependency "powersync-sqlite-core", "~> 0.3.0"
|
|
21
|
+
if defined?(install_modules_dependencies())
|
|
22
|
+
install_modules_dependencies(s)
|
|
23
|
+
else
|
|
24
|
+
s.dependency "React-Core"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { DB, SQLBatchTuple } from '@op-engineering/op-sqlite';
|
|
2
|
+
import { BaseObserver, DBAdapterListener, QueryResult, RowUpdateType } from '@powersync/common';
|
|
3
|
+
|
|
4
|
+
export type OPSQLiteConnectionOptions = {
|
|
5
|
+
baseDB: DB;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export class OPSQLiteConnection extends BaseObserver<DBAdapterListener> {
|
|
9
|
+
protected DB: DB;
|
|
10
|
+
constructor(protected options: OPSQLiteConnectionOptions) {
|
|
11
|
+
super();
|
|
12
|
+
this.DB = options.baseDB;
|
|
13
|
+
|
|
14
|
+
// link table update commands
|
|
15
|
+
this.DB.updateHook((update) => {
|
|
16
|
+
this.iterateListeners((cb) => {
|
|
17
|
+
let opType: RowUpdateType;
|
|
18
|
+
switch (update.operation) {
|
|
19
|
+
case 'INSERT':
|
|
20
|
+
opType = RowUpdateType.SQLITE_INSERT;
|
|
21
|
+
break;
|
|
22
|
+
case 'DELETE':
|
|
23
|
+
opType = RowUpdateType.SQLITE_DELETE;
|
|
24
|
+
break;
|
|
25
|
+
case 'UPDATE':
|
|
26
|
+
opType = RowUpdateType.SQLITE_UPDATE;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
cb.tablesUpdated?.({
|
|
30
|
+
table: update.table,
|
|
31
|
+
opType,
|
|
32
|
+
rowId: update.rowId
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
close() {
|
|
39
|
+
return this.DB.close();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async execute(query: string, params?: any[]): Promise<QueryResult> {
|
|
43
|
+
const res = await this.DB.execute(query, params);
|
|
44
|
+
return {
|
|
45
|
+
insertId: res.insertId,
|
|
46
|
+
rowsAffected: res.rowsAffected,
|
|
47
|
+
rows: {
|
|
48
|
+
_array: res.rows ?? [],
|
|
49
|
+
length: res.rows?.length ?? 0,
|
|
50
|
+
item: (index: number) => res.rows?.[index]
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async executeBatch(query: string, params: any[][] = []): Promise<QueryResult> {
|
|
56
|
+
const tuple: SQLBatchTuple[] = [[query, params[0]]];
|
|
57
|
+
params.slice(1).forEach((p) => tuple.push([query, p]));
|
|
58
|
+
|
|
59
|
+
const result = await this.DB.executeBatch(tuple);
|
|
60
|
+
return {
|
|
61
|
+
rowsAffected: result.rowsAffected ?? 0
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async getAll<T>(sql: string, parameters?: any[]): Promise<T[]> {
|
|
66
|
+
const result = await this.DB.execute(sql, parameters);
|
|
67
|
+
return result.rows ?? [];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async getOptional<T>(sql: string, parameters?: any[]): Promise<T | null> {
|
|
71
|
+
const result = await this.DB.execute(sql, parameters);
|
|
72
|
+
return result.rows?.[0] ?? null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async get<T>(sql: string, parameters?: any[]): Promise<T> {
|
|
76
|
+
const result = await this.getOptional(sql, parameters);
|
|
77
|
+
if (!result) {
|
|
78
|
+
throw new Error('Result set is empty');
|
|
79
|
+
}
|
|
80
|
+
return result as T;
|
|
81
|
+
}
|
|
82
|
+
}
|