Forked from xdenser/node-firebird-libfbclient.js
Last active
August 29, 2015 14:04
-
-
Save mariuz/2749cc88678def631b6c to your computer and use it in GitHub Desktop.
node-firebird vs node-firebird-libfbclient
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cfg = require("./config").cfg; | |
var fb = require('firebird'); | |
var util = require('util'); | |
var events = require('events'); | |
var http = require('http'); | |
var con = fb.createConnection(); | |
con.connectSync(cfg.db, cfg.user, cfg.password, cfg.role); | |
http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
function doTr(){ | |
if(!con.inTransaction){ | |
con.startTransaction(doTr); | |
return; | |
} | |
con.query('select * from test',function(err,rs){ | |
var rows = rs.fetchSync("all",false); | |
con.commit(); | |
res.write('['); | |
rows.forEach(function(r){ | |
res.write(JSON.stringify(r)+','); | |
}); | |
res.end(']'); | |
}); | |
} | |
doTr(); | |
}).listen(1337, "127.0.0.1"); | |
console.log('Server running at http://127.0.0.1:1337/'); | |
process.on('exit',function(){ | |
con.disconnect(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cfg = require("./config").cfg; | |
var fb = require('node-firebird'); | |
var util = require('util'); | |
var events = require('events'); | |
var http = require('http'); | |
var con = new fb.Database('127.0.0.1', 3050, cfg.db, cfg.user, cfg.password, | |
function(){ | |
http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
function doReq(){ | |
con.execute("select * from test", function(rs){ | |
res.write('['); | |
rs.data.forEach(function(r){ | |
res.write(JSON.stringify(r)+','); | |
}); | |
res.end(']'); | |
},function(err){ console.log(err);}); | |
} | |
doReq(); | |
}).listen(1337, "127.0.0.1"); | |
console.log('Server running at http://127.0.0.1:1337/'); | |
}); | |
process.on('exit',function(){ | |
con.detach(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment