Commit 6a08c074 authored by Francesco Poldi's avatar Francesco Poldi

Edited titles, loaded sqlite3 compiled

parent 9b05311f
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Title</title> <title>Twint OSINT Explorer</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/uikit.min.css" /> <link rel="stylesheet" href="css/uikit.min.css" />
......
This diff is collapsed.
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
"dependencies": { "dependencies": {
"electron": "^1.8.4", "electron": "^1.8.4",
"jquery": "^3.3.1", "jquery": "^3.3.1",
"sqlite3": "^4.0.0",
"uikit": "^3.0.0-beta.40", "uikit": "^3.0.0-beta.40",
"vis": "^4.21.0" "vis": "^4.21.0"
}, },
......
# Changelog
## 4.0.0
- Drop support for Node v0.10 and v.12
- Upgrade to node-pre-gyp@0.9.0
- Upgrade to nan@2.9.2
## 3.1.13
- Attempt to fix regression of #866
## 3.1.12
- Fixed to ensure the binaries do not rely on `GLIBC_2.14` and only `GLIBC_2.2.5`. This regressed in v3.1.11.
## 3.1.11
- Fixed building from source on alpine linux
## 3.1.10
- Removed `npm ls` from `prepublish` hook per mapbox/node-pre-gyp#291
- Upgraded node-pre-gyp to v0.6.37
- Removed accidentally committed large file
## 3.1.9
- Added support for node v8 and upgraded `nan`, `node-pre-gyp` deps.
## 3.1.8
- Added support for node v7 (pre-compiled binaries available)
## 3.1.7
- Upgrade sqlite to 3.15, enable FTS4, FTS5 (@wmertens)
- Upgrade to node-pre-gyp@0.6.31 and nan@2.4.0
## 3.1.6
- Starts bundling node-pre-gyp again to avoid #720
## 3.1.5
- [Added support for sqlite3_interrupt](https://github.com/mapbox/node-sqlite3/pull/518): this makes
it possible to interrupt a long-running query.
- [Fixes uv_ref race](https://github.com/mapbox/node-sqlite3/pull/705).
## 3.1.4
- Added support for node v6
## 3.1.3
- Upgrade to node-pre-gyp@0.6.26 with better support for Electron
## 3.1.2
- Only providing binaries for node v0.10x, v0.12.x, v4, and v5
- Upgrade to nan@2.2.x
- Upgrade to node-pre-gyp@0.6.24
## 3.1.1
- Support for node 5.x
- Upgraded SQLite to 3.9.1: https://www.sqlite.org/releaselog/3_9_1.html
- Enabled json1 extension by default
## 3.1.0
- Support for node 3.x and 4.x
- Stopped producing binaries for node-webkit and 32 bit linux
## 3.0.11
- Support for io.js 3.x (upgrade to Nan 2.x) @kkoopa
## 3.0.10
- Upgraded SQLite to 3.8.11.1: https://www.sqlite.org/releaselog/3_8_11_1.html
- Fixed binary compatibility regression with old centos/rhel glibc GLIBC_2.14 (re-introduced alpine linux (musl) build regression)
- Now providing binaries against Visual Studio 2015 (pass --toolset=v140) and use binaries from https://github.com/mapbox/node-cpp11
## 3.0.9
- Fixed build regression against alpine linux (musl)
- Upgraded node-pre-gyp@0.6.8
## 3.0.8
- Fixed build regression against FreeBSD
- Upgraded node-pre-gyp@0.6.7
## 3.0.7
- Fixed build regression against ARM and i386 linux
- Upgraded node-pre-gyp@0.6.6
- Added support for io.js 2.0.0
## 3.0.6
- Upgraded node-pre-gyp@0.6.5
- Upgraded nan@1.8.4
- Fixed binaries to work on older linux systems (circa GLIBC_2.2.5 like centos 6) @bnoordhuis
- Updated internal libsqlite3 from 3.8.7.1 -> 3.8.9 (http://www.sqlite.org/news.html)
## 3.0.5
- IO.js and Node v0.12.x support.
- Node-webkit v0.11.x support regressed in this release, sorry (https://github.com/mapbox/node-sqlite3/issues/404).
## 3.0.4
- Upgraded node-pre-gyp@0.6.1
## 3.0.3
- Upgraded to node-pre-gyp@0.6.0 which should fix crashes against node v0.11.14
- Now providing binaries against Visual Studio 2014 (pass --toolset=v140) and use binaries from https://github.com/mapbox/node-cpp11
## 3.0.2
- Republish for possibly busted npm package.
## 3.0.1
- Use ~ in node-pre-gyp semver for more flexible dep management.
## 3.0.0
Released September 20nd, 2014
- Backwards-incompatible change: node versions 0.8.x are no longer supported.
- Updated to node-pre-gyp@0.5.27
- Updated NAN to 1.3.0
- Updated internal libsqlite3 to v3.8.6
## 2.2.7
Released August 6th, 2014
- Removed usage of `npm ls` with `prepublish` target (which breaks node v0.8.x)
## 2.2.6
Released August 6th, 2014
- Fix bundled version of node-pre-gyp
## 2.2.5
Released August 5th, 2014
- Fix leak in complete() callback of Database.each() (#307)
- Started using `engineStrict` and improved `engines` declaration to make clear only >= 0.11.13 is supported for the 0.11.x series.
## 2.2.4
Released July 14th, 2014
- Now supporting node v0.11.x (specifically >=0.11.13)
- Fix db opening error with absolute path on windows
- Updated to node-pre-gyp@0.5.18
- updated internal libsqlite3 from 3.8.4.3 -> 3.8.5 (http://www.sqlite.org/news.html)
## 2.2.3
- Fixed regression in v2.2.2 for installing from binaries on windows.
## 2.2.2
- Fixed packaging problem whereby a `config.gypi` was unintentially packaged and could cause breakages for OS X builds.
## 2.2.1
- Now shipping with 64bit FreeBSD binaries against both node v0.10.x and node v0.8.x.
- Fixed solaris/smartos source compile by passing `-std=c99` when building internally bundled libsqlite3 (#201)
- Reduced size of npm package by ignoring tests and examples.
- Various fixes and improvements for building against node-webkit
- Upgraded to node-pre-gyp@0.5.x from node-pre-gyp@0.2.5
- Improved ability to build from source against `sqlcipher` by passing custom library name: `--sqlite_libname=sqlcipher`
- No changes to C++ Core / Existing binaries are exactly the same
## 2.2.0
Released Jan 13th, 2014
- updated internal libsqlite3 from 3.7.17 -> 3.8.2 (http://www.sqlite.org/news.html) which includes the next-generation query planner http://www.sqlite.org/queryplanner-ng.html
- improved binary deploy system using https://github.com/springmeyer/node-pre-gyp
- binary install now supports http proxies
- source compile now supports freebsd
- fixed support for node-webkit
## 2.1.19
Released October 31st, 2013
- Started respecting `process.env.npm_config_tmp` as location to download binaries
- Removed uneeded `progress` dependency
## 2.1.18
Released October 22nd, 2013
- `node-sqlite3` moved to mapbox github group
- Fixed reporting of node-gyp errors
- Fixed support for node v0.6.x
## 2.1.17
- Minor fixes to binary deployment
## 2.1.16
- Support for binary deployment
## 2.1.15
Released August 7th, 2013
- Minor readme additions and code optimizations
# Contributing
General guidelines for contributing to node-sqlite3
## Install Help
If you've landed here due to a failed install of `node-sqlite3` then feel free to create a [new issue](https://github.com/mapbox/node-sqlite3/issues/new) to ask for help. The most likely problem is that we do not yet provide pre-built binaries for your particular platform and so the `node-sqlite3` install attempted a source compile but failed because you are missing the [dependencies for node-gyp](https://github.com/TooTallNate/node-gyp#installation). But please provide as much detail on your problem as possible and we'll try to help. Please include:
- terminal logs of failed install (preferably from running `npm install sqlite3 --loglevel=info`)
- `node-sqlite3` version you tried to install
- node version you are running
- operating system and architecture you are running, e.g. `Windows 7 64 bit`.
## Developing / Pre-release
Create a milestone for the next release on github. If all anticipated changes are back compatible then a `patch` release is in order. If minor API changes are needed then a `minor` release is in order. And a `major` bump is warranted if major API changes are needed.
Assign tickets and pull requests you are working to the milestone you created.
## Releasing
To release a new version:
**1)** Ensure tests are passing
Before considering a release all the tests need to be passing on appveyor and travis.
**2)** Bump commit
Bump the version in `package.json` like https://github.com/mapbox/node-sqlite3/commit/77d51d5785b047ff40f6a8225051488a0d96f7fd
What if you already committed the `package.json` bump and you have no changes to commit but want to publish binaries? In this case you can do:
```sh
git commit --allow-empty -m "[publish binary]"
```
**3)** Ensure binaries built
Check the travis and appveyor pages to ensure they are all green as an indication that the `[publish binary]` command worked.
If you need to republish binaries you can do this with the command below, however this should not be a common thing for you to do!
```sh
git commit --allow-empty -m "[republish binary]"
```
Note: NEVER republish binaries for an existing released version.
**7)** Officially release
An official release requires:
- Updating the CHANGELOG.md
- Create and push github tag like `git tag v3.1.1 -m "v3.1.1" && git push --tags`
- Ensure you have a clean checkout (no extra files in your check that are not known by git). You need to be careful, for instance, to avoid a large accidental file being packaged by npm. You can get a view of what npm will publish by running `make testpack`
- Fully rebuild and ensure install from binary works: `make clean && npm install --fallback-to-build=false`
- Then publish the module to npm repositories by running `npm publish`
Copyright (c) MapBox
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
- Neither the name "MapBox" nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
Asynchronous, non-blocking [SQLite3](http://sqlite.org/) bindings for [Node.js](http://nodejs.org/).
[![NPM](https://nodei.co/npm/sqlite3.png?downloads=true&downloadRank=true)](https://nodei.co/npm/sqlite3/)
[![Build Status](https://travis-ci.org/mapbox/node-sqlite3.svg?branch=master)](https://travis-ci.org/mapbox/node-sqlite3)
[![Build status](https://ci.appveyor.com/api/projects/status/gvm7ul0hpmdawqom)](https://ci.appveyor.com/project/Mapbox/node-sqlite3)
[![Coverage Status](https://coveralls.io/repos/mapbox/node-sqlite3/badge.svg?branch=master&service=github)](https://coveralls.io/github/mapbox/node-sqlite3?branch=master)
[![Dependencies](https://david-dm.org/mapbox/node-sqlite3.svg)](https://david-dm.org/mapbox/node-sqlite3)
## Supported platforms
The `sqlite3` module works with Node.js v4.x, v5.x, v6.x and v7.x.
Binaries for most Node versions and platforms are provided by default via [node-pre-gyp](https://github.com/mapbox/node-pre-gyp).
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)
SQLite's [SQLCipher extension](https://github.com/sqlcipher/sqlcipher) is also supported. [(See below.)](#building-for-sqlcipher)
# Usage
**Note:** the module must be [installed](#installing) before use.
``` js
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database(':memory:');
db.serialize(function() {
db.run("CREATE TABLE lorem (info TEXT)");
var stmt = db.prepare("INSERT INTO lorem VALUES (?)");
for (var i = 0; i < 10; i++) {
stmt.run("Ipsum " + i);
}
stmt.finalize();
db.each("SELECT rowid AS id, info FROM lorem", function(err, row) {
console.log(row.id + ": " + row.info);
});
});
db.close();
```
# Features
- Straightforward query and parameter binding interface
- Full Buffer/Blob support
- Extensive [debugging support](https://github.com/mapbox/node-sqlite3/wiki/Debugging)
- [Query serialization](https://github.com/mapbox/node-sqlite3/wiki/Control-Flow) API
- [Extension support](https://github.com/mapbox/node-sqlite3/wiki/Extensions)
- Big test suite
- Written in modern C++ and tested for memory leaks
- Bundles Sqlite3 3.15.0 as a fallback if the installing system doesn't include SQLite
# API
See the [API documentation](https://github.com/mapbox/node-sqlite3/wiki) in the wiki.
# Installing
You can use [`npm`](https://github.com/isaacs/npm) to download and install:
* The latest `sqlite3` package: `npm install sqlite3`
* GitHub's `master` branch: `npm install https://github.com/mapbox/node-sqlite3/tarball/master`
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.
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)).
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.
## 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/
## Building for node-webkit
Because of ABI differences, `sqlite3` must be built in a custom to be used with [node-webkit](https://github.com/rogerwang/node-webkit).
To build node-sqlite3 for node-webkit:
1. Install [`nw-gyp`](https://github.com/rogerwang/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`:
```sh
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`](https://github.com/mapbox/node-pre-gyp) which itself calls out to [`nw-gyp`](https://github.com/rogerwang/nw-gyp) when the `--runtime=node-webkit` option is passed.
You can also run this command from within a `node-sqlite3` checkout:
```sh
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](https://github.com/rogerwang/node-webkit/wiki/Using-Node-modules)” article in the node-webkit's wiki for more details.
## Building for sqlcipher
For instructions for building sqlcipher see
[Building SQLCipher for node.js](https://coolaj86.com/articles/building-sqlcipher-for-node-js-on-raspberry-pi-2/)
To run node-sqlite3 against sqlcipher you need to compile 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 also need to 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"
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](https://github.com/electron/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=1.7.6 --dist-url=https://atom.io/download/electron
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=1.7.6 --dist-url=https://atom.io/download/electron
# Testing
[mocha](https://github.com/visionmedia/mocha) is required to run unit tests.
In sqlite3's directory (where its `package.json` resides) run the following:
npm install mocha
npm test
# Contributors
* [Konstantin Käfer](https://github.com/kkaefer)
* [Dane Springmeyer](https://github.com/springmeyer)
* [Will White](https://github.com/willwhite)
* [Orlando Vazquez](https://github.com/orlandov)
* [Artem Kustikov](https://github.com/artiz)
* [Eric Fredricksen](https://github.com/grumdrig)
* [John Wright](https://github.com/mrjjwright)
* [Ryan Dahl](https://github.com/ry)
* [Tom MacWright](https://github.com/tmcw)
* [Carter Thaxton](https://github.com/carter-thaxton)
* [Audrius Kažukauskas](https://github.com/audriusk)
* [Johannes Schauer](https://github.com/pyneo)
* [Mithgol](https://github.com/Mithgol)
# Acknowledgments
Thanks to [Orlando Vazquez](https://github.com/orlandov),
[Eric Fredricksen](https://github.com/grumdrig) and
[Ryan Dahl](https://github.com/ry) for their SQLite bindings for node, and to mraleph on Freenode's #v8 for answering questions.
Development of this module is sponsored by [MapBox](http://mapbox.org/).
# License
`node-sqlite3` is [BSD licensed](https://github.com/mapbox/node-sqlite3/raw/master/LICENSE).
environment:
node_pre_gyp_accessKeyId:
secure: 7DrSVc5eIGtmMcki5H+iRft+Tk3MJTwDBQEUuJHWaQ4=
node_pre_gyp_secretAccessKey:
secure: 1amwJJw9fu0j6dXnc5KsAQbSYf7Cjw/dapT6OZWABa6nc52grkKeLQ+DGaOfQz8i
matrix:
- nodejs_version: 4
platform: x64
- nodejs_version: 4
platform: x86
- nodejs_version: 5
platform: x64
- nodejs_version: 5
platform: x86
- nodejs_version: 6
platform: x64
- nodejs_version: 6
platform: x86
- nodejs_version: 7
platform: x64
- nodejs_version: 7
platform: x86
- nodejs_version: 8
platform: x64
- nodejs_version: 8
platform: x86
- nodejs_version: 9
platform: x64
- nodejs_version: 9
platform: x86
os: Visual Studio 2015
install:
- scripts\build-appveyor.bat
build: OFF
test: OFF
deploy: OFF
{
"includes": [ "deps/common-sqlite.gypi" ],
"variables": {
"sqlite%":"internal",
"sqlite_libname%":"sqlite3"
},
"targets": [
{
"target_name": "<(module_name)",
"include_dirs": ["<!(node -e \"require('nan')\")"],
"conditions": [
["sqlite != 'internal'", {
"include_dirs": [ "<(sqlite)/include" ],
"libraries": [
"-l<(sqlite_libname)"
],
"conditions": [ [ "OS=='linux'", {"libraries+":["-Wl,-rpath=<@(sqlite)/lib"]} ] ],
"conditions": [ [ "OS!='win'", {"libraries+":["-L<@(sqlite)/lib"]} ] ],
'msvs_settings': {
'VCLinkerTool': {
'AdditionalLibraryDirectories': [
'<(sqlite)/lib'
],
},
}
},
{
"dependencies": [
"deps/sqlite3.gyp:sqlite3"
]
}
]
],
"sources": [
"src/database.cc",
"src/node_sqlite3.cc",
"src/statement.cc"
]
},
{
"target_name": "action_after_build",
"type": "none",
"dependencies": [ "<(module_name)" ],
"copies": [
{
"files": [ "<(PRODUCT_DIR)/<(module_name).node" ],
"destination": "<(module_path)"
}
]
}
]
}
{
'variables': {
'sqlite_version%':'3150000',
"toolset%":'',
},
'target_defaults': {
'default_configuration': 'Release',
'msbuild_toolset':'<(toolset)',
'configurations': {
'Debug': {
'defines!': [
'NDEBUG'
],
'cflags_cc!': [
'-O3',
'-Os',
'-DNDEBUG'
],
'xcode_settings': {
'OTHER_CPLUSPLUSFLAGS!': [
'-O3',
'-Os',
'-DDEBUG'
],
'GCC_OPTIMIZATION_LEVEL': '0',
'GCC_GENERATE_DEBUGGING_SYMBOLS': 'YES'
},
'msvs_settings': {
'VCCLCompilerTool': {
'ExceptionHandling': 1, # /EHsc
}
}
},
'Release': {
'defines': [
'NDEBUG'
],
'xcode_settings': {
'OTHER_CPLUSPLUSFLAGS!': [
'-Os',
'-O2'
],
'GCC_OPTIMIZATION_LEVEL': '3',
'GCC_GENERATE_DEBUGGING_SYMBOLS': 'NO',
'DEAD_CODE_STRIPPING': 'YES',
'GCC_INLINES_ARE_PRIVATE_EXTERN': 'YES'
},
'msvs_settings': {
'VCCLCompilerTool': {
'ExceptionHandling': 1, # /EHsc
}
}
}
}
}
}
import sys
import tarfile
import os
tarball = os.path.abspath(sys.argv[1])
dirname = os.path.abspath(sys.argv[2])
tfile = tarfile.open(tarball,'r:gz');
tfile.extractall(dirname)
sys.exit(0)
{
'includes': [ 'common-sqlite.gypi' ],
'target_defaults': {
'default_configuration': 'Release',
'cflags':[
'-std=c99'
],
'configurations': {
'Debug': {
'defines': [ 'DEBUG', '_DEBUG' ],
'msvs_settings': {
'VCCLCompilerTool': {
'RuntimeLibrary': 1, # static debug
},
},
},
'Release': {
'defines': [ 'NDEBUG' ],
'msvs_settings': {
'VCCLCompilerTool': {
'RuntimeLibrary': 0, # static release
},
},
}
},
'msvs_settings': {
'VCCLCompilerTool': {
},
'VCLibrarianTool': {
},
'VCLinkerTool': {
'GenerateDebugInformation': 'true',
},
},
'conditions': [
['OS == "win"', {
'defines': [
'WIN32'
],
}]
],
},
'targets': [
{
'target_name': 'action_before_build',
'type': 'none',
'hard_dependency': 1,
'actions': [
{
'action_name': 'unpack_sqlite_dep',
'inputs': [
'./sqlite-autoconf-<@(sqlite_version).tar.gz'
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/sqlite-autoconf-<@(sqlite_version)/sqlite3.c'
],
'action': ['python','./extract.py','./sqlite-autoconf-<@(sqlite_version).tar.gz','<(SHARED_INTERMEDIATE_DIR)']
}
],
'direct_dependent_settings': {
'include_dirs': [
'<(SHARED_INTERMEDIATE_DIR)/sqlite-autoconf-<@(sqlite_version)/',
]
},
},
{
'target_name': 'sqlite3',
'type': 'static_library',
'include_dirs': [ '<(SHARED_INTERMEDIATE_DIR)/sqlite-autoconf-<@(sqlite_version)/' ],
'dependencies': [
'action_before_build'
],
'sources': [
'<(SHARED_INTERMEDIATE_DIR)/sqlite-autoconf-<@(sqlite_version)/sqlite3.c'
],
'direct_dependent_settings': {
'include_dirs': [ '<(SHARED_INTERMEDIATE_DIR)/sqlite-autoconf-<@(sqlite_version)/' ],
'defines': [
'SQLITE_THREADSAFE=1',
'SQLITE_ENABLE_FTS3',
'SQLITE_ENABLE_FTS4',
'SQLITE_ENABLE_FTS5',
'SQLITE_ENABLE_JSON1',
'SQLITE_ENABLE_RTREE'
],
},
'cflags_cc': [
'-Wno-unused-value'
],
'defines': [
'_REENTRANT=1',
'SQLITE_THREADSAFE=1',
'SQLITE_ENABLE_FTS3',
'SQLITE_ENABLE_FTS4',
'SQLITE_ENABLE_FTS5',
'SQLITE_ENABLE_JSON1',
'SQLITE_ENABLE_RTREE'
],
'export_dependent_settings': [
'action_before_build',
]
}
]
}
npm install \
--build-from-source \
--runtime=electron --target=1.7.6 \
--dist-url=https://atom.io/download/electron
{
"_from": "sqlite3",
"_id": "sqlite3@4.0.0",
"_inBundle": false,
"_integrity": "sha512-6OlcAQNGaRSBLK1CuaRbKwlMFBb9DEhzmZyQP+fltNRF6XcIMpVIfXCBEcXPe1d4v9LnhkQUYkknDbA5JReqJg==",
"_location": "/sqlite3",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "sqlite3",
"name": "sqlite3",
"escapedName": "sqlite3",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/sqlite3/-/sqlite3-4.0.0.tgz",
"_shasum": "cc0e093ab51873f50d9dfc4126fcbef15d486570",
"_spec": "sqlite3",
"_where": "/home/user/ELECTRON/kit",
"author": {
"name": "MapBox",
"url": "https://mapbox.com/"
},
"binary": {
"module_name": "node_sqlite3",
"module_path": "./lib/binding/{node_abi}-{platform}-{arch}",
"host": "https://mapbox-node-binary.s3.amazonaws.com",
"remote_path": "./{name}/v{version}/{toolset}/",
"package_name": "{node_abi}-{platform}-{arch}.tar.gz"
},
"bugs": {
"url": "https://github.com/mapbox/node-sqlite3/issues"
},
"bundleDependencies": [
"node-pre-gyp"
],
"contributors": [
{
"name": "Konstantin Käfer",
"email": "mail@kkaefer.com"
},
{
"name": "Dane Springmeyer",
"email": "dane@mapbox.com"
},
{
"name": "Will White",
"email": "will@mapbox.com"
},
{
"name": "Orlando Vazquez",
"email": "ovazquez@gmail.com"
},
{
"name": "Artem Kustikov",
"email": "kustikoff@gmail.com"
},
{
"name": "Eric Fredricksen",
"email": "efredricksen@gmail.com"
},
{
"name": "John Wright",
"email": "mrjjwright@gmail.com"
},
{
"name": "Ryan Dahl",
"email": "ry@tinyclouds.org"
},
{
"name": "Tom MacWright",
"email": "tom@mapbox.com"
},
{
"name": "Carter Thaxton",
"email": "carter.thaxton@gmail.com"
},
{
"name": "Audrius Kažukauskas",
"email": "audrius@neutrino.lt"
},
{
"name": "Johannes Schauer",
"email": "josch@pyneo.org"
},
{
"name": "Nathan Rajlich",
"email": "nathan@tootallnate.net"
},
{
"name": "AJ ONeal",
"email": "coolaj86@gmail.com"
},
{
"name": "Mithgol"
},
{
"name": "Ben Noordhuis",
"email": "ben@strongloop.com"
}
],
"dependencies": {
"nan": "~2.9.2",
"node-pre-gyp": "~0.9.0"
},
"deprecated": false,
"description": "Asynchronous, non-blocking SQLite3 bindings",
"devDependencies": {
"aws-sdk": "2.x",
"eslint": "3.5.0",
"mocha": "3.x"
},
"homepage": "http://github.com/mapbox/node-sqlite3",
"keywords": [
"sql",
"sqlite",
"sqlite3",
"database"
],
"license": "BSD-3-Clause",
"main": "./lib/sqlite3",
"name": "sqlite3",
"repository": {
"type": "git",
"url": "git://github.com/mapbox/node-sqlite3.git"
},
"scripts": {
"install": "node-pre-gyp install --fallback-to-build",
"prepublishOnly": "npm ls",
"pretest": "node test/support/createdb.js",
"test": "mocha -R spec --timeout 480000"
},
"version": "4.0.0"
}
module.exports = require('./lib/sqlite3');
#ifndef NODE_SQLITE3_SRC_ASYNC_H
#define NODE_SQLITE3_SRC_ASYNC_H
#include "threading.h"
#include <node_version.h>
#if defined(NODE_SQLITE3_BOOST_THREADING)
#include <boost/thread/mutex.hpp>
#endif
// Generic uv_async handler.
template <class Item, class Parent> class Async {
typedef void (*Callback)(Parent* parent, Item* item);
protected:
uv_async_t watcher;
NODE_SQLITE3_MUTEX_t
std::vector<Item*> data;
Callback callback;
public:
Parent* parent;
public:
Async(Parent* parent_, Callback cb_)
: callback(cb_), parent(parent_) {
watcher.data = this;
NODE_SQLITE3_MUTEX_INIT
uv_async_init(uv_default_loop(), &watcher, reinterpret_cast<uv_async_cb>(listener));
}
static void listener(uv_async_t* handle, int status) {
Async* async = static_cast<Async*>(handle->data);
std::vector<Item*> rows;
NODE_SQLITE3_MUTEX_LOCK(&async->mutex)
rows.swap(async->data);
NODE_SQLITE3_MUTEX_UNLOCK(&async->mutex)
for (unsigned int i = 0, size = rows.size(); i < size; i++) {
async->callback(async->parent, rows[i]);
}
}
static void close(uv_handle_t* handle) {
assert(handle != NULL);
assert(handle->data != NULL);
Async* async = static_cast<Async*>(handle->data);
delete async;
}
void finish() {
// Need to call the listener again to ensure all items have been
// processed. Is this a bug in uv_async? Feels like uv_close
// should handle that.
listener(&watcher, 0);
uv_close((uv_handle_t*)&watcher, close);
}
void add(Item* item) {
NODE_SQLITE3_MUTEX_LOCK(&mutex);
data.push_back(item);
NODE_SQLITE3_MUTEX_UNLOCK(&mutex)
}
void send() {
uv_async_send(&watcher);
}
void send(Item* item) {
add(item);
send();
}
~Async() {
NODE_SQLITE3_MUTEX_DESTROY
}
};
#endif
This diff is collapsed.
#ifndef NODE_SQLITE3_SRC_DATABASE_H
#define NODE_SQLITE3_SRC_DATABASE_H
#include <string>
#include <queue>
#include <sqlite3.h>
#include <nan.h>
#include "async.h"
using namespace v8;
namespace node_sqlite3 {
class Database;
class Database : public Nan::ObjectWrap {
public:
static Nan::Persistent<FunctionTemplate> constructor_template;
static NAN_MODULE_INIT(Init);
static inline bool HasInstance(Local<Value> val) {
Nan::HandleScope scope;
if (!val->IsObject()) return false;
Local<Object> obj = val.As<Object>();
return Nan::New(constructor_template)->HasInstance(obj);
}
struct Baton {
uv_work_t request;
Database* db;
Nan::Persistent<Function> callback;
int status;
std::string message;
Baton(Database* db_, Local<Function> cb_) :
db(db_), status(SQLITE_OK) {
db->Ref();
request.data = this;
callback.Reset(cb_);
}
virtual ~Baton() {
db->Unref();
callback.Reset();
}
};
struct OpenBaton : Baton {
std::string filename;
int mode;
OpenBaton(Database* db_, Local<Function> cb_, const char* filename_, int mode_) :
Baton(db_, cb_), filename(filename_), mode(mode_) {}
};
struct ExecBaton : Baton {
std::string sql;
ExecBaton(Database* db_, Local<Function> cb_, const char* sql_) :
Baton(db_, cb_), sql(sql_) {}
};
struct LoadExtensionBaton : Baton {
std::string filename;
LoadExtensionBaton(Database* db_, Local<Function> cb_, const char* filename_) :
Baton(db_, cb_), filename(filename_) {}
};
typedef void (*Work_Callback)(Baton* baton);
struct Call {
Call(Work_Callback cb_, Baton* baton_, bool exclusive_ = false) :
callback(cb_), exclusive(exclusive_), baton(baton_) {};
Work_Callback callback;
bool exclusive;
Baton* baton;
};
struct ProfileInfo {
std::string sql;
sqlite3_int64 nsecs;
};
struct UpdateInfo {
int type;
std::string database;
std::string table;
sqlite3_int64 rowid;
};
bool IsOpen() { return open; }
bool IsLocked() { return locked; }
typedef Async<std::string, Database> AsyncTrace;
typedef Async<ProfileInfo, Database> AsyncProfile;
typedef Async<UpdateInfo, Database> AsyncUpdate;
friend class Statement;
protected:
Database() : Nan::ObjectWrap(),
_handle(NULL),
open(false),
closing(false),
locked(false),
pending(0),
serialize(false),
debug_trace(NULL),
debug_profile(NULL),
update_event(NULL) {
}
~Database() {
RemoveCallbacks();
sqlite3_close(_handle);
_handle = NULL;
open = false;
}
static NAN_METHOD(New);
static void Work_BeginOpen(Baton* baton);
static void Work_Open(uv_work_t* req);
static void Work_AfterOpen(uv_work_t* req);
static NAN_GETTER(OpenGetter);
void Schedule(Work_Callback callback, Baton* baton, bool exclusive = false);
void Process();
static NAN_METHOD(Exec);
static void Work_BeginExec(Baton* baton);
static void Work_Exec(uv_work_t* req);
static void Work_AfterExec(uv_work_t* req);
static NAN_METHOD(Wait);
static void Work_Wait(Baton* baton);
static NAN_METHOD(Close);
static void Work_BeginClose(Baton* baton);
static void Work_Close(uv_work_t* req);
static void Work_AfterClose(uv_work_t* req);
static NAN_METHOD(LoadExtension);
static void Work_BeginLoadExtension(Baton* baton);
static void Work_LoadExtension(uv_work_t* req);
static void Work_AfterLoadExtension(uv_work_t* req);
static NAN_METHOD(Serialize);
static NAN_METHOD(Parallelize);
static NAN_METHOD(Configure);
static NAN_METHOD(Interrupt);
static void SetBusyTimeout(Baton* baton);
static void RegisterTraceCallback(Baton* baton);
static void TraceCallback(void* db, const char* sql);
static void TraceCallback(Database* db, std::string* sql);
static void RegisterProfileCallback(Baton* baton);
static void ProfileCallback(void* db, const char* sql, sqlite3_uint64 nsecs);
static void ProfileCallback(Database* db, ProfileInfo* info);
static void RegisterUpdateCallback(Baton* baton);
static void UpdateCallback(void* db, int type, const char* database, const char* table, sqlite3_int64 rowid);
static void UpdateCallback(Database* db, UpdateInfo* info);
void RemoveCallbacks();
protected:
sqlite3* _handle;
bool open;
bool closing;
bool locked;
unsigned int pending;
bool serialize;
std::queue<Call*> queue;
AsyncTrace* debug_trace;
AsyncProfile* debug_profile;
AsyncUpdate* update_event;
};
}
#endif
// http://web.archive.org/web/20140401031018/http://rjpower9000.wordpress.com:80/2012/04/09/fun-with-shared-libraries-version-glibc_2-14-not-found/
#if defined(__linux__) && defined(__x86_64__)
__asm__(".symver memcpy,memcpy@GLIBC_2.2.5");
#endif
#ifndef NODE_SQLITE3_SRC_MACROS_H
#define NODE_SQLITE3_SRC_MACROS_H
const char* sqlite_code_string(int code);
const char* sqlite_authorizer_string(int type);
#define REQUIRE_ARGUMENTS(n) \
if (info.Length() < (n)) { \
return Nan::ThrowTypeError("Expected " #n "arguments"); \
}
#define REQUIRE_ARGUMENT_EXTERNAL(i, var) \
if (info.Length() <= (i) || !info[i]->IsExternal()) { \
return Nan::ThrowTypeError("Argument " #i " invalid"); \
} \
Local<External> var = Local<External>::Cast(info[i]);
#define REQUIRE_ARGUMENT_FUNCTION(i, var) \
if (info.Length() <= (i) || !info[i]->IsFunction()) { \
return Nan::ThrowTypeError("Argument " #i " must be a function"); \
} \
Local<Function> var = Local<Function>::Cast(info[i]);
#define REQUIRE_ARGUMENT_STRING(i, var) \
if (info.Length() <= (i) || !info[i]->IsString()) { \
return Nan::ThrowTypeError("Argument " #i " must be a string"); \
} \
Nan::Utf8String var(info[i]);
#define OPTIONAL_ARGUMENT_FUNCTION(i, var) \
Local<Function> var; \
if (info.Length() > i && !info[i]->IsUndefined()) { \
if (!info[i]->IsFunction()) { \
return Nan::ThrowTypeError("Argument " #i " must be a function"); \
} \
var = Local<Function>::Cast(info[i]); \
}
#define OPTIONAL_ARGUMENT_INTEGER(i, var, default) \
int var; \
if (info.Length() <= (i)) { \
var = (default); \
} \
else if (info[i]->IsInt32()) { \
var = Nan::To<int32_t>(info[i]).FromJust(); \
} \
else { \
return Nan::ThrowTypeError("Argument " #i " must be an integer"); \
}
#define DEFINE_CONSTANT_INTEGER(target, constant, name) \
Nan::ForceSet(target, \
Nan::New(#name).ToLocalChecked(), \
Nan::New<Integer>(constant), \
static_cast<PropertyAttribute>(ReadOnly | DontDelete) \
);
#define DEFINE_CONSTANT_STRING(target, constant, name) \
Nan::ForceSet(target, \
Nan::New(#name).ToLocalChecked(), \
Nan::New(constant).ToLocalChecked(), \
static_cast<PropertyAttribute>(ReadOnly | DontDelete) \
);
#define NODE_SET_GETTER(target, name, function) \
Nan::SetAccessor((target)->InstanceTemplate(), \
Nan::New(name).ToLocalChecked(), (function));
#define GET_STRING(source, name, property) \
Nan::Utf8String name(Nan::Get(source, \
Nan::New(prop).ToLocalChecked()).ToLocalChecked());
#define GET_INTEGER(source, name, prop) \
int name = Nan::To<int>(Nan::Get(source, \
Nan::New(property).ToLocalChecked()).ToLocalChecked()).FromJust();
#define EXCEPTION(msg, errno, name) \
Local<Value> name = Exception::Error( \
String::Concat( \
String::Concat( \
Nan::New(sqlite_code_string(errno)).ToLocalChecked(), \
Nan::New(": ").ToLocalChecked() \
), \
(msg) \
) \
); \
Local<Object> name ##_obj = name.As<Object>(); \
Nan::Set(name ##_obj, Nan::New("errno").ToLocalChecked(), Nan::New(errno));\
Nan::Set(name ##_obj, Nan::New("code").ToLocalChecked(), \
Nan::New(sqlite_code_string(errno)).ToLocalChecked());
#define EMIT_EVENT(obj, argc, argv) \
TRY_CATCH_CALL((obj), \
Nan::Get(obj, \
Nan::New("emit").ToLocalChecked()).ToLocalChecked().As<Function>(),\
argc, argv \
);
#define TRY_CATCH_CALL(context, callback, argc, argv) \
Nan::MakeCallback((context), (callback), (argc), (argv))
#define WORK_DEFINITION(name) \
static NAN_METHOD(name); \
static void Work_Begin##name(Baton* baton); \
static void Work_##name(uv_work_t* req); \
static void Work_After##name(uv_work_t* req);
#define STATEMENT_BEGIN(type) \
assert(baton); \
assert(baton->stmt); \
assert(!baton->stmt->locked); \
assert(!baton->stmt->finalized); \
assert(baton->stmt->prepared); \
baton->stmt->locked = true; \
baton->stmt->db->pending++; \
int status = uv_queue_work(uv_default_loop(), \
&baton->request, \
Work_##type, reinterpret_cast<uv_after_work_cb>(Work_After##type)); \
assert(status == 0);
#define STATEMENT_INIT(type) \
type* baton = static_cast<type*>(req->data); \
Statement* stmt = baton->stmt;
#define STATEMENT_END() \
assert(stmt->locked); \
assert(stmt->db->pending); \
stmt->locked = false; \
stmt->db->pending--; \
stmt->Process(); \
stmt->db->Process(); \
delete baton;
#define DELETE_FIELD(field) \
if (field != NULL) { \
switch ((field)->type) { \
case SQLITE_INTEGER: delete (Values::Integer*)(field); break; \
case SQLITE_FLOAT: delete (Values::Float*)(field); break; \
case SQLITE_TEXT: delete (Values::Text*)(field); break; \
case SQLITE_BLOB: delete (Values::Blob*)(field); break; \
case SQLITE_NULL: delete (Values::Null*)(field); break; \
} \
}
#endif
#include <stdint.h>
#include <sstream>
#include <cstring>
#include <string>
#include <sqlite3.h>
#include "macros.h"
#include "database.h"
#include "statement.h"
using namespace node_sqlite3;
namespace {
NAN_MODULE_INIT(RegisterModule) {
Nan::HandleScope scope;
Database::Init(target);
Statement::Init(target);
DEFINE_CONSTANT_INTEGER(target, SQLITE_OPEN_READONLY, OPEN_READONLY);
DEFINE_CONSTANT_INTEGER(target, SQLITE_OPEN_READWRITE, OPEN_READWRITE);
DEFINE_CONSTANT_INTEGER(target, SQLITE_OPEN_CREATE, OPEN_CREATE);
DEFINE_CONSTANT_STRING(target, SQLITE_VERSION, VERSION);
#ifdef SQLITE_SOURCE_ID
DEFINE_CONSTANT_STRING(target, SQLITE_SOURCE_ID, SOURCE_ID);
#endif
DEFINE_CONSTANT_INTEGER(target, SQLITE_VERSION_NUMBER, VERSION_NUMBER);
DEFINE_CONSTANT_INTEGER(target, SQLITE_OK, OK);
DEFINE_CONSTANT_INTEGER(target, SQLITE_ERROR, ERROR);
DEFINE_CONSTANT_INTEGER(target, SQLITE_INTERNAL, INTERNAL);
DEFINE_CONSTANT_INTEGER(target, SQLITE_PERM, PERM);
DEFINE_CONSTANT_INTEGER(target, SQLITE_ABORT, ABORT);
DEFINE_CONSTANT_INTEGER(target, SQLITE_BUSY, BUSY);
DEFINE_CONSTANT_INTEGER(target, SQLITE_LOCKED, LOCKED);
DEFINE_CONSTANT_INTEGER(target, SQLITE_NOMEM, NOMEM);
DEFINE_CONSTANT_INTEGER(target, SQLITE_READONLY, READONLY);
DEFINE_CONSTANT_INTEGER(target, SQLITE_INTERRUPT, INTERRUPT);
DEFINE_CONSTANT_INTEGER(target, SQLITE_IOERR, IOERR);
DEFINE_CONSTANT_INTEGER(target, SQLITE_CORRUPT, CORRUPT);
DEFINE_CONSTANT_INTEGER(target, SQLITE_NOTFOUND, NOTFOUND);
DEFINE_CONSTANT_INTEGER(target, SQLITE_FULL, FULL);
DEFINE_CONSTANT_INTEGER(target, SQLITE_CANTOPEN, CANTOPEN);
DEFINE_CONSTANT_INTEGER(target, SQLITE_PROTOCOL, PROTOCOL);
DEFINE_CONSTANT_INTEGER(target, SQLITE_EMPTY, EMPTY);
DEFINE_CONSTANT_INTEGER(target, SQLITE_SCHEMA, SCHEMA);
DEFINE_CONSTANT_INTEGER(target, SQLITE_TOOBIG, TOOBIG);
DEFINE_CONSTANT_INTEGER(target, SQLITE_CONSTRAINT, CONSTRAINT);
DEFINE_CONSTANT_INTEGER(target, SQLITE_MISMATCH, MISMATCH);
DEFINE_CONSTANT_INTEGER(target, SQLITE_MISUSE, MISUSE);
DEFINE_CONSTANT_INTEGER(target, SQLITE_NOLFS, NOLFS);
DEFINE_CONSTANT_INTEGER(target, SQLITE_AUTH, AUTH);
DEFINE_CONSTANT_INTEGER(target, SQLITE_FORMAT, FORMAT);
DEFINE_CONSTANT_INTEGER(target, SQLITE_RANGE, RANGE);
DEFINE_CONSTANT_INTEGER(target, SQLITE_NOTADB, NOTADB);
}
}
const char* sqlite_code_string(int code) {
switch (code) {
case SQLITE_OK: return "SQLITE_OK";
case SQLITE_ERROR: return "SQLITE_ERROR";
case SQLITE_INTERNAL: return "SQLITE_INTERNAL";
case SQLITE_PERM: return "SQLITE_PERM";
case SQLITE_ABORT: return "SQLITE_ABORT";
case SQLITE_BUSY: return "SQLITE_BUSY";
case SQLITE_LOCKED: return "SQLITE_LOCKED";
case SQLITE_NOMEM: return "SQLITE_NOMEM";
case SQLITE_READONLY: return "SQLITE_READONLY";
case SQLITE_INTERRUPT: return "SQLITE_INTERRUPT";
case SQLITE_IOERR: return "SQLITE_IOERR";
case SQLITE_CORRUPT: return "SQLITE_CORRUPT";
case SQLITE_NOTFOUND: return "SQLITE_NOTFOUND";
case SQLITE_FULL: return "SQLITE_FULL";
case SQLITE_CANTOPEN: return "SQLITE_CANTOPEN";
case SQLITE_PROTOCOL: return "SQLITE_PROTOCOL";
case SQLITE_EMPTY: return "SQLITE_EMPTY";
case SQLITE_SCHEMA: return "SQLITE_SCHEMA";
case SQLITE_TOOBIG: return "SQLITE_TOOBIG";
case SQLITE_CONSTRAINT: return "SQLITE_CONSTRAINT";
case SQLITE_MISMATCH: return "SQLITE_MISMATCH";
case SQLITE_MISUSE: return "SQLITE_MISUSE";
case SQLITE_NOLFS: return "SQLITE_NOLFS";
case SQLITE_AUTH: return "SQLITE_AUTH";
case SQLITE_FORMAT: return "SQLITE_FORMAT";
case SQLITE_RANGE: return "SQLITE_RANGE";
case SQLITE_NOTADB: return "SQLITE_NOTADB";
case SQLITE_ROW: return "SQLITE_ROW";
case SQLITE_DONE: return "SQLITE_DONE";
default: return "UNKNOWN";
}
}
const char* sqlite_authorizer_string(int type) {
switch (type) {
case SQLITE_INSERT: return "insert";
case SQLITE_UPDATE: return "update";
case SQLITE_DELETE: return "delete";
default: return "";
}
}
NODE_MODULE(node_sqlite3, RegisterModule)
This diff is collapsed.
#ifndef NODE_SQLITE3_SRC_STATEMENT_H
#define NODE_SQLITE3_SRC_STATEMENT_H
#include "database.h"
#include "threading.h"
#include <cstdlib>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <sqlite3.h>
#include <nan.h>
using namespace v8;
using namespace node;
namespace node_sqlite3 {
namespace Values {
struct Field {
inline Field(unsigned short _index, unsigned short _type = SQLITE_NULL) :
type(_type), index(_index) {}
inline Field(const char* _name, unsigned short _type = SQLITE_NULL) :
type(_type), index(0), name(_name) {}
unsigned short type;
unsigned short index;
std::string name;
};
struct Integer : Field {
template <class T> inline Integer(T _name, int64_t val) :
Field(_name, SQLITE_INTEGER), value(val) {}
int64_t value;
};
struct Float : Field {
template <class T> inline Float(T _name, double val) :
Field(_name, SQLITE_FLOAT), value(val) {}
double value;
};
struct Text : Field {
template <class T> inline Text(T _name, size_t len, const char* val) :
Field(_name, SQLITE_TEXT), value(val, len) {}
std::string value;
};
struct Blob : Field {
template <class T> inline Blob(T _name, size_t len, const void* val) :
Field(_name, SQLITE_BLOB), length(len) {
value = (char*)malloc(len);
memcpy(value, val, len);
}
inline ~Blob() {
free(value);
}
int length;
char* value;
};
typedef Field Null;
}
typedef std::vector<Values::Field*> Row;
typedef std::vector<Row*> Rows;
typedef Row Parameters;
class Statement : public Nan::ObjectWrap {
public:
static Nan::Persistent<FunctionTemplate> constructor_template;
static NAN_MODULE_INIT(Init);
static NAN_METHOD(New);
struct Baton {
uv_work_t request;
Statement* stmt;
Nan::Persistent<Function> callback;
Parameters parameters;
Baton(Statement* stmt_, Local<Function> cb_) : stmt(stmt_) {
stmt->Ref();
request.data = this;
callback.Reset(cb_);
}
virtual ~Baton() {
for (unsigned int i = 0; i < parameters.size(); i++) {
Values::Field* field = parameters[i];
DELETE_FIELD(field);
}
stmt->Unref();
callback.Reset();
}
};
struct RowBaton : Baton {
RowBaton(Statement* stmt_, Local<Function> cb_) :
Baton(stmt_, cb_) {}
Row row;
};
struct RunBaton : Baton {
RunBaton(Statement* stmt_, Local<Function> cb_) :
Baton(stmt_, cb_), inserted_id(0), changes(0) {}
sqlite3_int64 inserted_id;
int changes;
};
struct RowsBaton : Baton {
RowsBaton(Statement* stmt_, Local<Function> cb_) :
Baton(stmt_, cb_) {}
Rows rows;
};
struct Async;
struct EachBaton : Baton {
Nan::Persistent<Function> completed;
Async* async; // Isn't deleted when the baton is deleted.
EachBaton(Statement* stmt_, Local<Function> cb_) :
Baton(stmt_, cb_) {}
virtual ~EachBaton() {
completed.Reset();
}
};
struct PrepareBaton : Database::Baton {
Statement* stmt;
std::string sql;
PrepareBaton(Database* db_, Local<Function> cb_, Statement* stmt_) :
Baton(db_, cb_), stmt(stmt_) {
stmt->Ref();
}
virtual ~PrepareBaton() {
stmt->Unref();
if (!db->IsOpen() && db->IsLocked()) {
// The database handle was closed before the statement could be
// prepared.
stmt->Finalize();
}
}
};
typedef void (*Work_Callback)(Baton* baton);
struct Call {
Call(Work_Callback cb_, Baton* baton_) : callback(cb_), baton(baton_) {};
Work_Callback callback;
Baton* baton;
};
struct Async {
uv_async_t watcher;
Statement* stmt;
Rows data;
NODE_SQLITE3_MUTEX_t;
bool completed;
int retrieved;
// Store the callbacks here because we don't have
// access to the baton in the async callback.
Nan::Persistent<Function> item_cb;
Nan::Persistent<Function> completed_cb;
Async(Statement* st, uv_async_cb async_cb) :
stmt(st), completed(false), retrieved(0) {
watcher.data = this;
NODE_SQLITE3_MUTEX_INIT
stmt->Ref();
uv_async_init(uv_default_loop(), &watcher, async_cb);
}
~Async() {
stmt->Unref();
item_cb.Reset();
completed_cb.Reset();
NODE_SQLITE3_MUTEX_DESTROY
}
};
Statement(Database* db_) : Nan::ObjectWrap(),
db(db_),
_handle(NULL),
status(SQLITE_OK),
prepared(false),
locked(true),
finalized(false) {
db->Ref();
}
~Statement() {
if (!finalized) Finalize();
}
WORK_DEFINITION(Bind);
WORK_DEFINITION(Get);
WORK_DEFINITION(Run);
WORK_DEFINITION(All);
WORK_DEFINITION(Each);
WORK_DEFINITION(Reset);
static NAN_METHOD(Finalize);
protected:
static void Work_BeginPrepare(Database::Baton* baton);
static void Work_Prepare(uv_work_t* req);
static void Work_AfterPrepare(uv_work_t* req);
static void AsyncEach(uv_async_t* handle, int status);
static void CloseCallback(uv_handle_t* handle);
static void Finalize(Baton* baton);
void Finalize();
template <class T> inline Values::Field* BindParameter(const Local<Value> source, T pos);
template <class T> T* Bind(Nan::NAN_METHOD_ARGS_TYPE info, int start = 0, int end = -1);
bool Bind(const Parameters &parameters);
static void GetRow(Row* row, sqlite3_stmt* stmt);
static Local<Object> RowToJS(Row* row);
void Schedule(Work_Callback callback, Baton* baton);
void Process();
void CleanQueue();
template <class T> static void Error(T* baton);
protected:
Database* db;
sqlite3_stmt* _handle;
int status;
std::string message;
bool prepared;
bool locked;
bool finalized;
std::queue<Call*> queue;
};
}
#endif
#ifndef NODE_SQLITE3_SRC_THREADING_H
#define NODE_SQLITE3_SRC_THREADING_H
#ifdef _WIN32
#include <windows.h>
#define NODE_SQLITE3_MUTEX_t HANDLE mutex;
#define NODE_SQLITE3_MUTEX_INIT mutex = CreateMutex(NULL, FALSE, NULL);
#define NODE_SQLITE3_MUTEX_LOCK(m) WaitForSingleObject(*m, INFINITE);
#define NODE_SQLITE3_MUTEX_UNLOCK(m) ReleaseMutex(*m);
#define NODE_SQLITE3_MUTEX_DESTROY CloseHandle(mutex);
#elif defined(NODE_SQLITE3_BOOST_THREADING)
#include <boost/thread/mutex.hpp>
#define NODE_SQLITE3_MUTEX_t boost::mutex mutex;
#define NODE_SQLITE3_MUTEX_INIT
#define NODE_SQLITE3_MUTEX_LOCK(m) (*m).lock();
#define NODE_SQLITE3_MUTEX_UNLOCK(m) (*m).unlock();
#define NODE_SQLITE3_MUTEX_DESTROY mutex.unlock();
#else
#define NODE_SQLITE3_MUTEX_t pthread_mutex_t mutex;
#define NODE_SQLITE3_MUTEX_INIT pthread_mutex_init(&mutex,NULL);
#define NODE_SQLITE3_MUTEX_LOCK(m) pthread_mutex_lock(m);
#define NODE_SQLITE3_MUTEX_UNLOCK(m) pthread_mutex_unlock(m);
#define NODE_SQLITE3_MUTEX_DESTROY pthread_mutex_destroy(&mutex);
#endif
#endif // NODE_SQLITE3_SRC_THREADING_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment