I prefer knexjs because of simplicity and the amount of features it 
supports. Also allows for neater code, in the sense that it's a lot easier 
to read.

For instance I've made an external JS file included in most of my routes 
that load data from the database. I simply call a function load(tableName) 
and that JS file will find a connection, parse all the req.params / 
req.query properties and add them to the whereclause, including other 
things as well like limit/offset/orderby/etc. All done in less than ~30 
lines of code, which is great.

Den tisdagen den 25:e november 2014 kl. 16:25:05 UTC+1 skrev John:
>
> Any reason not using pg-native?
>
> Sent from my LG Mobile
>
> Alex Spencer <[email protected] <javascript:>> wrote:
>
> >Hey.
> >
> >Need some advice on an api application built using:
> >- express
> >- knexjs
> >- postgres
> >
> >My question is if im handling database operations correctly or if im 
> doing 
> >it completely wrong.. See example
> >
> >var knex = require('knex');
> >app.get('/example/:param',
> >loadWithParam(),
> >updateWithParam(),
> >render.staticOK()
> >
> >function loadWithParam() {
> >return function(req, res, next) {
> >var db = knex({conConfig});
> >db(tableName).where(field, req.params.param).select().then(function(rows) 
> {
> >db.destroy(function() {
> >res.locals[tableName] = rows;
> >next();
> >});
> >}).catch(function(err) {
> >...
> >});
> >};
> >}
> >
> >function updateWithParam() {
> >return function(req, res, next) {
> >if(res.locals[tableName].length === 0) {
> >return next();
> >}
> >var db = knex({conConfig});
> >db(tableName).where(field, req.params.param).update({field: value}).then(
> >function() {
> >db.destroy(function() {
> >next();
> >});
> >}).catch(function(err) {
> >...
> >});
> >};
> >}
> >
> >
> >In short my question is if its good or bad practise opening up and 
> closing 
> >database connections per operation required to run? Ive been told setting 
> >up a database connection on res.locals upon receiving a request is 
> better, 
> >but i disagree..
> >
> >Thanks
> >
> >-- 
> >Job board: http://jobs.nodejs.org/
> >New group rules: 
> https://gist.github.com/othiym23/9886289#file-moderation-policy-md
> >Old group rules: 
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> >--- 
> >You received this message because you are subscribed to the Google Groups 
> "nodejs" group.
> >To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] <javascript:>.
> >To post to this group, send email to [email protected] 
> <javascript:>.
> >To view this discussion on the web visit 
> https://groups.google.com/d/msgid/nodejs/408d3fd6-dd6c-4621-9030-99ff2e3fe7d6%40googlegroups.com
> .
> >For more options, visit https://groups.google.com/d/optout.
>
>

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/b32b4c7c-bdf4-40f3-9f5b-9894618de944%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to