Skip to content

Commit

Permalink
path.sep now works in node 0.6 too
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Giammarchi committed Aug 27, 2013
1 parent 51499e6 commit 12e2046
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 26 deletions.
10 changes: 0 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,7 @@ amd:

bench:
echo ''
node benchmark/sqlite3.js 1
node benchmark/sqlite3.js
node benchmark/sqlite3.js
node benchmark/sqlite3.js
node benchmark/sqlite3.js 1
node benchmark/dblite.js 1
node benchmark/dblite.js
node benchmark/dblite.js
node benchmark/dblite.js
node benchmark/dblite.js 1
rm bench.sqlite3.db
rm bench.dblite.db


Expand Down
2 changes: 1 addition & 1 deletion benchmark/dblite.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var startTime = Date.now(),
db = require('../build/dblite.node.js')('./bench.dblite.db');
//db = require('../build/dblite.node.js')(':memory:');
// db = require('../build/dblite.node.js')(':memory:');

db.query('BEGIN');
db.query('CREATE TABLE IF NOT EXISTS users_login (id INTEGER PRIMARY KEY, name TEXT, pass TEXT)');
Expand Down
22 changes: 14 additions & 8 deletions build/dblite.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ var
path = require('path'),
// each dblite(fileName) instance is an EventEmitter
EventEmitter = require('events').EventEmitter,
// used to perform some fallback
WIN32 = process.platform === 'win32',
// what kind of Path Separator we have here ?
PATH_SEP = path.sep || (
WIN32 ? '\\' : '/'
),
// what kind of End Of Line we have here ?
EOL = require('os').EOL || (
process.platform === 'win32' ? '\r\n' : '\n'
WIN32 ? '\r\n' : '\n'
),
// what's EOL length? Used to properly parse data
EOL_LENGTH = EOL.length,
Expand Down Expand Up @@ -137,7 +143,7 @@ function dblite() {
// the "spawned once" program, will be used for the whole session
program = spawn(
// executable only, folder needs to be specified a part
bin.length === 1 ? bin[0] : ('.' + path.sep + bin[bin.length - 1]),
bin.length === 1 ? bin[0] : ('.' + PATH_SEP + bin[bin.length - 1]),
// normalize file path if not :memory:
normalizeFirstArgument(
// it is possible to eventually send extra sqlite3 args
Expand All @@ -147,7 +153,7 @@ function dblite() {
// be sure the dir is the right one
{
// the right folder is important or sqlite3 won't work
cwd: bin.slice(0, -1).join(path.sep) || process.cwd(),
cwd: bin.slice(0, -1).join(PATH_SEP) || process.cwd(),
env: process.env, // same env is OK
encoding: 'utf8', // utf8 is OK
detached: true, // asynchronous
Expand Down Expand Up @@ -328,7 +334,7 @@ function dblite() {
// it does not make sense to execute anything after
// the program is being closed
if (notWorking) return onerror('closing'), self;
// if something is still going on in the sqlite3 sheel
// if something is still going on in the sqlite3 shell
// the progcess is flagged as busy. Just queue other operations
if (busy) return queue.push(arguments);
// if a SELECT or a PRAGMA ...
Expand Down Expand Up @@ -406,7 +412,7 @@ function dblite() {
sanitize(string) + 'SELECT ' + SUPER_SECRET_SELECT
);
} else {
// if db.plain() was used but this is not an error
// if db.plain() was used but this is not a SELECT or PRAGMA
// something is wrong with the logic since no result
// was expected anyhow
if (dontParseCSV) {
Expand Down Expand Up @@ -659,10 +665,10 @@ Object.defineProperty(
{
get: function () {
// normalized string if was a path
return bin.join(path.sep);
return bin.join(PATH_SEP);
},
set: function (value) {
var isPath = -1 < value.indexOf(path.sep);
var isPath = -1 < value.indexOf(PATH_SEP);
if (isPath) {
// resolve the path
value = path.resolve(value);
Expand All @@ -672,7 +678,7 @@ Object.defineProperty(
}
}
// assign as Array in any case
bin = value.split(path.sep);
bin = value.split(PATH_SEP);
}
}
);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.2.6",
"version": "0.2.7",
"engine": "node >= 0.6.0",
"name": "dblite",
"description": "a zero hassle wrapper for sqlite",
Expand Down
18 changes: 12 additions & 6 deletions src/dblite.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ var
path = require('path'),
// each dblite(fileName) instance is an EventEmitter
EventEmitter = require('events').EventEmitter,
// used to perform some fallback
WIN32 = process.platform === 'win32',
// what kind of Path Separator we have here ?
PATH_SEP = path.sep || (
WIN32 ? '\\' : '/'
),
// what kind of End Of Line we have here ?
EOL = require('os').EOL || (
process.platform === 'win32' ? '\r\n' : '\n'
WIN32 ? '\r\n' : '\n'
),
// what's EOL length? Used to properly parse data
EOL_LENGTH = EOL.length,
Expand Down Expand Up @@ -115,7 +121,7 @@ function dblite() {
// the "spawned once" program, will be used for the whole session
program = spawn(
// executable only, folder needs to be specified a part
bin.length === 1 ? bin[0] : ('.' + path.sep + bin[bin.length - 1]),
bin.length === 1 ? bin[0] : ('.' + PATH_SEP + bin[bin.length - 1]),
// normalize file path if not :memory:
normalizeFirstArgument(
// it is possible to eventually send extra sqlite3 args
Expand All @@ -125,7 +131,7 @@ function dblite() {
// be sure the dir is the right one
{
// the right folder is important or sqlite3 won't work
cwd: bin.slice(0, -1).join(path.sep) || process.cwd(),
cwd: bin.slice(0, -1).join(PATH_SEP) || process.cwd(),
env: process.env, // same env is OK
encoding: 'utf8', // utf8 is OK
detached: true, // asynchronous
Expand Down Expand Up @@ -637,10 +643,10 @@ Object.defineProperty(
{
get: function () {
// normalized string if was a path
return bin.join(path.sep);
return bin.join(PATH_SEP);
},
set: function (value) {
var isPath = -1 < value.indexOf(path.sep);
var isPath = -1 < value.indexOf(PATH_SEP);
if (isPath) {
// resolve the path
value = path.resolve(value);
Expand All @@ -650,7 +656,7 @@ Object.defineProperty(
}
}
// assign as Array in any case
bin = value.split(path.sep);
bin = value.split(PATH_SEP);
}
}
);
Expand Down

0 comments on commit 12e2046

Please sign in to comment.