Add Close() and deleteDatabase() methods for expo-sqlite
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.
marked this post as
Merged in a post:
Close-method for SQLite
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.
Check out https://www.npmjs.com/package/expo-sqlite-wrapper, Added support to close and many other features
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.
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':
WebSQLDatabaseobject that has Expo's
_dbproperty. As a result, to close the database you need to do something like this:
// Open the database
const db = Expo.SQLite.openDatabase("db_name");
// Close the database
To fix this, a new public
closemethod would need to be added to
WebSQLDatabasein Expo's fork of node-websql.
Jen Garcia: Hey Jen, just to quickly confirm. I tested it in my implementation and it works as expected. Thank you!