OP-Engineering / op-sqlite

Fastest SQLite library for react-native by @ospfranco
MIT License
598 stars 41 forks source link

[question] How open SQLite database in shared folder? #147

Closed akserg closed 2 months ago

akserg commented 2 months ago

I'm currently using react-native-sqlite-storage to open a database in shared mode, with several native modules running in the background on iOS. This setup leverages an App Group's Shared Container, allowing access to the same database instance across native modules and the main application, storing the files in the following directory: .//Shared/AppGroup/4045CAC7-5BC7-4A1C-8D40-EE98C46CFCC0/app.db

I noticed in the code at line 54-55 that you're reading the appGroupID from the OPSQLite_AppGroup key.

Screenshot 2024-09-18 at 16 52 30

However, after checking in the Xcode debugger, it seems this code is never reached. Instead, the database files are always created under a different directory: .//Data/Application/7BEE9A09-790D-4F6E-BA20-6DE1431CC045/Library/app.db

Could you please clarify how to configure OP-SQLITE to work with a shared folder?

ospfranco commented 2 months ago

Did you set the value in the info.plist?

akserg commented 2 months ago

Yes, of course

ospfranco commented 2 months ago

Did you set it with the key OPSQlite_AppGroup? Or did you take the comment literally?

OSP 000361 OSP 000360

ospfranco commented 2 months ago

This is also described in the docs

https://ospfranco.notion.site/Configuration-6b8b9564afcc4ac6b6b377fe34475090?pvs=4

Closing this

akserg commented 2 months ago

I figured out the issue. There's no need to pass the location parameter in shared mode:

let db;

if (Platform.OS === 'ios') {
  db = open({ name: 'myDB' });
} else {
  db = open({ name: 'myDB', location: ANDROID_DATABASE_PATH });
}

I'm using version 3.0.7, and it always attempts to create/open the database in the IOS_LIBRARY_PATH folder. I'm not sure if this has been addressed in the latest release.

Thank you for your time, @ospfranco.

ospfranco commented 2 months ago

location will always override any value set by the C++ code, this is expected. Glad you solved it!