Skip to content

Commit e3df365

Browse files
committed
Updated README
refs #1555 - moved some sections around to put the important and notable things first (I think) - added note about Node-API and prebuilt binaries - fixed links to point to TryGhost org - used explicit codeblocks in markdown
1 parent 426930f commit e3df365

File tree

1 file changed

+93
-58
lines changed

1 file changed

+93
-58
lines changed

README.md

Lines changed: 93 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,62 @@ Asynchronous, non-blocking [SQLite3](https://sqlite.org/) bindings for [Node.js]
99
[![N-API v3 Badge](https://img.shields.io/badge/N--API-v3-green.svg)](https://nodejs.org/dist/latest/docs/api/n-api.html#n_api_n_api)
1010
[![N-API v6 Badge](https://img.shields.io/badge/N--API-v6-green.svg)](https://nodejs.org/dist/latest/docs/api/n-api.html#n_api_n_api)
1111

12-
## Supported platforms
12+
# Features
13+
14+
- Straightforward query and parameter binding interface
15+
- Full Buffer/Blob support
16+
- Extensive [debugging support](https://github.com/tryghost/node-sqlite3/wiki/Debugging)
17+
- [Query serialization](https://github.com/tryghost/node-sqlite3/wiki/Control-Flow) API
18+
- [Extension support](https://github.com/tryghost/node-sqlite3/wiki/Extensions), including bundled support for the [json1 extension](https://www.sqlite.org/json1.html).
19+
- Big test suite
20+
- Written in modern C++ and tested for memory leaks
21+
- Bundles SQLite3 3.38.2, or you can build using a local SQLite
22+
23+
# Installing
24+
25+
You can use [`npm`](https://github.com/isaacs/npm) or [`yarn`](https://github.com/yarnpkg/yarn) to install `sqlite3`:
26+
27+
* (recommended) Latest package:
28+
```bash
29+
npm install sqlite3
30+
# or
31+
yarn add sqlite3
32+
```
33+
* GitHub's `master` branch: `npm install https://github.com/tryghost/node-sqlite3/tarball/master`
34+
35+
### Prebuilt binaries
36+
37+
`sqlite3` v5+ was rewritten to use [Node-API](https://nodejs.org/api/n-api.html) 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](https://nodejs.org/api/n-api.html#node-api-version-matrix) to ensure your Node version supports one of these. The prebuilt binaries should be supported on Node v10+.
1338

14-
The `sqlite3` module works with:
15-
* Node.js v11.x, v12.x, v13.x and v14.x.
16-
* Electron v6.0.x, v6.1.x, v7.0.x, v7.1.x, v8.0.x, v8.1.x and v8.2.x
39+
The module uses [node-pre-gyp](https://github.com/mapbox/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 supported:
1740

18-
Binaries for most Node versions and platforms are provided by default via [node-pre-gyp](https://github.com/mapbox/node-pre-gyp).
41+
Format: `napi-v{napi_build_version}-{platform}-{arch}`
42+
43+
* `napi-v3-darwin-x64`
44+
* `napi-v3-linux-x64`
45+
* `napi-v3-win32-ia32`
46+
* `napi-v3-win32-x64`
47+
* `napi-v6-darwin-x64`
48+
* `napi-v6-linux-x64`
49+
* `napi-v6-win32-ia32`
50+
* `napi-v6-win32-x64`
51+
52+
Support for other platforms and architectures may be added in the future if CI supports building on them.
53+
54+
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.
55+
56+
### Other ways to install
57+
58+
It is also possible to make your own build of `sqlite3` from its source instead of its npm package ([See below.](#building-from-the-source)).
1959

2060
The `sqlite3` module also works with [node-webkit](https://github.com/rogerwang/node-webkit) if node-webkit contains a supported version of Node.js engine. [(See below.)](#building-for-node-webkit)
2161

2262
SQLite's [SQLCipher extension](https://github.com/sqlcipher/sqlcipher) is also supported. [(See below.)](#building-for-sqlcipher)
2363

64+
# API
65+
66+
See the [API documentation](https://github.com/tryghost/node-sqlite3/wiki) in the wiki.
67+
2468
# Usage
2569

2670
**Note:** the module must be [installed](#installing) before use.
@@ -46,61 +90,42 @@ db.serialize(function() {
4690
db.close();
4791
```
4892

49-
# Features
50-
51-
- Straightforward query and parameter binding interface
52-
- Full Buffer/Blob support
53-
- Extensive [debugging support](https://github.com/mapbox/node-sqlite3/wiki/Debugging)
54-
- [Query serialization](https://github.com/mapbox/node-sqlite3/wiki/Control-Flow) API
55-
- [Extension support](https://github.com/mapbox/node-sqlite3/wiki/Extensions), including bundled support for the [json1 extension](https://www.sqlite.org/json1.html).
56-
- Big test suite
57-
- Written in modern C++ and tested for memory leaks
58-
- Bundles SQLite3 3.38.2 as a fallback if the installing system doesn't include SQLite
59-
60-
# API
61-
62-
See the [API documentation](https://github.com/mapbox/node-sqlite3/wiki) in the wiki.
63-
64-
# Installing
65-
66-
You can use [`npm`](https://github.com/isaacs/npm) to download and install:
67-
68-
* The latest `sqlite3` package: `npm install sqlite3`
69-
70-
* GitHub's `master` branch: `npm install https://github.com/mapbox/node-sqlite3/tarball/master`
71-
72-
The module uses [node-pre-gyp](https://github.com/mapbox/node-pre-gyp) to download a pre-compiled binary for your platform, if it exists. Otherwise, it uses `node-gyp` to build the extension.
73-
74-
It is also possible to make your own build of `sqlite3` from its source instead of its npm package ([see below](#building-from-the-source)).
75-
76-
It is possible to use the installed package in [node-webkit](https://github.com/rogerwang/node-webkit) instead of the vanilla Node.js. See [Building for node-webkit](#building-for-node-webkit) for details.
77-
7893
## Source install
7994

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

82-
npm install --build-from-source
97+
```bash
98+
npm install --build-from-source
99+
```
83100

84101
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.
85102

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

88-
npm install --build-from-source --sqlite=/usr/local
105+
```bash
106+
npm install --build-from-source --sqlite=/usr/local
107+
```
89108

90109
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.
91110

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

94-
npm install --build-from-source --sqlite=/usr/local/opt/sqlite/
113+
```bash
114+
npm install --build-from-source --sqlite=/usr/local/opt/sqlite/
115+
```
95116

96117
By default the node-gyp install will use `python` as part of the installation. A
97118
different python executable can be specified on the command line.
98119

99-
npm install --build-from-source --python=/usr/bin/python2
120+
```bash
121+
npm install --build-from-source --python=/usr/bin/python2
122+
```
100123

101124
This uses the npm_config_python config, so values in .npmrc will be honoured:
102125

103-
python=/usr/bin/python2
126+
```bash
127+
python=/usr/bin/python2
128+
```
104129

105130
## Custom file header (magic)
106131

@@ -112,7 +137,7 @@ You can specify a different magic, though this will make standard tools and libr
112137

113138

114139
Note that the magic *must* be exactly 15 characters long (16 bytes including null terminator).
115-
140+
116141
## Building for node-webkit
117142

118143
Because of ABI differences, `sqlite3` must be built in a custom to be used with [node-webkit](https://github.com/rogerwang/node-webkit).
@@ -123,7 +148,7 @@ To build node-sqlite3 for node-webkit:
123148

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

126-
```sh
151+
```bash
127152
NODE_WEBKIT_VERSION="0.8.6" # see latest version at https://github.com/rogerwang/node-webkit#downloads
128153
npm install sqlite3 --build-from-source --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION)
129154
```
@@ -132,7 +157,7 @@ This command internally calls out to [`node-pre-gyp`](https://github.com/mapbox/
132157

133158
You can also run this command from within a `node-sqlite3` checkout:
134159

135-
```sh
160+
```bash
136161
npm install --build-from-source --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION)
137162
```
138163

@@ -145,16 +170,18 @@ Remember the following:
145170

146171
Visit the “[Using Node modules](https://github.com/rogerwang/node-webkit/wiki/Using-Node-modules)” article in the node-webkit's wiki for more details.
147172

148-
## Building for sqlcipher
173+
## Building for SQLCipher
149174

150175
For instructions for building sqlcipher see
151176
[Building SQLCipher for node.js](https://coolaj86.com/articles/building-sqlcipher-for-node-js-on-raspberry-pi-2/)
152177

153178
To run node-sqlite3 against sqlcipher you need to compile from source by passing build options like:
154179

155-
npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=/usr/
180+
```bash
181+
npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=/usr/
156182

157-
node -e 'require("sqlite3")'
183+
node -e 'require("sqlite3")'
184+
```
158185

159186
If your sqlcipher is installed in a custom location (if you compiled and installed it yourself),
160187
you'll also need to to set some environment variables:
@@ -163,22 +190,26 @@ you'll also need to to set some environment variables:
163190

164191
Set the location where `brew` installed it:
165192

166-
export LDFLAGS="-L`brew --prefix`/opt/sqlcipher/lib"
167-
export CPPFLAGS="-I`brew --prefix`/opt/sqlcipher/include"
168-
npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix`
193+
```bash
194+
export LDFLAGS="-L`brew --prefix`/opt/sqlcipher/lib"
195+
export CPPFLAGS="-I`brew --prefix`/opt/sqlcipher/include"
196+
npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix`
169197

170-
node -e 'require("sqlite3")'
198+
node -e 'require("sqlite3")'
199+
```
171200

172201
### On most Linuxes (including Raspberry Pi)
173202

174203
Set the location where `make` installed it:
175204

176-
export LDFLAGS="-L/usr/local/lib"
177-
export CPPFLAGS="-I/usr/local/include -I/usr/local/include/sqlcipher"
178-
export CXXFLAGS="$CPPFLAGS"
179-
npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=/usr/local --verbose
205+
```bash
206+
export LDFLAGS="-L/usr/local/lib"
207+
export CPPFLAGS="-I/usr/local/include -I/usr/local/include/sqlcipher"
208+
export CXXFLAGS="$CPPFLAGS"
209+
npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=/usr/local --verbose
180210

181-
node -e 'require("sqlite3")'
211+
node -e 'require("sqlite3")'
212+
```
182213

183214
### Custom builds and Electron
184215

@@ -188,16 +219,20 @@ Running sqlite3 through [electron-rebuild](https://github.com/electron/electron-
188219

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

191-
npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix` --runtime=electron --target=1.7.6 --dist-url=https://electronjs.org/headers
222+
```bash
223+
npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix` --runtime=electron --target=1.7.6 --dist-url=https://electronjs.org/headers
224+
```
192225

193226
# Testing
194227

195228
[mocha](https://github.com/visionmedia/mocha) is required to run unit tests.
196229

197230
In sqlite3's directory (where its `package.json` resides) run the following:
198231

199-
npm install mocha
200-
npm test
232+
```bash
233+
npm install mocha
234+
npm test
235+
```
201236

202237
# Contributors
203238

@@ -225,6 +260,6 @@ Development of this module is sponsored by [MapBox](https://mapbox.com/).
225260

226261
# License
227262

228-
`node-sqlite3` is [BSD licensed](https://github.com/mapbox/node-sqlite3/raw/master/LICENSE).
263+
`node-sqlite3` is [BSD licensed](https://github.com/tryghost/node-sqlite3/raw/master/LICENSE).
229264

230265
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmapbox%2Fnode-sqlite3.svg?type=large)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmapbox%2Fnode-sqlite3?ref=badge_large)

0 commit comments

Comments
 (0)