sagiegurari / simple-oracledb

Extend capabilities of oracledb with simplified API for quicker development.
Apache License 2.0
36 stars 4 forks source link

take clue from pg-promise for promise support #14

Closed volkmarbuehringer closed 7 years ago

volkmarbuehringer commented 8 years ago

this could be done similiar in pool.run:

db.task(function (t) { // this = t = task protocol context; // this.ctx = task config + state context; return t.one("select * from users where id=$1", 123) .then(function (user) { return t.any("select * from events where login=$1", user.name); }); }) .then(function (events) { // success; }) .catch(function (error) { console.log("ERROR:", error.message || error);
});


#### Error Stack/Info (if any)
sagiegurari commented 8 years ago

not sure I follow, sorry. can you explain a bit more?

volkmarbuehringer commented 8 years ago

pool.run( (connection)=>connection.query("select * from dual" )) .then((res)=>connection.query("select * from another",[res])) ) .then( (res) => console.log("endresult is",res ) ) .catch( (err) =>console.error("error",err) ) ;

also for transactions, there could be an array of promise returning functions,which are resolved sequentially or in parallel

in pg-promise are also other functions which might be useful in simple-oracledb

sagiegurari commented 8 years ago

ok got you. I'll think about it. For now I'm keeping it open and I'll consider it.

sagiegurari commented 7 years ago

Took me forever and I kept going back and think about this one. Anyhow, I implemented it currently for the pool.run so now the function can return a promise as shown below and I think it is what you were looking for. I might start also look at connection.run and connection.transaction as well. Please tell me what you think about it

//extended promise support (action is returning a promise instead of using the callback)
pool.run(function (connection) {
  //run some query and the output will be available in the 'run' promise 'then'
  return connection.query('SELECT department_id, department_name FROM departments WHERE manager_id < :id', [110]); //no need for a callback, instead return a promise
}).then(function onActionDone(result) {
  //do something with the result
});
sagiegurari commented 7 years ago

closing this one. I will try to see if connection.run and connection.transaction can also be modified. if you have more suggestions please open in a new issue.

volkmarbuehringer commented 7 years ago

Trank YouTube very much Tested run and parallel with promises

Von meinem Samsung Galaxy Smartphone gesendet.

-------- Ursprüngliche Nachricht -------- Von: Sagie Gur-Ari notifications@github.com Datum: 17.01.17 23:40 (GMT+01:00) An: sagiegurari/simple-oracledb simple-oracledb@noreply.github.com Cc: Volkmar Bühringer Volkmar.Buehringer@prounix.de, Author author@noreply.github.com Betreff: Re: [sagiegurari/simple-oracledb] take clue from pg-promise for promise support (#14)

closing this one. I will try to see if connection.run and connection.transaction can also be modified. if you have more suggestions please open in a new issue.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/sagiegurari/simple-oracledb/issues/14#issuecomment-273323591, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AKI8bCIKaZTEsSwyY4LxgyPiwLLzPQ33ks5rTUMWgaJpZM4JvzZB.

Prounix Gesellschaft für Softwareentwicklung mbH - Geschäftsführer: Andreas Decker - Handelsregister: Amtsgericht Bonn HRB 5855 - Sitz der Gesellschaft: Bonn

sagiegurari commented 7 years ago

also updated oracledb.run, connection.run and connection.transaction. all action/s provided can return a promise instead of using a callback.