I've got a basic Node webserver (Koa.js + a ORM). I like to start it with a REPL meaning I can use my app like a CLI-tool.
All my queries return Promises but I don't know how I can resolve them in the REPL. How can I resolve them?
For example the following code (fetch() queries the database and returns a promise) gives only this output Promise {_bitField: 4325376, _fulfillmentHandler0: undefined, _rejectionHandler0: undefined …}
Transaction.where('reference', '1').fetch().then((res) => return res)
Old answer:
You can't resolve them proper - but you can extract their references to the global scope:
> Transaction.where('reference', '1').fetch().then((res) => out = res)
[Object Promise]
> out
/* your data outputted here since the global was assigned to*/
We might allow await
in the REPL in the future in Node which would solve the issue more cleanly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With