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
e1c1ac6d
Commit
e1c1ac6d
authored
Mar 17, 2010
by
Orlando Vazquez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove some files
parent
4d274ee1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
0 additions
and
341 deletions
+0
-341
examples.html
doc/examples.html
+0
-133
examples.js
doc/examples.js
+0
-124
index.php
doc/index.php
+0
-84
No files found.
doc/examples.html
deleted
100644 → 0
View file @
4d274ee1
<p>
<h2>
Documentation by Example
</h2>
<p>
Import the library and open a database. (Only syncronous database
access is implemented at this time.)
<p>
<pre>
var sqlite = require("../sqlite");
var db = sqlite.openDatabaseSync("example.db");
</pre>
<p>
Perform an SQL query on the database:
<p>
<pre>
db.query("CREATE TABLE foo (a,b,c)");
</pre>
<p>
This is a more convenient form than the HTML5 syntax for the same
thing, but which is also supported:
<p>
<pre>
db.transaction(function(tx) {
tx.executeSql("CREATE TABLE bar (x,y,z)");
});
</pre>
<p>
This allows the same or similar code to work on the client and
server end (modulo browser support of HTML5 Web SQL).
<p>
Transactions generate either a "commit" or "rollback" event.
<p>
<pre>
var rollbacks = 0;
db.addListener("rollback", function () {
++rollbacks;
});
</pre>
<p>
Both forms take an optional second parameter which is values to
bind to fields in the query, as an array:
<p>
<pre>
db.query("INSERT INTO foo (a,b,c) VALUES (?,?,?)", ['apple','banana',22]);
</pre>
<p>
or as a map:
<p>
<pre>
db.query("INSERT INTO bar (x,y,z) VALUES ($x,$y,$zebra)",
{$x: 10, $y:20, $zebra:"stripes"});
</pre>
<p>
Also optional is a callback function which is called with an object
representing the results of the query:
<p>
<pre>
db.query("SELECT x FROM bar", function (records) {
process.assert(records.length == 1);
process.assert(records[0].x == 10);
</pre>
<p>
The HTML5 semantics for the record set also work:
<p>
<pre>
process.assert(records.rows.length == 1);
process.assert(records.rows.item(0).x == 10);
});
</pre>
<p>
INSERT, UPDATE
&
DELETE queries set
<code>
rowsAffected
</code>
on their result
set object:
<p>
<pre>
db.query("UPDATE foo SET a = ? WHERE a = ?", ['orange', 'apple'], function(r) {
process.assert(r.rowsAffected == 1);
});
</pre>
<p>
They also emit an
<code>
"update"
</code>
event.
<p>
INSERT queries set
<code>
insertId
</code>
:
<p>
<pre>
var insert = db.query("INSERT INTO foo VALUES (1,2,3)");
process.assert(insert.insertId == 2);
</pre>
<p>
Note here that the result set passed to the callback is also
returned by
<code>
query
</code>
.
<p>
Multiple-statement queries are supported; each statement's result set is retuned to the callback as a separate parameter:
<p>
<pre>
var q = db.query("UPDATE bar SET z=20; SELECT SUM(z) FROM bar;",
function (update, select) {
process.assert(update.rowsAffected == 1);
process.assert(select[0]['SUM(z)'] == 20);
});
</pre>
<p>
An array of all result sets is available as the
<code>
.all
</code>
property on
each result set:
<p>
<pre>
process.assert(q.all[1].length == 1);
</pre>
<p>
HTML5 semantics are supported.
<p>
<pre>
db.transaction(function(tx) {
tx.executeSql("SELECT * FROM foo WHERE c = ?", [3], function(tx,res) {
process.assert(res.rows.item(0).c == 3);
});
});
</pre>
<p>
The
<code>
query
</code>
and
<code>
transaction
</code>
APIs wrap lower level APIs that more
thinly wrap the underlying C api:
<p>
<pre>
var stmt = db.prepare("INSERT INTO foo VALUES (?,?,?)");
stmt.bind(1, "curly");
stmt.bind(2, "moe");
stmt.bind(3, "larry");
stmt.step(); // Insert Curly, Moe
&
Larry
stmt.reset();
stmt.step(); // Insert another row with same stooges
stmt.reset();
stmt.clearBindings();
stmt.bind(2, "lonely");
stmt.step(); // Insert (null, "lonely", null)
stmt.finalize();
</pre>
<p>
Close it:
<p>
<pre>
db.close();
</pre>
<p>
<p>
</pre>
<p>
</pre>
<p>
doc/examples.js
deleted
100644 → 0
View file @
4d274ee1
#!/usr/local/bin/node
/*
//!! To be processed by docbyex.py (or run by Node)
<h2>Documentation by Example</h2>
*/
// Import the library and open a database. (Only syncronous database
// access is implemented at this time.)
var
sqlite
=
require
(
"../sqlite"
);
var
db
=
sqlite
.
openDatabaseSync
(
"example.db"
);
// Perform an SQL query on the database:
db
.
query
(
"CREATE TABLE foo (a,b,c)"
);
// This is a more convenient form than the HTML5 syntax for the same
// thing, but which is also supported:
db
.
transaction
(
function
(
tx
)
{
tx
.
executeSql
(
"CREATE TABLE bar (x,y,z)"
);
});
// This allows the same or similar code to work on the client and
// server end (modulo browser support of HTML5 Web SQL).
// Transactions generate either a "commit" or "rollback" event.
var
rollbacks
=
0
;
db
.
addListener
(
"rollback"
,
function
()
{
++
rollbacks
;
});
// Both forms take an optional second parameter which is values to
// bind to fields in the query, as an array:
db
.
query
(
"INSERT INTO foo (a,b,c) VALUES (?,?,?)"
,
[
'apple'
,
'banana'
,
22
]);
// or as a map:
db
.
query
(
"INSERT INTO bar (x,y,z) VALUES ($x,$y,$zebra)"
,
{
$x
:
10
,
$y
:
20
,
$zebra
:
"stripes"
});
// Also optional is a callback function which is called with an object
// representing the results of the query:
db
.
query
(
"SELECT x FROM bar"
,
function
(
records
)
{
process
.
assert
(
records
.
length
==
1
);
process
.
assert
(
records
[
0
].
x
==
10
);
// The HTML5 semantics for the record set also work:
process
.
assert
(
records
.
rows
.
length
==
1
);
process
.
assert
(
records
.
rows
.
item
(
0
).
x
==
10
);
});
// INSERT, UPDATE & DELETE queries set `rowsAffected` on their result
// set object:
db
.
query
(
"UPDATE foo SET a = ? WHERE a = ?"
,
[
'orange'
,
'apple'
],
function
(
r
)
{
process
.
assert
(
r
.
rowsAffected
==
1
);
});
// They also emit an `"update"` event.
// INSERT queries set `insertId`:
var
insert
=
db
.
query
(
"INSERT INTO foo VALUES (1,2,3)"
);
process
.
assert
(
insert
.
insertId
==
2
);
// Note here that the result set passed to the callback is also
// returned by `query`.
// Multiple-statement queries are supported; each statement's result set is retuned to the callback as a separate parameter:
var
q
=
db
.
query
(
"UPDATE bar SET z=20; SELECT SUM(z) FROM bar;"
,
function
(
update
,
select
)
{
process
.
assert
(
update
.
rowsAffected
==
1
);
process
.
assert
(
select
[
0
][
'SUM(z)'
]
==
20
);
});
// An array of all result sets is available as the `.all` property on
// each result set:
process
.
assert
(
q
.
all
[
1
].
length
==
1
);
// HTML5 semantics are supported.
db
.
transaction
(
function
(
tx
)
{
tx
.
executeSql
(
"SELECT * FROM foo WHERE c = ?"
,
[
3
],
function
(
tx
,
res
)
{
process
.
assert
(
res
.
rows
.
item
(
0
).
c
==
3
);
});
});
// The `query` and `transaction` APIs wrap lower level APIs that more
// thinly wrap the underlying C api:
var
stmt
=
db
.
prepare
(
"INSERT INTO foo VALUES (?,?,?)"
);
stmt
.
bind
(
1
,
"curly"
);
stmt
.
bind
(
2
,
"moe"
);
stmt
.
bind
(
3
,
"larry"
);
stmt
.
step
();
// Insert Curly, Moe & Larry
stmt
.
reset
();
stmt
.
step
();
// Insert another row with same stooges
stmt
.
reset
();
stmt
.
clearBindings
();
stmt
.
bind
(
2
,
"lonely"
);
stmt
.
step
();
// Insert (null, "lonely", null)
stmt
.
finalize
();
// Close it:
db
.
close
();
// !!**
// Might as well clean up the mess we made.
var
posix
=
require
(
"posix"
);
posix
.
unlink
(
'example.db'
);
var
sys
=
require
(
"sys"
);
sys
.
puts
(
"OK"
);
doc/index.php
deleted
100644 → 0
View file @
4d274ee1
<head>
<title>
node-sqlite
</title>
<style>
pre
,
code
{
color
:
#060
;
font-size
:
11pt
;
}
pre
{
margin-left
:
2ex
;
padding
:
1ex
;
background-color
:
#eee
;
}
p
{
font-size
:
12pt
;
}
body
{
margin-left
:
10%
;
margin-right
:
10%
;
background-color
:
#fff
;
color
:
black
;
max-width
:
800px
;
}
h1
,
h2
,
h3
,
h4
{
font-family
:
helvetica
}
h1
{
font-size
:
36pt
;
}
h1
{
background-color
:
#58b
;
color
:
white
;
padding-left
:
6px
;
}
h2
{
color
:
#28b
;
}
</style>
</head>
<body>
<h1>
node-sqlite
</h1>
<a
href=
http://sqlite.org/
>
SQLite
</a>
bindings for
<a
//
href=
http://nodejs.org/
>
Node
</a>
.
<p>
The semantics conform somewhat to those of the
<a
href=
http://dev.w3.org/html5/webdatabase/#sql
>
HTML5 Web SQL API
</a>
,
plus some extensions. Also, only the synchronous API is implemented;
the asynchronous API is a big TODO item.
<h2>
Download
</h2>
<p>
The spiritual home of node-sqlite is at
<a
href=
http://grumdrig.com/node-sqlite/
>
http://grumdrig.com/node-sqlite/
</a>
.
<p>
The code lives at
<a
href=
http://code.google.com/p/node-sqlite/
>
http://code.google.com/p/node-sqlite/
</a>
.
<?
readfile
(
'examples.html'
)
?>
<h2>
Installation
</h2>
<p>
<ol>
<li>
Install
<a
//
href=
http://nodejs.org/
>
Node
</a>
and
<a
href=
http://sqlite.org/
>
SQLite
</a>
.
<p>
<li>
Get the code
<pre>
$ git clone git://github.com/grumdrig/node-sqlite.git
</pre>
<li>
Configure and build
<pre>
$ cd node-sqlite
$ node-waf configure
$ node-waf build
</pre>
<li>
Test:
<pre>
$ node test.js
$ node doc/examples.js
</pre>
</ol>
<p>
The two files needed to use this library are
<code>
sqlite.js
</code>
and
<code>
build/default/sqlite3_bindings.node
</code>
; copy them where you need
them.
\ No newline at end of file
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