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
5f45466b
Commit
5f45466b
authored
Mar 12, 2010
by
Orlando Vazquez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add simple queueing to queries
parent
b72f6bcd
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
17 deletions
+62
-17
sqlite.js
sqlite.js
+53
-15
sqlite3_bindings.cc
sqlite3_bindings.cc
+1
-0
test3.js
test3.js
+8
-2
No files found.
sqlite.js
View file @
5f45466b
...
...
@@ -19,23 +19,55 @@ var sys = require("sys");
var
puts
=
sys
.
puts
;
var
sqlite
=
require
(
"./sqlite3_bindings"
);
var
Database
=
exports
.
Database
=
sqlite
.
Database
;
var
Database
=
exports
.
Database
=
function
()
{
var
self
=
this
;
this
.
queue
=
[];
this
.
db
=
new
sqlite
.
Database
();
};
Database
.
prototype
.
dispatch
=
function
()
{
puts
(
'dispatching'
);
if
(
!
this
.
queue
||
this
.
currentQuery
||
!
this
.
queue
.
length
)
{
puts
(
"no queries
\
n"
+
inspect
([
this
.
queue
,
this
.
currentQuery
]));
return
;
}
this
.
currentQuery
=
this
.
queue
.
shift
();
puts
(
"current query
\
n"
+
inspect
(
this
.
currentQuery
));
this
.
executeQuery
.
apply
(
this
,
this
.
currentQuery
);
}
Database
.
prototype
.
open
=
function
()
{
this
.
db
.
open
.
apply
(
this
.
db
,
arguments
);
}
Database
.
prototype
.
close
=
function
()
{
this
.
db
.
close
.
apply
(
this
.
db
,
arguments
);
}
Database
.
prototype
.
prepare
=
function
()
{
this
.
db
.
prepare
.
apply
(
this
.
db
,
arguments
);
}
Database
.
prototype
.
query
=
function
(
sql
,
bindings
,
queryCallback
)
{
this
.
queue
=
this
.
queue
||
[];
this
.
queue
.
push
([
sql
,
bindings
,
queryCallback
]);
this
.
dispatch
();
}
Database
.
prototype
.
executeQuery
=
function
(
sql
,
bindings
,
queryCallback
)
{
var
self
=
this
;
if
(
typeof
(
bindings
)
==
"function"
)
{
var
tmp
=
bindings
;
bindings
=
c
allback
;
c
allback
=
tmp
;
bindings
=
queryC
allback
;
queryC
allback
=
tmp
;
}
var
all
=
[];
// Iterate over the list of bindings. Since we can't use something as
// simple as a for or while loop, we'll
use
the event loop
function
doBindingsByIndex
(
statement
,
bindings
,
queryCallback
,
startIndex
)
{
(
function
(
statement
,
bindings
,
start
Index
)
{
// simple as a for or while loop, we'll
just chain them via
the event loop
function
doBindingsByIndex
(
statement
,
bindings
,
queryCallback
)
{
(
function
(
statement
,
bindings
,
bind
Index
)
{
var
innerFunction
=
arguments
.
callee
;
if
(
!
bindings
.
length
)
{
process
.
nextTick
(
function
()
{
...
...
@@ -44,23 +76,28 @@ Database.prototype.query = function (sql, bindings, queryCallback) {
return
;
}
startIndex
=
start
Index
||
1
;
bindIndex
=
bind
Index
||
1
;
var
value
=
bindings
.
shift
();
puts
(
"setting index "
+
start
Index
+
" to "
+
value
);
puts
(
"setting index "
+
bind
Index
+
" to "
+
value
);
process
.
nextTick
(
function
()
{
statement
.
bind
(
start
Index
,
value
,
function
()
{
innerFunction
(
statement
,
bindings
,
start
Index
+
1
);
statement
.
bind
(
bind
Index
,
value
,
function
()
{
innerFunction
(
statement
,
bindings
,
bind
Index
+
1
);
});
});
})(
statement
,
bindings
,
startIndex
);
})(
statement
,
bindings
,
1
);
}
function
queryDone
(
statement
,
rows
)
{
if
(
statement
.
tail
)
{
puts
(
"omg it has a tail"
);
self
.
prepare
(
statement
.
tail
,
onPrepare
);
statement
.
finalize
(
function
()
{
self
.
db
.
prepare
(
statement
.
tail
,
onPrepare
);
});
}
// if there are any queries queued, let them know it's safe to go
self
.
db
.
emit
(
"ready"
);
queryCallback
(
undefined
,
rows
);
}
...
...
@@ -97,7 +134,8 @@ Database.prototype.query = function (sql, bindings, queryCallback) {
}
}
this
.
prepare
(
sql
,
onPrepare
);
puts
(
"preparing"
);
this
.
db
.
prepare
(
sql
,
onPrepare
);
}
function
SQLTransactionSync
(
db
,
txCallback
,
errCallback
,
successCallback
)
{
...
...
sqlite3_bindings.cc
View file @
5f45466b
...
...
@@ -145,6 +145,7 @@ protected:
FatalException
(
try_catch
);
}
open_req
->
dbo
->
Emit
(
String
::
New
(
"ready"
),
0
,
NULL
);
open_req
->
cb
.
Dispose
();
free
(
open_req
);
...
...
test3.js
View file @
5f45466b
...
...
@@ -8,8 +8,14 @@ var db = new sqlite.Database();
db
.
open
(
"mydatabase.db"
,
function
()
{
puts
(
"opened the db"
);
db
.
query
(
"SELECT * FROM foo WHERE baz < ?
OR baz > ?; SELECT 1;
"
,
[
6
,
3
],
function
(
error
,
result
)
{
puts
(
inspect
(
arguments
)
);
db
.
query
(
"SELECT * FROM foo WHERE baz < ?
AND baz > ?
"
,
[
6
,
3
],
function
(
error
,
result
)
{
ok
(
!
error
);
puts
(
"query callback "
+
inspect
(
result
));
equal
(
result
.
length
,
2
);
});
db
.
query
(
"SELECT 1"
,
function
(
error
,
result
)
{
ok
(
!
error
);
puts
(
"query callback "
+
inspect
(
result
));
equal
(
result
.
length
,
1
);
});
});
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