Skip to content

0.13.0

Latest
Compare
Choose a tag to compare
@DallasHoff DallasHoff released this 02 Dec 03:40
· 3 commits to main since this release
  • Add support for initializing SQLocal with an in-memory database. Specifying :memory: as the databasePath for an SQLocal instance puts it in memory mode with support for all SQLocal methods including importing, exporting, and clearing the database.
new SQLocal(':memory:')
  • Add onInit hook that can be used to set SQL statements that should be run whenever the SQLocal instance makes a new database connection. These statements are always executed before any other statements can run on the connection. This makes it the best place to set PRAGMA settings or create temporary tables, views, triggers, or other connection-specific commands.
new SQLocal({
  databasePath: 'database.sqlite3',
  onInit: (sql) => [
    sql`PRAGMA foreign_keys = ON`,
    sql`CREATE TEMP VIEW hrEmployees AS
    SELECT name, salary
    FROM employees
    WHERE department = 'HR'`,
  ],
})
  • The onConnect hook is now passed a reason argument to specify why the hook was called: for initialization, because of database overwrite, or because of database deletion.