@ac-moore-inc/oracledb-wrapper 中文文档教程
OracleDb Wrapper
一个易于使用的 orabledb 包装器,具有分页和大结果支持。
由 AC Moore 软件工程团队创建和维护。
Methods
prepareService
为提供的数据库创建连接池连接
prepareService(config);
Parameters:
config: object
需要包含与数据库相关信息的配置对象。 它被prepareService和close
config Example:
{
databaseName: {
'connectString': 'dbconnect',
'poolMin': 4,
'poolMax': 200,
'poolIncrement': 4,
'poolTimeout': 60,
'user': 'db_user_name',
'password': 'db_pass',
'queueRequests': true,
'queueTimeout': 0
},
other db connections...
}
getConnection
使用如果连接被传递返回相同的连接,否则创建连接
getConnection(databaseOrConnection, callback);
Parameters:
databaseOrConnection:
将数据库名称作为字符串或现有连接传递
releaseConn
释放数据库连接
release(connection, info);
Parameters:
connection:
参考已建立的连接
info: string
调试信息,如果在释放连接时遇到任何错误将被记录
close
关闭数据库连接池
close(config, callback);
Parameters:
config:
查看 prepareService
selectQuery
对数据库执行选择查询
executeQuery(options, callback);
Parameters:
options: object
Field | Type | Required | Value |
---|---|---|---|
conn | database connection | true | database connection |
db | string | true | database name as defined in the config object used to prepare the service |
qrydata | object | false | object containing query data, details below |
flatQry | string | false | string defining the query to be executed |
bindvars | object or array | false | defines the bind variables for the query, details below |
outFormat | oracledb type | false | defines the outformat of the query. defaults to oracledb.OBJECT |
qrydata:
Field | Type | Required | Value |
---|---|---|---|
fields | string | true | fields to be retrieved in query |
from_objects | string | true | objects to be queried |
where_clause | string | false | additional criteria for query |
order_by | string | false | field or fields to order results by |
bindvars: object
Field | Type | Required | Value |
---|---|---|---|
val | value type | false | the value being used in the package call, omitted if value is out bound |
type | oracledb type | false | the oracledb type of the value, only required if value is vartype |
dir | oracledb.BINDIN/BINDOUT/BIND_INOUT | false | defines if value is in bound, out bound, or both |
bindvars object Example:
var bindvars = {
I_EMPLOYEE_ID: {
val: employeeId,
type: oracledb.NUMBER,
dir: oracledb.BIND_IN
},
O_ERROR_MESSAGE: {
type: oracledb.STRING,
dir: oracledb.BIND_OUT
},
v_Return: {
type: oracledb.NUMBER,
dir: oracledb.BIND_OUT
}
};
bindvars: array
如果绑定变量是简单值,它们可以是传入数组
bindvars array Example:
var iemployee_id = employeeId
var iemployee_name = employeeName
var bindvars = [iemployee_id., iemployee_name];
executePkg
执行包调用数据库
executePkg 也可以执行 select 和 update 语句。 与 selectQuery 不同,executePkg 未针对检索大型数据集进行优化。
executePkg(options, callback);
如果连接在选项变量中传递,则查询被视为事务的一部分,并且不会提交
如果连接未在选项变量中传递,则查询被视为独立查询,并且将有一个自动提交
Parameters:
options: object
Field | Type | Required | Value |
---|---|---|---|
conn | database connection | true | database connection |
db | string | true | database name as defined in the config object used to prepare the service |
qry | string | false | string defining the package call to be executed |
bindvars | object or array | false | defines the bind variables for the query, see executeQuery for exmaples |
buildBindVariables
构建绑定变量对象包话费。
buildBindVariables(inputStructure, input);
Parameters:
inputStructure: Array
Elements: [Field name, Type, Dir, Required(boolean)]
Types Mapping:
Symbol | Value |
---|---|
S | String |
N | Number |
D | Date |
Dirs Mapping:
Symbol | Value |
---|---|
I | BIND_IN |
O | BIND_OUT |
IO | BIND_INOUT |
inputStructure Example:
let inputStructure = [
['employee', 'S', 'I', true],
['salary', 'N', 'I', true],
['hire_date', 'D', 'I', false]
['entry_id', 'N', 'O'],
['error_message', 'S', 'O']
];
input: Object
输入对象属性名称必须与 inputStructure 中的字段名称匹配
input Example:
let input = {
employee: 'Sally Sales',
salary: 100000,
hire_date: '2017-03-17T17:47:08.000Z'
};
OracleDb Wrapper
An easy to use orabledb wrapper with pagination and large result support.
Created and maintained by the A.C. Moore software engineering team.
Methods
prepareService
Create the connection pools for provided databases
prepareService(config);
Parameters:
config: object
A configuration object containing information related to the database is required to connect. It is utilized by prepareService and close
config Example:
{
databaseName: {
'connectString': 'dbconnect',
'poolMin': 4,
'poolMax': 200,
'poolIncrement': 4,
'poolTimeout': 60,
'user': 'db_user_name',
'password': 'db_pass',
'queueRequests': true,
'queueTimeout': 0
},
other db connections...
}
getConnection
If connection is passed return same connection, otherwise create the connection
getConnection(databaseOrConnection, callback);
Parameters:
databaseOrConnection:
Pass the database name as a string or an existing connection
releaseConn
Releases the database connection
release(connection, info);
Parameters:
connection:
Reference to the established connection
info: string
Debugging information, will be logged if any error is encountered while releasing the connection
close
Closes the database connection pool
close(config, callback);
Parameters:
config:
See prepareService
selectQuery
Executes a select query to the database
executeQuery(options, callback);
Parameters:
options: object
Field | Type | Required | Value |
---|---|---|---|
conn | database connection | true | database connection |
db | string | true | database name as defined in the config object used to prepare the service |
qrydata | object | false | object containing query data, details below |
flatQry | string | false | string defining the query to be executed |
bindvars | object or array | false | defines the bind variables for the query, details below |
outFormat | oracledb type | false | defines the outformat of the query. defaults to oracledb.OBJECT |
qrydata:
Field | Type | Required | Value |
---|---|---|---|
fields | string | true | fields to be retrieved in query |
from_objects | string | true | objects to be queried |
where_clause | string | false | additional criteria for query |
order_by | string | false | field or fields to order results by |
bindvars: object
Field | Type | Required | Value |
---|---|---|---|
val | value type | false | the value being used in the package call, omitted if value is out bound |
type | oracledb type | false | the oracledb type of the value, only required if value is vartype |
dir | oracledb.BINDIN/BINDOUT/BIND_INOUT | false | defines if value is in bound, out bound, or both |
bindvars object Example:
var bindvars = {
I_EMPLOYEE_ID: {
val: employeeId,
type: oracledb.NUMBER,
dir: oracledb.BIND_IN
},
O_ERROR_MESSAGE: {
type: oracledb.STRING,
dir: oracledb.BIND_OUT
},
v_Return: {
type: oracledb.NUMBER,
dir: oracledb.BIND_OUT
}
};
bindvars: array
If the bind variables are simple values, they can be passed in an array
bindvars array Example:
var iemployee_id = employeeId
var iemployee_name = employeeName
var bindvars = [iemployee_id., iemployee_name];
executePkg
Executes a package call to the database
executePkg is also capible of executing select and update statements. Unlike selectQuery, executePkg is not optimized to retrieve large sets of data.
executePkg(options, callback);
If connection is passed in the options variable then query considered to be part of transaction and there will be no commit
If connection is not passed in the options variable then query considered to be a standalone query and there will be an autoCommit
Parameters:
options: object
Field | Type | Required | Value |
---|---|---|---|
conn | database connection | true | database connection |
db | string | true | database name as defined in the config object used to prepare the service |
qry | string | false | string defining the package call to be executed |
bindvars | object or array | false | defines the bind variables for the query, see executeQuery for exmaples |
buildBindVariables
Builds bind variables object for package calls.
buildBindVariables(inputStructure, input);
Parameters:
inputStructure: Array
Elements: [Field name, Type, Dir, Required(boolean)]
Types Mapping:
Symbol | Value |
---|---|
S | String |
N | Number |
D | Date |
Dirs Mapping:
Symbol | Value |
---|---|
I | BIND_IN |
O | BIND_OUT |
IO | BIND_INOUT |
inputStructure Example:
let inputStructure = [
['employee', 'S', 'I', true],
['salary', 'N', 'I', true],
['hire_date', 'D', 'I', false]
['entry_id', 'N', 'O'],
['error_message', 'S', 'O']
];
input: Object
The input object property names must match the field names in inputStructure
input Example:
let input = {
employee: 'Sally Sales',
salary: 100000,
hire_date: '2017-03-17T17:47:08.000Z'
};