node-oracledb/examples/metadata.js

72 lines
1.9 KiB
JavaScript
Raw Normal View History

/* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. */
2016-12-01 18:25:44 +08:00
/******************************************************************************
*
* You may not use the identified files except in compliance with the Apache
* License, Version 2.0 (the "License.")
*
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
* NAME
* metadata.js
*
* DESCRIPTION
* Shows default and extended query column metadata
* Uses Oracle's sample HR schema.
*
* Scripts to create the HR schema can be found at:
* https://github.com/oracle/db-sample-schemas
*
* This example requires node-oracledb 1.10 or later.
*
* This example uses Node 8's async/await syntax.
*
*****************************************************************************/
2016-12-01 18:25:44 +08:00
var oracledb = require('oracledb');
var dbConfig = require('./dbconfig.js');
async function run() {
2016-12-01 18:25:44 +08:00
let connection;
2016-12-01 18:25:44 +08:00
try {
connection = await oracledb.getConnection(dbConfig);
console.log('Default query metadata');
let result = await connection.execute(
`SELECT location_id, city
FROM locations`);
console.log(result.metaData);
console.log('Extended query metadata');
result = await connection.execute(
`SELECT location_id, city
FROM locations`,
{}, // no binds
{ extendedMetaData: true }); // enable the extra metadata
console.log(result.metaData);
2016-12-01 18:25:44 +08:00
} catch (err) {
console.error(err);
} finally {
if (connection) {
try {
await connection.close();
} catch (err) {
console.error(err);
2016-12-01 18:25:44 +08:00
}
}
}
}
2016-12-01 18:25:44 +08:00
run();