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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
67 deletions
+68
-67
sqlite.js
sqlite.js
+68
-67
No files found.
sqlite.js
View file @
317b3811
...
@@ -21,8 +21,8 @@ var sqlite = require("./sqlite3_bindings");
...
@@ -21,8 +21,8 @@ var sqlite = require("./sqlite3_bindings");
var
Database
=
exports
.
Database
=
function
()
{
var
Database
=
exports
.
Database
=
function
()
{
var
self
=
this
;
var
self
=
this
;
this
.
queue
=
[];
this
.
queue
=
[];
this
.
d
b
=
new
sqlite
.
Database
();
this
.
d
river
=
new
sqlite
.
Database
();
this
.
d
b
.
addListener
(
"ready"
,
function
()
{
this
.
d
river
.
addListener
(
"ready"
,
function
()
{
self
.
dispatch
();
self
.
dispatch
();
});
});
};
};
...
@@ -37,15 +37,15 @@ Database.prototype.dispatch = function () {
...
@@ -37,15 +37,15 @@ Database.prototype.dispatch = function () {
}
}
Database
.
prototype
.
open
=
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
()
{
Database
.
prototype
.
close
=
function
()
{
this
.
d
b
.
close
.
apply
(
this
.
db
,
arguments
);
this
.
d
river
.
close
.
apply
(
this
.
driver
,
arguments
);
}
}
Database
.
prototype
.
prepare
=
function
()
{
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
)
{
Database
.
prototype
.
query
=
function
(
sql
,
bindings
,
queryCallback
)
{
...
@@ -54,82 +54,83 @@ Database.prototype.query = function (sql, bindings, queryCallback) {
...
@@ -54,82 +54,83 @@ Database.prototype.query = function (sql, bindings, queryCallback) {
this
.
dispatch
();
this
.
dispatch
();
}
}
Database
.
prototype
.
executeQuery
=
function
(
sql
,
bindings
,
queryCallback
)
{
// Iterate over the list of bindings. Since we can't use something as
var
self
=
this
;
// simple as a for or while loop, we'll just chain them via the event loop
function
_setBindingsByIndex
(
db
,
if
(
typeof
(
bindings
)
==
"function"
)
{
statement
,
bindings
,
nextCallback
,
rowCallback
)
{
var
tmp
=
bindings
;
puts
(
"setting bindings"
);
bindings
=
queryCallback
;
var
innerFunction
=
function
(
statement
,
bindings
,
bindIndex
)
{
queryCallback
=
tmp
;
if
(
!
bindings
.
length
)
{
}
nextCallback
(
db
,
statement
,
rowCallback
);
// 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
)
{
var
innerFunction
=
function
(
statement
,
bindings
,
bindIndex
)
{
if
(
!
bindings
.
length
)
{
callback
(
statement
);
return
;
}
bindIndex
=
bindIndex
||
1
;
var
value
=
bindings
.
shift
();
statement
.
bind
(
bindIndex
,
value
,
function
()
{
innerFunction
(
statement
,
bindings
,
bindIndex
+
1
);
});
};
innerFunction
(
statement
,
bindings
,
1
);
}
function
queryDone
(
statement
)
{
if
(
statement
.
tail
)
{
statement
.
finalize
(
function
()
{
self
.
db
.
prepare
(
statement
.
tail
,
onPrepare
);
});
return
;
return
;
}
}
bindIndex
=
bindIndex
||
1
;
var
value
=
bindings
.
shift
();
statement
.
bind
(
bindIndex
,
value
,
function
()
{
innerFunction
(
statement
,
bindings
,
bindIndex
+
1
);
});
};
innerFunction
(
statement
,
bindings
,
1
);
}
function
_queryDone
(
db
,
statement
)
{
if
(
statement
.
tail
)
{
statement
.
finalize
(
function
()
{
statement
.
finalize
(
function
()
{
self
.
currentQuery
=
undefined
;
db
.
driver
.
prepare
(
statement
.
tail
,
onPrepare
);
// if there are any queries queued, let them know it's safe to go
self
.
db
.
emit
(
"ready"
);
});
});
return
;
}
}
function
doStep
(
statement
)
{
statement
.
finalize
(
function
()
{
(
function
innerFunction
()
{
db
.
currentQuery
=
undefined
;
statement
.
step
(
function
(
error
,
row
)
{
// if there are any queries queued, let them know it's safe to go
if
(
error
)
throw
error
;
db
.
driver
.
emit
(
"ready"
);
if
(
!
row
)
{
});
// rows.rowsAffected = this.changes();
}
// rows.insertId = this.lastInsertRowid();
queryCallback
();
queryDone
(
statement
);
return
;
}
queryCallback
(
row
);
innerFunction
();
});
})();
}
function
onPrepare
(
error
,
statement
)
{
function
_doStep
(
db
,
statement
,
rowCallback
)
{
if
(
error
)
throw
error
;
(
function
innerFunction
()
{
if
(
bindings
)
{
statement
.
step
(
function
(
error
,
row
)
{
if
(
Object
.
prototype
.
toString
.
call
(
bindings
)
===
"[object Array]"
)
{
if
(
error
)
throw
error
;
doBindingsByIndex
(
statement
,
bindings
,
doStep
);
if
(
!
row
)
{
}
// rows.rowsAffected = this.changes();
else
{
// rows.insertId = this.lastInsertRowid();
// TODO index by keys
rowCallback
();
_queryDone
(
db
,
statement
);
return
;
}
}
rowCallback
(
row
);
innerFunction
();
});
})();
}
function
_onPrepare
(
db
,
error
,
statement
,
bindings
,
rowCallback
)
{
if
(
error
)
throw
error
;
if
(
Array
.
isArray
(
bindings
))
{
if
(
bindings
.
length
)
{
_setBindingsByIndex
(
db
,
statement
,
bindings
,
_doStep
,
rowCallback
);
}
}
else
{
else
{
doStep
(
statement
);
_doStep
(
db
,
statement
,
rowCallback
);
}
}
}
}
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
)
{
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