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
c6a6aa1e
Commit
c6a6aa1e
authored
Jul 14, 2014
by
Dane Springmeyer
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #314 from KidsKilla/master
rm errorCallback, add normalizeMethod
parents
11b4a620
1b0494d8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
56 deletions
+56
-56
.gitignore
.gitignore
+2
-2
sqlite3.js
lib/sqlite3.js
+54
-54
No files found.
.gitignore
View file @
c6a6aa1e
...
...
@@ -18,4 +18,5 @@ npm-debug.log
test/support/big.db
test/tmp
test/nw/app.nw
.DS_Store
\ No newline at end of file
.DS_Store
.idea
lib/sqlite3.js
View file @
c6a6aa1e
var
path
=
require
(
'path'
);
var
binary
=
require
(
'node-pre-gyp'
);
var
path
=
require
(
'path'
)
var
path
=
require
(
'path'
)
;
var
binding_path
=
binary
.
find
(
path
.
resolve
(
path
.
join
(
__dirname
,
'../package.json'
)));
var
binding
=
require
(
binding_path
);
var
sqlite3
=
module
.
exports
=
exports
=
binding
;
var
util
=
require
(
'util'
);
var
EventEmitter
=
require
(
'events'
).
EventEmitter
;
function
errorCallback
(
args
)
{
if
(
typeof
args
[
args
.
length
-
1
]
===
'function'
)
{
var
callback
=
args
[
args
.
length
-
1
];
return
function
(
err
)
{
if
(
err
)
callback
(
err
);
};
function
normalizeMethod
(
fn
)
{
return
function
(
sql
)
{
var
errBack
;
var
args
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
);
if
(
typeof
args
[
args
.
length
-
1
]
===
'function'
)
{
var
callback
=
args
[
args
.
length
-
1
];
errBack
=
function
(
err
)
{
if
(
err
)
{
callback
(
err
);
}
};
}
var
statement
=
new
Statement
(
this
,
sql
,
errBack
);
return
fn
.
call
(
this
,
statement
,
args
);
}
}
...
...
@@ -55,56 +63,40 @@ inherits(Database, EventEmitter);
inherits
(
Statement
,
EventEmitter
);
// Database#prepare(sql, [bind1, bind2, ...], [callback])
Database
.
prototype
.
prepare
=
function
(
sql
)
{
var
params
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
);
if
(
!
params
.
length
||
(
params
.
length
===
1
&&
typeof
params
[
0
]
===
'function'
))
{
return
new
Statement
(
this
,
sql
,
params
[
0
]);
}
else
{
var
statement
=
new
Statement
(
this
,
sql
,
errorCallback
(
params
));
return
statement
.
bind
.
apply
(
statement
,
params
);
}
};
Database
.
prototype
.
prepare
=
normalizeMethod
(
function
(
statement
,
params
)
{
return
params
.
length
?
statement
.
bind
.
apply
(
statement
,
params
)
:
statement
;
});
// Database#run(sql, [bind1, bind2, ...], [callback])
Database
.
prototype
.
run
=
function
(
sql
)
{
var
params
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
);
var
statement
=
new
Statement
(
this
,
sql
,
errorCallback
(
params
));
Database
.
prototype
.
run
=
normalizeMethod
(
function
(
statement
,
params
)
{
statement
.
run
.
apply
(
statement
,
params
).
finalize
();
return
this
;
};
}
)
;
// Database#get(sql, [bind1, bind2, ...], [callback])
Database
.
prototype
.
get
=
function
(
sql
)
{
var
params
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
);
var
statement
=
new
Statement
(
this
,
sql
,
errorCallback
(
params
));
Database
.
prototype
.
get
=
normalizeMethod
(
function
(
statement
,
params
)
{
statement
.
get
.
apply
(
statement
,
params
).
finalize
();
return
this
;
};
}
)
;
// Database#all(sql, [bind1, bind2, ...], [callback])
Database
.
prototype
.
all
=
function
(
sql
)
{
var
params
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
);
var
statement
=
new
Statement
(
this
,
sql
,
errorCallback
(
params
));
Database
.
prototype
.
all
=
normalizeMethod
(
function
(
statement
,
params
)
{
statement
.
all
.
apply
(
statement
,
params
).
finalize
();
return
this
;
};
}
)
;
// Database#each(sql, [bind1, bind2, ...], [callback], [complete])
Database
.
prototype
.
each
=
function
(
sql
)
{
var
params
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
);
var
statement
=
new
Statement
(
this
,
sql
,
errorCallback
(
params
));
Database
.
prototype
.
each
=
normalizeMethod
(
function
(
statement
,
params
)
{
statement
.
each
.
apply
(
statement
,
params
).
finalize
();
return
this
;
};
}
)
;
Database
.
prototype
.
map
=
function
(
sql
)
{
var
params
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
);
var
statement
=
new
Statement
(
this
,
sql
,
errorCallback
(
params
));
Database
.
prototype
.
map
=
normalizeMethod
(
function
(
statement
,
params
)
{
statement
.
map
.
apply
(
statement
,
params
).
finalize
();
return
this
;
};
}
)
;
Statement
.
prototype
.
map
=
function
()
{
var
params
=
Array
.
prototype
.
slice
.
call
(
arguments
);
...
...
@@ -164,22 +156,30 @@ Database.prototype.removeAllListeners = function(type) {
sqlite3
.
verbose
=
function
()
{
if
(
!
isVerbose
)
{
var
trace
=
require
(
'./trace'
);
trace
.
extendTrace
(
Database
.
prototype
,
'prepare'
);
trace
.
extendTrace
(
Database
.
prototype
,
'get'
);
trace
.
extendTrace
(
Database
.
prototype
,
'run'
);
trace
.
extendTrace
(
Database
.
prototype
,
'all'
);
trace
.
extendTrace
(
Database
.
prototype
,
'each'
);
trace
.
extendTrace
(
Database
.
prototype
,
'map'
);
trace
.
extendTrace
(
Database
.
prototype
,
'exec'
);
trace
.
extendTrace
(
Database
.
prototype
,
'close'
);
trace
.
extendTrace
(
Statement
.
prototype
,
'bind'
);
trace
.
extendTrace
(
Statement
.
prototype
,
'get'
);
trace
.
extendTrace
(
Statement
.
prototype
,
'run'
);
trace
.
extendTrace
(
Statement
.
prototype
,
'all'
);
trace
.
extendTrace
(
Statement
.
prototype
,
'each'
);
trace
.
extendTrace
(
Statement
.
prototype
,
'map'
);
trace
.
extendTrace
(
Statement
.
prototype
,
'reset'
);
trace
.
extendTrace
(
Statement
.
prototype
,
'finalize'
);
[
'prepare'
,
'get'
,
'run'
,
'all'
,
'each'
,
'map'
,
'close'
,
'exec'
].
forEach
(
function
(
name
)
{
trace
.
extendTrace
(
Database
.
prototype
,
name
);
});
[
'bind'
,
'get'
,
'run'
,
'all'
,
'each'
,
'map'
,
'reset'
,
'finalize'
,
].
forEach
(
function
(
name
)
{
trace
.
extendTrace
(
Statement
.
prototype
,
name
);
});
isVerbose
=
true
;
}
...
...
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