Add Close() and deleteDatabase() methods for expo-sqlite
complete
Chintan Patel
We are planning a preview-release for expo-sqlite adapter for AWS Amplify Datastore.
Currently, the database can only be opened but there is not close() method publicly available. The underlying code for close() already exists but it is not exposed publicly according to this post : https://github.com/expo/expo/issues/2278
If a database is loaded from Asset in order to overwrite a previous database, then it is required to close the database as otherwise it might cause an I/O error.
Additionally, there is no deleteDatabase() method available. Alternative is to drop All tables but it is not the same as deleting the database.
Adding support for these methods will bring expo-sqlite in parity with react-native-sqlite-storage package as well.
Brent Vatne
complete
Can Rau
Looks like it has been added https://docs.expo.dev/versions/v46.0.0/sdk/sqlite/#closeasync
Wodin
Merged in a post:
Close-method for SQLite
Jan
SQLite databases can only be opened, but not closed.
If a database is loaded from Asset in order to overwrite a previous database, then it is required to close the database as otherwise it will cause an I/O error.
The close-method is already included in the underlying code, but not exposed. Please expose the "close"-method for SQLite databases.
Alen Toma
Check out https://www.npmjs.com/package/expo-sqlite-wrapper, Added support to close and many other features
Alen Toma
Try my new library expo-sqlite-wrapper(https://www.npmjs.com/package/expo-sqlite-wrapper) added support to close and many other feature. check it out.
This library is a wrapper around expo sqlite so there will not be many changes to your code.
Jen Garcia
A new close method was added to the SQLite API in this pull request: https://github.com/expo/expo-sdk/pull/112
However, this new method still isn't 'public':
Expo.SQLite.openDatabase()
returns a WebSQLDatabase
object that has Expo's SQLiteDatabase
in the _db
property. As a result, to close the database you need to do something like this:```javascript
// Open the database
const db = Expo.SQLite.openDatabase("db_name");
// Close the database
db._db.close();
```
To fix this, a new public
close
method would need to be added to WebSQLDatabase
in Expo's fork of node-websql.Jan
Jen Garcia: Hey Jen, just to quickly confirm. I tested it in my implementation and it works as expected. Thank you!