File tree Expand file tree Collapse file tree 3 files changed +25
-8
lines changed
packages/powersync-sdk-react-native
src/db/adapters/react-native-quick-sqlite Expand file tree Collapse file tree 3 files changed +25
-8
lines changed Original file line number Diff line number Diff line change 2424 },
2525 "homepage" : " https://docs.powersync.co/" ,
2626 "peerDependencies" : {
27- "@journeyapps/react-native-quick-sqlite" : " ^ 0.0.1 " ,
27+ "@journeyapps/react-native-quick-sqlite" : " 0.0.0-dev-20231023173642 " ,
2828 "base-64" : " ^1.0.0" ,
2929 "react" : " *" ,
3030 "react-native-fetch-api" : " ^3.0.0" ,
4040 "async-lock" : " ^1.4.0"
4141 },
4242 "devDependencies" : {
43- "@journeyapps/react-native-quick-sqlite" : " ^ 0.0.1 " ,
43+ "@journeyapps/react-native-quick-sqlite" : " 0.0.0-dev-20231023173642 " ,
4444 "@types/async-lock" : " ^1.4.0" ,
4545 "react" : " 18.2.0" ,
4646 "typescript" : " ^4.1.3"
Original file line number Diff line number Diff line change 1- import { open } from '@journeyapps/react-native-quick-sqlite' ;
1+ import { open , QuickSQLite , QuickSQLiteConnection } from '@journeyapps/react-native-quick-sqlite' ;
22
33import {
44 AbstractPowerSyncDatabase ,
@@ -19,7 +19,22 @@ export class RNQSPowerSyncDatabaseOpenFactory extends AbstractPowerSyncDatabaseO
1919 * in the options (if provided)
2020 * https://github.com/margelo/react-native-quick-sqlite/blob/main/README.md#loading-existing-dbs
2121 */
22- return new RNQSDBAdapter ( open ( this . options . dbFilename , { location : this . options . dbLocation } ) ) ;
22+ const { dbFilename } = this . options ;
23+ const openOptions = { location : this . options . dbLocation } ;
24+ let DB : QuickSQLiteConnection ;
25+ try {
26+ // Hot reloads can sometimes clear global JS state, but not close DB on native side
27+ DB = open ( dbFilename , openOptions ) ;
28+ } catch ( ex ) {
29+ if ( ex . message . includes ( 'already open' ) ) {
30+ QuickSQLite . close ( dbFilename ) ;
31+ DB = open ( dbFilename , openOptions ) ;
32+ } else {
33+ throw ex ;
34+ }
35+ }
36+
37+ return new RNQSDBAdapter ( DB ) ;
2338 }
2439
2540 generateInstance ( options : PowerSyncDatabaseOptions ) : AbstractPowerSyncDatabase {
Original file line number Diff line number Diff line change 21342134 "@types/yargs" "^17.0.8"
21352135 chalk "^4.0.0"
21362136
2137- "@journeyapps/react-native-quick-sqlite@0.0.1", "@journeyapps/react-native-quick-sqlite@^0.0.1":
2138- version "0.0.1"
2139- resolved "https://registry.npmjs.org/@journeyapps/react-native-quick-sqlite/-/react-native-quick-sqlite-0.0.1.tgz#a5b731bfc658d6c8257ef3edebf243941a69a764"
2140- integrity sha512-vUXWngjpTFX6xCsy6Y8jd9zcI1eajIw/rWfdkpJOdnazR0SzAmrMc0ViRB6K84fWq9CmAV3DZw+GCVEHubqhSw==
2137+ "@journeyapps/react-native-quick-sqlite@0.0.0-dev-20231023173642":
2138+ version "0.0.0-dev-20231023173642"
2139+ resolved "https://registry.npmjs.org/@journeyapps/react-native-quick-sqlite/-/react-native-quick-sqlite-0.0.0-dev-20231023173642.tgz#00cfd6aec9674519ffbbc06245e7ce4ce42a0bcb"
2140+ integrity sha512-Na4XDi2u5AUZw+/mflV6LLIHJJvfvJxp5uYMDZtG+4WZ4dw0NDq+sZk+U26T/IU9xgdDWlcmwVKku9dDHLt7eg==
2141+ dependencies:
2142+ lodash "^4.17.21"
21412143
21422144"@jridgewell/gen-mapping@^0.3.0", "@jridgewell/gen-mapping@^0.3.2":
21432145 version "0.3.3"
You can’t perform that action at this time.
0 commit comments