@jsh/db
Since v8.0.52Client
The database client.
Usage example
| |
Creation
| Constructor | Description |
|---|---|
| new Client(options) | Instantiates a database client object with an options |
If neither bridge nor driver is specified, the client defaults to connecting to the internal Machbase DBMS.
Options
| Option | Type | Default | Description |
|---|---|---|---|
| lowerCaseColumns | Boolean | false | map the lower-cased column names to the result object |
- Options for Drivers
driver and dataSource options support sqlite, mysql, mssql, postgresql and machbase without pre-defined bridge.
| Option | Type | Default | Description |
|---|---|---|---|
| driver | String | driver name | |
| dataSource | String | database connection string |
- Options for Bridge
It is also possible to create Client with predefined bridge.
| Option | Type | Default | Description |
|---|---|---|---|
| bridge | String | bridge name |
Properties
| Property | Type | Description |
|---|---|---|
| supportAppend | Boolean | true if the client supports “Append” mode. |
connect()
connect to the database.
Return value
ObjectConn
Conn
close()
disconnect to the database and release
Syntax
close()query()
Syntax
query(String *sqlText*, any ...*args*)Return value
ObjectRows
queryRow()
Syntax
queryRow(String *sqlText*, any ...*args*)Return value
ObjectRow
exec()
Syntax
exec(sqlText, ...args)Parameters
sqlTextStringSql text stringargsanyA variable-length list of arguments.
Return value
ObjectResult
appender()
Create new “appender”.
Syntax
appender(table_name, ...columns)Parameters
table_nameStringThe table name of to append.columnsStringA variable-length list of column names. Ifcolumnsis omitted, all columns of the table will be appended in order.
Return value
ObjectAppender
Rows
Rows encapsulates the result set obtained from executing a query.
It implements Symbol.iterable, enabling support for both patterns:
for(rec := rows.next(); rec != null; rec = rows.next()) {
console.log(...rec);
}
for (rec of rows) {
console.log(...rec);
}close()
Release database statement
Syntax
close()Parameters
None.
Return value
None.
next()
fetch a record, returns null if no more records
Syntax
next()Parameters
None.
Return value
any[]
columns()
Syntax
columns()Parameters
None.
Return value
ObjectColumns
columnNames()
Syntax
columnNames()Parameters
None.
Return value
String[]
columnTypes()
Syntax
columnTypes()Parameters
None.
Return value
String[]
Row
Row encapsulates the result of queryRow which retrieve a single record.
columns()
Syntax
columns()Parameters
None.
Return value
ObjectColumns
columnNames()
names of the result
Syntax
columnNames()Parameters
None.
Return value
String[]
columnTypes()
types of the result
Syntax
columnTypes()Parameters
None.
Return value
String[]
values()
result columns
Syntax
values()Parameters
None.
Return value
any[]
Result
Result represents the outcome of the exec() method, providing details about the execution.
Properties
| Property | Type | Description |
|---|---|---|
| message | String | result message |
| rowsAffected | Number |
Columns
Properties
| Property | Type | Description |
|---|---|---|
| columns | String[] | names of the result |
| types | String[] | types of the result |
Appender
append()
Invoke the append method with the specified values in the order of the columns.
Syntax
append(...values)Parameters
valuesanyThe values to be appended to the table, provided in the order of the specified columns.
Return value
None.
close()
Close the appender.
Syntax
close()Parameters
None.
Return value
None.
result()
Returns the result of the append operation after the appender is closed.
Syntax
result()Parameters
None.
Return value
Object
| Property | Type | Description |
|---|---|---|
| success | Number | |
| faile | Number |