Skip to content

Thin api wrapper around better-sqlite3 and bun:sqlite to allow cross- runtime/engine usage

License

Notifications You must be signed in to change notification settings

farjs/better-sqlite3-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CI npm version

@farjs/better-sqlite3-wrapper

Thin api wrapper around better-sqlite3 and bun:sqlite to allow cross- runtime/engine usage.

It exposes only a subset of better-sqlite3 api because not everything is available in bun:sqlite.

For example, since run returns undefined you can use the following queries to get changes and/or lastInsertRowid:

const changes = db.prepare("SELECT changes() AS changes;").get().changes;
const lastInsertRowId = db.prepare("SELECT last_insert_rowid() AS id;").get().id;

Also, since db.pragma is not available in bun:sqlite, you can run:

// non-transactional
db.prepare("PRAGMA foreign_keys = ON;").run();