sagiegurari / simple-oracledb

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

Error: Callback not provided #25

Closed jay-jlm closed 6 years ago

jay-jlm commented 6 years ago

Trying to convert some existing code to use promises instead of callbacks. Got the following error:

Connection failed - Error: Callback not provided.

Code:

const oracledb = require('oracledb')
const SimpleOracleDB = require('simple-oracledb')

SimpleOracleDB.extend(oracledb)
const onConnectError = error => logger.error(`Connection failed - ${error}`)
const onQueryError = error => logger.error(`Query failed - ${error}`)
const onQueryResult = results => {
  console.log(`Rows received: ${results.length}`)
}

exports.execQuery = () => oracledb.getConnection(connectionConfig)
  .then(connection => {
    connection.query(createQuery(), [], {
      splitResults: true,
      bulkRowsAmount: 50,
    })
      .then(onQueryResult)
      .catch(onQueryError)
  })
  .catch(onConnectError)
sagiegurari commented 6 years ago

splitResults does not support callback. reason is that with splitResults, your callback is called multiple times, each time with another bulk set of results. In promises, you can't call the then multiple times.

jay-jlm commented 6 years ago

Thank you. So both the getConnection() and the query() methods will not work with promises or just the query one? Maybe make this limitation more explicit in the Readme page?

sagiegurari commented 6 years ago

just the query. the split option is only gor query. I'll update the docs to be more clear

jay-jlm commented 6 years ago

Thanks, I suggest put this info in the information in the method documentation, I guess there's where ppl will look if they have the same problem I did.

sagiegurari commented 6 years ago

It was already documented in the js docs: https://github.com/sagiegurari/simple-oracledb/blob/master/docs/api.md#connectionquerysql-bindparams-options-callback--resultsetreadstream--promise

but i added to the example in the main readme as well.