![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
@zarcobox/oracle-object
Advanced tools
Turns oracledb execute result into javascript objects
Oracle's npm module oracledb
returns an atypical response in which columns are displayed as a meta-data object separate from the rows. This module helps programmers by turning those into more natural key-valued javascript objects.
The latest version is available at: https://www.npmjs.com/package/@zarcobox/oracle-object
Use your favorite package manager to install. For instance:
yarn add @zarcobox/oracle-object
Then import it:
import oracle-object from '@zarcobox/oracle-object'
Or, for commonjs:
const oracle-object = require('@zarcobox/oracle-object')
And you're good to go!
oracleObject(result, fn, options)
The function receives the result of an execution as the first parameter. This is the only required parameter.
Here's an exemple of an SQL execution with oracledb:
// ...
const result = await connection.execute(
`SELECT manager_id, department_id, department_name
FROM departments
WHERE manager_id = :id`,
[23],
)
This is an example of a normal result from oracledb
:
const result = {
metaData: [
{ name: 'manager_id' },
{ name: 'department_id'},
{ name: 'department_name'}
],
rows: [
['23', '3842', 'Finances'],
['23', '3984', 'Sales'],
// ...
]
}
The simplest usage of oracle-object
would be:
oracleObject(result)
Which returns:
[
{
manager_id: '23',
department_id: '3842',
department_name: 'Finances'
},
{
manager_id: '23',
department_id: '3984',
department_name: 'Sales'
}
]
The second argument is an optional function or an object which receives each column and modifies it. In the example below the function makes the object keys have the same name as the columns but lower cased.
const registers = oracleObject(result, col => col.toLowerCase())
Or, given an example result where CD_PATIENT and DS_NAME are actual database columns, if you want to modify the name of each column you could do:
const patients = oracleObject(result, (col) => {
switch(col) {
case 'CD_PATIENT': return 'code'
case 'DS_NAME': return 'name'
default: return col
}
}, { allowNull: true })
An equivalent would be:
const patients = oracleObject(result, {
'CD_PATIENT': 'code'
'DS_NAME': 'name'
}
}, { allowNull: true, defaultFn: col => col })
And the returned object will look like this:
patients = [
{
code: '129831',
name: 'Luiz Felipe'
// ...
},
{
code: '129831',
name: 'Larissa',
// ...
},
]
Note: the default return ensures the function does not limit the object keys to the ones in the cases.
const options = { defaultFn: col => 'not-defined-'+col }
const patients = oracleObject(result, {
'CD_PATIENT': 'code',
'DS_NAME': 'name'
}, options)
The third parameter of oracle-object
receives an options object.
The option allowNull: false
is set by default. If you want all props do not forget to add that option.
The option defaultFn
can be set when using objects instead of functions to apply that function to not specified (or default) column names.
Run the test suit with yarn test
.
If you want to contribute in any of theses ways:
You can (and should) open an issue or even a pull request!
Thanks for your interest in contributing to this repo!
Luiz Felipe Zarco (felipezarco@hotmail.com)
This code is licensed under the MIT License. See the LICENSE.md file for more info.
FAQs
Turns oracledb execute result into javascript objects
The npm package @zarcobox/oracle-object receives a total of 3 weekly downloads. As such, @zarcobox/oracle-object popularity was classified as not popular.
We found that @zarcobox/oracle-object demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.