You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

fastify-sqlite

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-sqlite

Fastify plugin to connect to a SQLite database

1.1.0
latest
Source
npmnpm
Version published
Weekly downloads
124
25.25%
Maintainers
1
Weekly downloads
 
Created
Source

fastify-sqlite

JavaScript Style Guide ci

Fastify plugin to connect to a SQLite3 database. Under the hood, this plugin uses sqlite3.

Install

npm install fastify-sqlite

Compatibility

Plugin versionFastify version
^1.0.0^4.0.0

Usage

const fastifySqlite = require('fastify-sqlite')

async function main () {
  const app = fastify()
  app.register(fastifySqlite, {
    dbFile: 'foo.db'
  })
  await app.ready()

  app.sqlite.all('SELECT * FROM myTable', (err, rows) => {
    // do something
  })
}
main()

Checkout the sqlite3 documentation to see all the available methods.

Note that Promise APIs are not supported by the sqlite3 module by default. By using the promiseApi option, the sqlite wrapper will be used to enhance the Database instance. It has many convenient utilities such as migration support.

Options

You can pass the following options to the plugin:

await app.register(require('fastify-sqlite'), {
  promiseApi: true, // the DB instance supports the Promise API. Default false
  name: 'mydb', // optional decorator name. Default null
  verbose: true, // log sqlite3 queries as trace. Default false
  dbFile: ':memory:', // select the database file. Default ':memory:'
  mode: fastifySqlite.sqlite3.OPEN_READONLY 
    // how to connecto to the DB, Default: OPEN_READWRITE | OPEN_CREATE | OPEN_FULLMUTEX
})

// usage WITH name option
await app.sqlite.myDb.all('SELECT * FROM myTable')

License

Copyright Manuel Spigolon, Licensed under MIT.

Keywords

fastify

FAQs

Package last updated on 18 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts