Skip to content

Commit

Permalink
WIP: RNQS require
Browse files Browse the repository at this point in the history
  • Loading branch information
mugikhan committed Oct 1, 2024
1 parent f68c45a commit bc065e3
Show file tree
Hide file tree
Showing 7 changed files with 20,052 additions and 28,310 deletions.
12 changes: 9 additions & 3 deletions demos/react-native-supabase-todolist/library/powersync/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ export class System {
this.kvStorage = new KVStorage();
this.supabaseConnector = new SupabaseConnector(this);
this.storage = this.supabaseConnector.storage;
const factory = new OPSqliteOpenFactory({
dbFilename: 'powersync.db'
// const factory = new OPSqliteOpenFactory({
// dbFilename: 'powersync.db'
// });
// this.powersync = new PowerSyncDatabase({ database: factory, schema: AppSchema });
this.powersync = new PowerSyncDatabase({
schema: AppSchema,
database: {
dbFilename: 'sqlite.db'
}
});
this.powersync = new PowerSyncDatabase({ database: factory, schema: AppSchema });

if (AppConfig.supabaseBucket) {
this.attachmentQueue = new PhotoAttachmentQueue({
Expand Down
3 changes: 1 addition & 2 deletions packages/powersync-op-sqlite/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@
{
"path": "../common"
}
],
"include": ["src/**/*"]
]
}
10 changes: 8 additions & 2 deletions packages/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,23 @@
},
"homepage": "https://docs.powersync.com/",
"peerDependencies": {
"@journeyapps/react-native-quick-sqlite": "^1.4.0",
"@powersync/common": "workspace:^1.15.0",
"react": "*",
"react-native": "*"
},
"peerDependenciesMeta": {
"@journeyapps/react-native-quick-sqlite": {
"optional": true
}
},
"dependencies": {
"@powersync/common": "workspace:*",
"@powersync/react": "workspace:*",
"async-mutex": "^0.5.0"
"@powersync/react": "workspace:*"
},
"devDependencies": {
"@craftzdog/react-native-buffer": "^6.0.5",
"@journeyapps/react-native-quick-sqlite": "^1.4.0",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-inject": "^5.0.5",
Expand Down
2 changes: 0 additions & 2 deletions packages/react-native/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ export default (commandLineArgs) => {
],
external: [
'@journeyapps/react-native-quick-sqlite',
'@op-engineering/op-sqlite',
'@powersync/common',
'@powersync/react',
'@powersync/op-sqlite',
'node-fetch',
'js-logger',
'react-native',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
DBGetUtils,
QueryResult
} from '@powersync/common';
import { QuickSQLiteConnection } from '@journeyapps/react-native-quick-sqlite';
import type { QuickSQLiteConnection } from '@journeyapps/react-native-quick-sqlite';

/**
* Adapter for React Native Quick SQLite
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// import { open, QuickSQLite, QuickSQLiteConnection } from '@journeyapps/react-native-quick-sqlite';

import { DBAdapter, SQLOpenFactory, SQLOpenOptions } from '@powersync/common';
import { RNQSDBAdapter } from './RNQSDBAdapter';

Expand All @@ -18,22 +16,24 @@ export class ReactNativeQuickSqliteOpenFactory implements SQLOpenFactory {
* in the options (if provided)
* https://github.com/margelo/react-native-quick-sqlite/blob/main/README.md#loading-existing-dbs
*/
// const { dbFilename } = this.options;
// const openOptions = { location: this.options.dbLocation };
// let DB: QuickSQLiteConnection;
// try {
// // Hot reloads can sometimes clear global JS state, but not close DB on native side
// DB = open(dbFilename, openOptions);
// } catch (ex) {
// if (ex.message.includes('already open')) {
// QuickSQLite.close(dbFilename);
// DB = open(dbFilename, openOptions);
// } else {
// throw ex;
// }
// }

// TODO need to conditionally use this package
return new RNQSDBAdapter({} as any, this.options.dbFilename);
const { dbFilename } = this.options;
const openOptions = { location: this.options.dbLocation };
let DB;
try {
const rnqs = require('@journeyapps/react-native-quick-sqlite');
// Hot reloads can sometimes clear global JS state, but not close DB on native side
DB = rnqs.open(dbFilename, openOptions);
} catch (ex) {
const rnqs = require('@journeyapps/react-native-quick-sqlite');
if (ex.message.includes('already open')) {
rnqs.QuickSQLite.close(dbFilename);
DB = rnqs.open(dbFilename, openOptions);
} else {
throw ex;
}
}

return new RNQSDBAdapter(DB, this.options.dbFilename);
}
}
Loading

0 comments on commit bc065e3

Please sign in to comment.