deleteDatabaseFile
Delete the SQLite database file.
Usage
Access or destructure deleteDatabaseFile
from the SQLocal
client.
import { SQLocal } from 'sqlocal';
const { deleteDatabaseFile } = new SQLocal('database.sqlite3');
NOTE
If you are using the Kysely Query Builder or Drizzle ORM for type-safe queries, you will initialize the client with a child class of SQLocal
. See the corresponding setup page. Usage is the same otherwise.
The deleteDatabaseFile
method returns a Promise
to delete the SQLocal
instance's associated database file and temporary files. After this method completes, the SQLocal
client will reinitialize, and any subsequent mutation queries will create a new database file.
await deleteDatabaseFile();
The method also accepts an optional argument: a callback function to run after the database is deleted but before connections from other SQLocal client instances are allowed to access the new database, a good time to run migrations.
await deleteDatabaseFile(async () => {
// Run your migrations
});
Since calling deleteDatabaseFile
will reset all connections to the database file, the configured onInit
statements and onConnect
hook (see Options) will re-run on any SQLocal clients connected to the database when it is cleared. The client that initiated the deletion will have its onConnect
hook run first, before the method's callback, and the other clients' onConnect
hooks will run after the callback.