@ac-moore-inc/oracledb-wrapper 中文文档教程

发布于 5年前 浏览 17 项目主页 更新于 3年前

OracleDb Wrapper

一个易于使用的 orabledb 包装器,具有分页和大结果支持。

由 AC Moore 软件工程团队创建和维护。

Methods

prepareService

为提供的数据库创建连接池连接

prepareService(config);

Parameters:

config: object

需要包含与数据库相关信息的配置对象。 它被prepareServiceclose

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
FieldTypeRequiredValue
conndatabase connectiontruedatabase connection
dbstringtruedatabase name as defined in the config object used to prepare the service
qrydataobjectfalseobject containing query data, details below
flatQrystringfalsestring defining the query to be executed
bindvarsobject or arrayfalsedefines the bind variables for the query, details below
outFormatoracledb typefalsedefines the outformat of the query. defaults to oracledb.OBJECT
qrydata:
FieldTypeRequiredValue
fieldsstringtruefields to be retrieved in query
from_objectsstringtrueobjects to be queried
where_clausestringfalseadditional criteria for query
order_bystringfalsefield or fields to order results by
bindvars: object
FieldTypeRequiredValue
valvalue typefalsethe value being used in the package call, omitted if value is out bound
typeoracledb typefalsethe oracledb type of the value, only required if value is vartype
diroracledb.BINDIN/BINDOUT/BIND_INOUTfalsedefines 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
FieldTypeRequiredValue
conndatabase connectiontruedatabase connection
dbstringtruedatabase name as defined in the config object used to prepare the service
qrystringfalsestring defining the package call to be executed
bindvarsobject or arrayfalsedefines 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:
SymbolValue
SString
NNumber
DDate
Dirs Mapping:
SymbolValue
IBIND_IN
OBIND_OUT
IOBIND_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
FieldTypeRequiredValue
conndatabase connectiontruedatabase connection
dbstringtruedatabase name as defined in the config object used to prepare the service
qrydataobjectfalseobject containing query data, details below
flatQrystringfalsestring defining the query to be executed
bindvarsobject or arrayfalsedefines the bind variables for the query, details below
outFormatoracledb typefalsedefines the outformat of the query. defaults to oracledb.OBJECT
qrydata:
FieldTypeRequiredValue
fieldsstringtruefields to be retrieved in query
from_objectsstringtrueobjects to be queried
where_clausestringfalseadditional criteria for query
order_bystringfalsefield or fields to order results by
bindvars: object
FieldTypeRequiredValue
valvalue typefalsethe value being used in the package call, omitted if value is out bound
typeoracledb typefalsethe oracledb type of the value, only required if value is vartype
diroracledb.BINDIN/BINDOUT/BIND_INOUTfalsedefines 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
FieldTypeRequiredValue
conndatabase connectiontruedatabase connection
dbstringtruedatabase name as defined in the config object used to prepare the service
qrystringfalsestring defining the package call to be executed
bindvarsobject or arrayfalsedefines 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:
SymbolValue
SString
NNumber
DDate
Dirs Mapping:
SymbolValue
IBIND_IN
OBIND_OUT
IOBIND_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'
};
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文