Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
node-sqlite3
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
node-sqlite3
Commits
bbde96ea
Commit
bbde96ea
authored
Feb 21, 2011
by
Konstantin Käfer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update license headers
parent
2e0690b7
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
18 additions
and
281 deletions
+18
-281
README.md
README.md
+18
-182
sqlite3.js
lib/sqlite3.js
+0
-15
database.cc
src/database.cc
+0
-14
database.h
src/database.h
+0
-14
macros.h
src/macros.h
+0
-14
sqlite3_bindings.cc
src/sqlite3_bindings.cc
+0
-14
statement.cc
src/statement.cc
+0
-14
statement.h
src/statement.h
+0
-14
No files found.
README.md
View file @
bbde96ea
# NAME
# NAME
node-sqlite - Asynchronous SQLite3 driver for Node.js
node-sqlite3 - Asynchronous, non-blocking SQLite3 bindings for Node.js
SQLite calls block, so to work around this, synchronous calls happen within
Node's libeio thread-pool, in a similar manner to how POSIX calls are
currently made.
# SYNOPSIS
# SYNOPSIS
## High-level Driver
TODO
var sys = require('sys'),
sqlite = require('sqlite');
var db = new sqlite.Database();
// open the database for reading if file exists
// create new database file if not
db.open("aquateen.db", function (error) {
if (error) {
console.log("Tonight. You."));
throw error;
}
db.execute
( "INSERT INTO aqua_teens (name) VALUES (?)"
, ['meaty meaty moo']
, function (error, rows) {
if (error) throw error;
console.log("Aqua teen added.");
}
);
var sql = 'SELECT name FROM dudes WHERE type = ? AND age > ?';
db.prepare(sql, function (error, statement) {
if (error) throw error;
// Fill in the placeholders
statement.bindArray(['milkshake', 30], function () {
statement.fetchAll(function (error, rows) {
// ...
statement.finalize(function (error) {
console.log("All done!");
});
});
});
});
});
# API
## Database Objects
To create a new database object:
var sqlite = require('sqlite');
var db = sqlite.Database();
### database.open(filename, function (error) {})
Open a database handle to the database at the specified filename. If the file
does not exist the bindings will attempt to create it. The callback takes no
arguments.
A filename of ":memory:" may be used to create an in-memory database.
### database.close(function (error) {})
Close the database handle.
### database.execute(sql[, bindings], function (error, rows) {})
Execute a SQL query,
`sql`
with optional bindings
`bindings`
on the currently
opened database. The callback will be executed once with all the rows returned
for the query. This is much faster than
`database.query`
since there are less roundtrips into the thread-pool.
### database.query(sql, [bindings,] function (error, row) {})
Execute a SQL query,
`sql`
, with optional bindings
`bindings`
on the currently
opened database. The callback will be executed once per row returned, plus
once more with row set to undefined to indicate end of results.
### database.executeScript(SQL, function (error) {});
db.executeScript
( "CREATE TABLE table1 (id, name);"
+ "CREATE TABLE table2 (id, age);"
+ "INSERT INTO table1 (1, 'Mister Shake');"
+ "INSER INTO table2 (1, 34);"
, function (error) {
if (error) throw error;
// ...
});
Execute multiple semi-colon separated SQL statements. Statements must take no
placeholders. Each statement will be executed with a single step() and then
reset. This is ideally suited to executing multiple DDL statements.
### database.prepare(SQL, [options,] function (error, statement) {})
Create a prepared statement from an SQL string. Prepared statements can be
used used to iterate over results and to avoid compiling SQL each time a query
is performed.
Options:
-
lastInsertRowID: boolean, default false.
If true, when this statement is step()'d over, the context object (this) in
the callback will contain a lastInsertRowID member with the ID of the last
inserted row.
-
affectedRows: boolean, default false.
If true, when this statement is step()'d over, the context object (this) in
the callback will contain an affectedRows member with the number of
affected rows for the last step.
## Statement Objects
### statement.bindArray(array, function (error) {})
statement.bindArray([1, 'robots', 4.20], callback)
Bind array items to place-holder values (? or $foo) in statement.
### statement.bindObject(object, function (error) {})
statement.bindObject({ $name: 'meatwad',
$occupation: 'Former detective' }, callback)
Bind object properties to named place-holder values ($foo, $bar, $baz) in
statement.
### statement.bind(position, value, function (error) {})
statement.bind(1, "tango", function (error) {})
Bind a value to a place-holder position. Because binding place-holders is done
by position (not index), the first place-holder is at position 1, second at
place-holder position 2, etc.
### statement.clearBindings()
Immediately clear the bindings from the statement. There is no callback.
### statement.step(function (error, row) {})
Fetch one row from a prepared statement and hand it off to a callback. If
there are no more rows to be fetched, row will be undefined. Rows are
represented as objects with properties named after the respective columns.
### statement.fetchAll(function (error, rows) {})
Fetch all rows in statement and pass them to the callback as an array of
objects, each object representing one row.
### statement.reset()
Immediately reset a statement object back to it's initial state, ready to be
step() or fetchAll()'d again.
### statement.finalize(function (error) {})
Free SQLite objects associated with this statement and mark it for garbage
collection.
## Supported Types
At the moment, the supported types are TEXT, NUMBER, FLOAT and NULL.
# BUILDING
# BUILDING
To obtain and build the bindings:
To obtain and build the bindings:
git clone http://github.com/orlandov/node-sqlite.git
git clone git://github.com/developmentseed/node-sqlite3.git
cd node-sqlite
cd node-sqlite3
node-waf configure build
./configure
make
# TESTS
# TESTS
Running the unit tests could not be easier. Simply:
[
expresso
](
https://github.com/visionmedia/expresso
)
is required to run unit tests.
git submodule update --init
npm install expresso
./run-tests
make test
# SEE ALSO
# SEE ALSO
*
http://sqlite.org/docs.html
*
http://sqlite.org/docs.html
*
http://github.com/
grumdrig/node-sqlite
/
*
http://github.com/
developmentseed/node-sqlite3
/
# AUTHORS
# AUTHORS
Orlando Vazquez
[
ovazquez@gmail.com
]
*
[
Konstantin Käfer
](
https://github.com/kkaefer
)
*
[
Orlando Vazquez
](
https://github.com/orlandov
)
Ryan Dahl
[
ry@tinyclouds.org
]
#
THANK
S
#
ACKNOWLEDGEMENT
S
Many thanks to Eric Fredricksen for his synchronous driver on which this
Thanks to
[
Orlando Vazquez
](
https://github.com/orlandov
)
,
driver was originally based.
[
Eric Fredricksen
](
https://github.com/grumdrig
)
and
[
Ryan Dahl
](
https://github.com/ry
)
for their SQLite drivers.
*
http://github.com/grumdrig/node-sqlite/
*
http://grumdrig.com/node-sqlite/
# LICENSE
# LICENSE
node-sqlite is BSD licensed.
node-sqlite
3
is BSD licensed.
(c) 201
0 Orlando Vazquez
(c) 201
1 Development Seed
lib/sqlite3.js
View file @
bbde96ea
// Copyright (c) 2009, Eric Fredricksen <e@fredricksen.net>
// Copyright (c) 2010, Orlando Vazquez <ovazquez@gmail.com>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
var
sqlite3
=
module
.
exports
=
exports
=
require
(
'./sqlite3_bindings'
);
var
sqlite3
=
module
.
exports
=
exports
=
require
(
'./sqlite3_bindings'
);
var
sys
=
require
(
"sys"
);
var
sys
=
require
(
"sys"
);
...
...
src/database.cc
View file @
bbde96ea
// Copyright (c) 2010, Orlando Vazquez <ovazquez@gmail.com>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <string.h>
#include <string.h>
#include <v8.h>
#include <v8.h>
#include <node.h>
#include <node.h>
...
...
src/database.h
View file @
bbde96ea
// Copyright (c) 2010, Orlando Vazquez <ovazquez@gmail.com>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifndef NODE_SQLITE3_SRC_DATABASE_H
#ifndef NODE_SQLITE3_SRC_DATABASE_H
#define NODE_SQLITE3_SRC_DATABASE_H
#define NODE_SQLITE3_SRC_DATABASE_H
...
...
src/macros.h
View file @
bbde96ea
// Copyright (c) 2010, Orlando Vazquez <ovazquez@gmail.com>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifndef NODE_SQLITE3_SRC_MACROS_H
#ifndef NODE_SQLITE3_SRC_MACROS_H
#define NODE_SQLITE3_SRC_MACROS_H
#define NODE_SQLITE3_SRC_MACROS_H
...
...
src/sqlite3_bindings.cc
View file @
bbde96ea
// Copyright (c) 2010, Orlando Vazquez <ovazquez@gmail.com>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <v8.h>
#include <v8.h>
#include <node.h>
#include <node.h>
#include <node_events.h>
#include <node_events.h>
...
...
src/statement.cc
View file @
bbde96ea
// Copyright (c) 2010, Orlando Vazquez <ovazquez@gmail.com>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <string.h>
#include <string.h>
#include <v8.h>
#include <v8.h>
#include <node.h>
#include <node.h>
...
...
src/statement.h
View file @
bbde96ea
// Copyright (c) 2010, Orlando Vazquez <ovazquez@gmail.com>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifndef NODE_SQLITE3_SRC_STATEMENT_H
#ifndef NODE_SQLITE3_SRC_STATEMENT_H
#define NODE_SQLITE3_SRC_STATEMENT_H
#define NODE_SQLITE3_SRC_STATEMENT_H
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment