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
317b3811
Commit
317b3811
authored
Mar 17, 2010
by
Orlando Vazquez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move some nested functions out of performance hot spots
parent
989f5a6b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
37 deletions
+38
-37
sqlite.js
sqlite.js
+38
-37
No files found.
sqlite.js
View file @
317b3811
...
...
@@ -21,8 +21,8 @@ var sqlite = require("./sqlite3_bindings");
var
Database
=
exports
.
Database
=
function
()
{
var
self
=
this
;
this
.
queue
=
[];
this
.
d
b
=
new
sqlite
.
Database
();
this
.
d
b
.
addListener
(
"ready"
,
function
()
{
this
.
d
river
=
new
sqlite
.
Database
();
this
.
d
river
.
addListener
(
"ready"
,
function
()
{
self
.
dispatch
();
});
};
...
...
@@ -37,15 +37,15 @@ Database.prototype.dispatch = function () {
}
Database
.
prototype
.
open
=
function
()
{
this
.
d
b
.
open
.
apply
(
this
.
db
,
arguments
);
this
.
d
river
.
open
.
apply
(
this
.
driver
,
arguments
);
}
Database
.
prototype
.
close
=
function
()
{
this
.
d
b
.
close
.
apply
(
this
.
db
,
arguments
);
this
.
d
river
.
close
.
apply
(
this
.
driver
,
arguments
);
}
Database
.
prototype
.
prepare
=
function
()
{
this
.
d
b
.
prepare
.
apply
(
this
.
db
,
arguments
);
this
.
d
river
.
prepare
.
apply
(
this
.
driver
,
arguments
);
}
Database
.
prototype
.
query
=
function
(
sql
,
bindings
,
queryCallback
)
{
...
...
@@ -54,21 +54,14 @@ Database.prototype.query = function (sql, bindings, queryCallback) {
this
.
dispatch
();
}
Database
.
prototype
.
executeQuery
=
function
(
sql
,
bindings
,
queryCallback
)
{
var
self
=
this
;
if
(
typeof
(
bindings
)
==
"function"
)
{
var
tmp
=
bindings
;
bindings
=
queryCallback
;
queryCallback
=
tmp
;
}
// Iterate over the list of bindings. Since we can't use something as
// simple as a for or while loop, we'll just chain them via the event loop
function
doBindingsByIndex
(
statement
,
bindings
,
callback
)
{
// Iterate over the list of bindings. Since we can't use something as
// simple as a for or while loop, we'll just chain them via the event loop
function
_setBindingsByIndex
(
db
,
statement
,
bindings
,
nextCallback
,
rowCallback
)
{
puts
(
"setting bindings"
);
var
innerFunction
=
function
(
statement
,
bindings
,
bindIndex
)
{
if
(
!
bindings
.
length
)
{
callback
(
statement
);
nextCallback
(
db
,
statement
,
rowCallback
);
return
;
}
...
...
@@ -80,56 +73,64 @@ Database.prototype.executeQuery = function(sql, bindings, queryCallback) {
});
};
innerFunction
(
statement
,
bindings
,
1
);
}
}
function
queryDone
(
statement
)
{
function
_queryDone
(
db
,
statement
)
{
if
(
statement
.
tail
)
{
statement
.
finalize
(
function
()
{
self
.
db
.
prepare
(
statement
.
tail
,
onPrepare
);
db
.
driver
.
prepare
(
statement
.
tail
,
onPrepare
);
});
return
;
}
statement
.
finalize
(
function
()
{
self
.
currentQuery
=
undefined
;
db
.
currentQuery
=
undefined
;
// if there are any queries queued, let them know it's safe to go
self
.
db
.
emit
(
"ready"
);
db
.
driver
.
emit
(
"ready"
);
});
}
}
function
doStep
(
statement
)
{
function
_doStep
(
db
,
statement
,
rowCallback
)
{
(
function
innerFunction
()
{
statement
.
step
(
function
(
error
,
row
)
{
if
(
error
)
throw
error
;
if
(
!
row
)
{
// rows.rowsAffected = this.changes();
// rows.insertId = this.lastInsertRowid();
query
Callback
();
queryDone
(
statement
);
row
Callback
();
_queryDone
(
db
,
statement
);
return
;
}
query
Callback
(
row
);
row
Callback
(
row
);
innerFunction
();
});
})();
}
}
function
onPrepare
(
error
,
statement
)
{
function
_onPrepare
(
db
,
error
,
statement
,
bindings
,
rowCallback
)
{
if
(
error
)
throw
error
;
if
(
bindings
)
{
if
(
Object
.
prototype
.
toString
.
call
(
bindings
)
===
"[object Array]"
)
{
doBindingsByIndex
(
statement
,
bindings
,
doStep
);
if
(
Array
.
isArray
(
bindings
)
)
{
if
(
bindings
.
length
)
{
_setBindingsByIndex
(
db
,
statement
,
bindings
,
_doStep
,
rowCallback
);
}
else
{
// TODO index by keys
_doStep
(
db
,
statement
,
rowCallback
);
}
}
else
{
doStep
(
statement
);
else
if
(
typeof
(
bindings
)
!==
'undefined'
)
{
// TODO index by keys
}
}
Database
.
prototype
.
executeQuery
=
function
(
sql
,
bindings
,
rowCallback
)
{
var
self
=
this
;
if
(
typeof
(
bindings
)
==
"function"
)
{
rowCallback
=
bindings
;
bindings
=
[];
}
this
.
d
b
.
prepare
(
sql
,
onPrepare
);
this
.
d
river
.
prepare
(
sql
,
function
(
error
,
statement
)
{
_onPrepare
(
self
,
error
,
statement
,
bindings
,
rowCallback
)
}
);
}
function
SQLTransactionSync
(
db
,
txCallback
,
errCallback
,
successCallback
)
{
...
...
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