• Stars
    star
    6,075
  • Rank 6,333 (Top 0.2 %)
  • Language PLpgSQL
  • License
    BSD 3-Clause "New...
  • Created over 13 years ago
  • Updated 17 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

SQLite3 bindings for Node.js

⚙️ node-sqlite3

Asynchronous, non-blocking SQLite3 bindings for Node.js.

Latest release Build Status FOSSA Status N-API v3 Badge N-API v6 Badge

Features

Installing

You can use npm or yarn to install sqlite3:

  • (recommended) Latest published package:
npm install sqlite3
# or
yarn add sqlite3
  • GitHub's master branch: npm install https://github.com/tryghost/node-sqlite3/tarball/master

Prebuilt binaries

sqlite3 v5+ was rewritten to use Node-API so prebuilt binaries do not need to be built for specific Node versions. sqlite3 currently builds for both Node-API v3 and v6. Check the Node-API version matrix to ensure your Node version supports one of these. The prebuilt binaries should be supported on Node v10+.

The module uses node-pre-gyp to download the prebuilt binary for your platform, if it exists. These binaries are hosted on GitHub Releases for sqlite3 versions above 5.0.2, and they are hosted on S3 otherwise. The following targets are currently provided:

Format: napi-v{napi_build_version}-{platform}-{libc}-{arch}

  • napi-v3-darwin-unknown-arm64
  • napi-v3-darwin-unknown-x64
  • napi-v3-linux-glibc-arm64
  • napi-v3-linux-glibc-x64
  • napi-v3-linux-musl-arm64
  • napi-v3-linux-musl-x64
  • napi-v3-win32-unknown-ia32
  • napi-v3-win32-unknown-x64
  • napi-v6-darwin-unknown-arm64
  • napi-v6-darwin-unknown-x64
  • napi-v6-linux-glibc-arm64
  • napi-v6-linux-glibc-x64
  • napi-v6-linux-musl-arm64
  • napi-v6-linux-musl-x64
  • napi-v6-win32-unknown-ia32
  • napi-v6-win32-unknown-x64

Unfortunately, node-pre-gyp cannot differentiate between armv6 and armv7, and instead uses arm as the {arch}. Until that is fixed, you will still need to install sqlite3 from source.

Support for other platforms and architectures may be added in the future if CI supports building on them.

If your environment isn't supported, it'll use node-gyp to build SQLite but you will need to install a C++ compiler and linker.

Other ways to install

It is also possible to make your own build of sqlite3 from its source instead of its npm package (See below.).

The sqlite3 module also works with node-webkit if node-webkit contains a supported version of Node.js engine. (See below.)

SQLite's SQLCipher extension is also supported. (See below.)

API

See the API documentation in the wiki.

Usage

Note: the module must be installed before use.

const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database(':memory:');

db.serialize(() => {
    db.run("CREATE TABLE lorem (info TEXT)");

    const stmt = db.prepare("INSERT INTO lorem VALUES (?)");
    for (let i = 0; i < 10; i++) {
        stmt.run("Ipsum " + i);
    }
    stmt.finalize();

    db.each("SELECT rowid AS id, info FROM lorem", (err, row) => {
        console.log(row.id + ": " + row.info);
    });
});

db.close();

Source install

To skip searching for pre-compiled binaries, and force a build from source, use

npm install --build-from-source

The sqlite3 module depends only on libsqlite3. However, by default, an internal/bundled copy of sqlite will be built and statically linked, so an externally installed sqlite3 is not required.

If you wish to install against an external sqlite then you need to pass the --sqlite argument to npm wrapper:

npm install --build-from-source --sqlite=/usr/local

If building against an external sqlite3 make sure to have the development headers available. Mac OS X ships with these by default. If you don't have them installed, install the -dev package with your package manager, e.g. apt-get install libsqlite3-dev for Debian/Ubuntu. Make sure that you have at least libsqlite3 >= 3.6.

Note, if building against homebrew-installed sqlite on OS X you can do:

npm install --build-from-source --sqlite=/usr/local/opt/sqlite/

Custom file header (magic)

The default sqlite file header is "SQLite format 3". You can specify a different magic, though this will make standard tools and libraries unable to work with your files.

npm install --build-from-source --sqlite_magic="MyCustomMagic15"

Note that the magic must be exactly 15 characters long (16 bytes including null terminator).

Building for node-webkit

Because of ABI differences, sqlite3 must be built in a custom to be used with node-webkit.

To build sqlite3 for node-webkit:

  1. Install nw-gyp globally: npm install nw-gyp -g (unless already installed)

  2. Build the module with the custom flags of --runtime, --target_arch, and --target:

NODE_WEBKIT_VERSION="0.8.6" # see latest version at https://github.com/rogerwang/node-webkit#downloads
npm install sqlite3 --build-from-source --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION)

This command internally calls out to node-pre-gyp which itself calls out to nw-gyp when the --runtime=node-webkit option is passed.

You can also run this command from within a sqlite3 checkout:

npm install --build-from-source --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION)

Remember the following:

  • You must provide the right --target_arch flag. ia32 is needed to target 32bit node-webkit builds, while x64 will target 64bit node-webkit builds (if available for your platform).

  • After the sqlite3 package is built for node-webkit it cannot run in the vanilla Node.js (and vice versa).

    • For example, npm test of the node-webkit's package would fail.

Visit the “Using Node modules” article in the node-webkit's wiki for more details.

Building for SQLCipher

For instructions on building SQLCipher, see Building SQLCipher for Node.js. Alternatively, you can install it with your local package manager.

To run against SQLCipher, you need to compile sqlite3 from source by passing build options like:

npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=/usr/

node -e 'require("sqlite3")'

If your SQLCipher is installed in a custom location (if you compiled and installed it yourself), you'll need to set some environment variables:

On OS X with Homebrew

Set the location where brew installed it:

export LDFLAGS="-L`brew --prefix`/opt/sqlcipher/lib"
export CPPFLAGS="-I`brew --prefix`/opt/sqlcipher/include/sqlcipher"
npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix`

node -e 'require("sqlite3")'

On most Linuxes (including Raspberry Pi)

Set the location where make installed it:

export LDFLAGS="-L/usr/local/lib"
export CPPFLAGS="-I/usr/local/include -I/usr/local/include/sqlcipher"
export CXXFLAGS="$CPPFLAGS"
npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=/usr/local --verbose

node -e 'require("sqlite3")'

Custom builds and Electron

Running sqlite3 through electron-rebuild does not preserve the SQLCipher extension, so some additional flags are needed to make this build Electron compatible. Your npm install sqlite3 --build-from-source command needs these additional flags (be sure to replace the target version with the current Electron version you are working with):

--runtime=electron --target=18.2.1 --dist-url=https://electronjs.org/headers

In the case of MacOS with Homebrew, the command should look like the following:

npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix` --runtime=electron --target=18.2.1 --dist-url=https://electronjs.org/headers

Testing

npm test

Contributors

Acknowledgments

Thanks to Orlando Vazquez, Eric Fredricksen and Ryan Dahl for their SQLite bindings for node, and to mraleph on Freenode's #v8 for answering questions.

This module was originally created by Mapbox & is now maintained by Ghost.

Changelog

We use GitHub releases for notes on the latest versions. See CHANGELOG.md in git history for details on older versions.

License

node-sqlite3 is BSD licensed.

FOSSA Status

More Repositories

1

Ghost

Independent technology for modern publishing, memberships, subscriptions and newsletters.
JavaScript
44,370
star
2

Casper

The default theme for Ghost
CSS
2,512
star
3

gatsby-starter-ghost

A starter template to build lightning fast websites with Ghost & Gatsby
JavaScript
1,042
star
4

Admin

Ghost's admin client
JavaScript
627
star
5

express-hbs

Express handlebars template engine with inheritance, partials, i18n and async helpers.
JavaScript
461
star
6

Ghost-CLI

CLI Tool for installing & updating Ghost
JavaScript
433
star
7

Starter

A development starter theme for Ghost
CSS
359
star
8

eleventy-starter-ghost

A starter template to build websites with Ghost & Eleventy
Nunjucks
335
star
9

action-deploy-theme

:octocat: Deploy your Ghost theme with Github Actions
JavaScript
335
star
10

Dawn

A minimal newsletter theme for Ghost
CSS
263
star
11

London

A free, open source theme for Ghost
Handlebars
258
star
12

Ghost-Android

🤖 Ghost for Android
Java
237
star
13

Ghost-Vagrant

Vagrant setup for developing Ghost
Puppet
226
star
14

Massively

A free, open source theme for Ghost
SCSS
216
star
15

Editorial

A free, open source theme for Ghost
SCSS
185
star
16

gatsby-source-ghost

Source plugin for pulling data into Gatsby.js from the Ghost Public API.
JavaScript
176
star
17

Lyra

A paid-members theme for Ghost
CSS
176
star
18

gatsby-plugin-advanced-sitemap

Advanced XML Sitemaps for Gatsby.js
JavaScript
149
star
19

Roon

The official Roon theme for Ghost
CSS
142
star
20

Koenig

Components of Ghost's Editor
JavaScript
116
star
21

Alto

A clean, minimalist theme featuring a light and dark mode for Ghost
Handlebars
114
star
22

docs

Ghost's official documentation
JavaScript
112
star
23

Ghost-App

Includes for Ghost Apps
JavaScript
111
star
24

SDK

Tools for working with Ghost's APIs
JavaScript
100
star
25

knex-migrator

DB migration tool for knex.js
JavaScript
98
star
26

Ghost-Config

Cross-platform meta data and configurations
JavaScript
82
star
27

Ease

A minimal documentation theme for Ghost
Handlebars
80
star
28

generator-ghost

Generate Ghost blogs and themes using Yeoman.
JavaScript
78
star
29

gscan

Ghost theme scanner - checks for errors and feature support
JavaScript
74
star
30

Edge

A visually aesthetic portfolio theme for Ghost
Handlebars
73
star
31

Edition

The newsletter theme for Ghost
JavaScript
72
star
32

Pico

A paid members publishing theme for Ghost
CSS
69
star
33

Wave

A podcast theme for Ghost
Handlebars
66
star
34

Themes

A monorepo for Ghost themes
Handlebars
61
star
35

Portal

Drop-in script to add membership features in a Ghost theme
JavaScript
56
star
36

Dope

A unique tag-based theme for Ghost
CSS
53
star
37

Ruby

A multi-column theme with a unique card layout for Ghost
Handlebars
44
star
38

Headline

A local news theme for Ghost
Handlebars
41
star
39

Journal

A newsletter theme for Ghost
Handlebars
41
star
40

GQL

Filter query language for working with Ghost's API
JavaScript
39
star
41

Source

The default theme for Ghost
CSS
38
star
42

nodecmsguide

Your guide to Node.js content management systems
JavaScript
37
star
43

Slimer-hubot

A bot who lives in IRC
CoffeeScript
36
star
44

wp-ghost-exporter

A WordPress plugin to export content to Ghost
PHP
30
star
45

migrate

JavaScript
27
star
46

Solo

A personal theme for Ghost
Handlebars
26
star
47

Members

JavaScript
24
star
48

Ghost-Editor

Ghost's Mobiledoc Editor
23
star
49

Argon

A simple publishing theme for Ghost
CSS
22
star
50

api-demos

Demo scripts showing how to use Ghost's Admin and Content APIs to accomplish common tasks.
JavaScript
22
star
51

gctools

Command line utilities for working with Ghost content
JavaScript
20
star
52

framework

A collection of handy components for building Node.js applications
JavaScript
20
star
53

bookshelf-relations

A bookshelf plugin which handles relationships.
JavaScript
18
star
54

Tribeca

A free theme for Ghost
CSS
16
star
55

Ignition

Basic configuration and tooling shared across applications
JavaScript
16
star
56

algolia

JavaScript
16
star
57

Utils

JavaScript
14
star
58

Ghost-Storage-Base

Base storage adapter for Ghost
JavaScript
13
star
59

slimer

Tools for working on Ghost & the surrounding ecosystem
JavaScript
11
star
60

vscode

TypeScript
11
star
61

roon-i18n

Roon Internationalization
Ruby
10
star
62

NQL-old

NQL Toolkit: Query data using the NQL Language
JavaScript
9
star
63

action-update-posts

GitHub action for making scheduled changes to posts (e.g. toggling featured)
JavaScript
9
star
64

passport-ghost

Passport adapter for logging in with Ghost.org
JavaScript
8
star
65

Bulletin

A newsletter theme for Ghost
Handlebars
7
star
66

eslint-plugin-ghost

Shared eslint configurations
JavaScript
7
star
67

comments-ui

Drop-in script for comments in Ghost
JavaScript
6
star
68

Digest

A newsletter theme for Ghost
Handlebars
6
star
69

static

Static remote assets for Ghost sites
6
star
70

action-ghost-release

🚢 GitHub Action to release Ghost
JavaScript
6
star
71

Deploy

Custom shipitjs plugin for deploying
JavaScript
6
star
72

mongo-knex

JavaScript
6
star
73

sodo-search

Drop-in script for search in Ghost
JavaScript
6
star
74

digitalocean-1-click

DigitalOcean 1-Click App
Shell
5
star
75

NQL

JavaScript
4
star
76

Zap

An ultra-minimal Ghost theme
CSS
4
star
77

Zapier

Ghost <-> Zapier Integration
JavaScript
4
star
78

slimer-dashboard

GitHub Dashboard built in Apollo
JavaScript
3
star
79

Taste

Handlebars
3
star
80

cropper

JavaScript
2
star
81

nameservers

2
star
82

bunyan-rotating-file-stream

Rotate bunyan logs based on time period and file-size threshold
JavaScript
2
star
83

Actions

GitHub Actions to power Ghost development
JavaScript
2
star
84

label-actions

Tools for managing Ghost's OSS repositories
JavaScript
1
star
85

.github

1
star
86

salt-formula-sensu

Salt formula for configuring Sensu.
1
star
87

Analytics

JavaScript
1
star
88

Core

JavaScript
1
star
89

action-trigger-metric

JavaScript
1
star
90

architecture-diagrams

Set of diagrams and docs explainig architecture of Ghost
1
star