@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 |
Using Drivers shows the examples how to connect to the databases with driver and dataSource.
Option | Type | Default | Description |
---|
driver | String | | driver name |
dataSource | String | | database connection string |
It is also possible to create Client with predefined bridge.
Option | Type | Default | Description |
---|
bridge | String | | bridge name |
Methods
Method | Returns | Description |
---|
connect() | Conn | connect to the database |
Conn
Methods
Method | Returns | Description |
---|
close() | | disconnect to the database and release |
query(String sqlText, any …args) | Rows | |
exec(String sqlText, any …args) | Result | |
Rows
Rows encapsulates the result set obtained from executing a query.
Methods
Method | Returns | Description |
---|
close() | | release database statement |
next() | any[] | fetch a record, returns null if no more records |
columns() | Columns | |
columnNames() | String[] | names of the result |
columnTypes() | String[] | types of the result |
It implements Symbol.iterable
, enabling support for both patterns:
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 |
Using Drivers
@jsh/db
module supports sqlite
, mysql
, mssql
, postgresql
and machbase
without pre-defined bridge.
Machbase
This example demonstrates how to connect to another Machbase instance via port 5656 and execute a query.
Set lowerCaseColumns: true
at line 5 to ensure that the query results use lower-cased property names in the record object, as demonstrated at line 17.
SQLite