@onzag/itemize / Modules / database / DatabaseConnection
database.DatabaseConnection
The database connection class that creates a database conection and executes queries it is designed to exist as a single instance and execute transactions
- forceLogging
- getAlterTableBuilder
- getClient
- getCreateTableBuilder
- getInsertBuilder
- getPool
- getSelectBuilder
- getUpdateBuilder
- query
- queryFirst
- queryRows
- startSingleClientOperation
- startTransaction
- suppressLogging
• new DatabaseConnection(info, client?, pool?): DatabaseConnection
Constructs a new database connection
| Name | Type | Description |
|---|---|---|
info |
IDatbaseConnectionInfo |
the connection information |
client? |
PoolClient |
for child database connections used in transactions the client that is in use |
pool? |
Pool |
for child database connections used in transactions the pool that generated this from |
• Private client: PoolClient
A client that is taken from the pool, normally this will be undefined unless specified in the constructor for child connections used for transactions
• Private forceLogs: boolean
Forces the logging even if env is not development
• Private pool: Pool
This is the pg pool
• Private suppressLogs: boolean
Suppresses console logging
▸ forceLogging(): void
Forces console logging even if env is not development
void
▸ getAlterTableBuilder(): AlterTableBuilder
Provides a single alter table builder
a new alter table builder
▸ getClient(): PoolClient
Provides the current active pg client, only really existant on transactions
PoolClient
the client
▸ getCreateTableBuilder(): CreateTableBuilder
Provides a single create table builder
a new create table builder
▸ getInsertBuilder(): InsertBuilder
Provides a single insert builder
a new insert builder
▸ getPool(): Pool
Provides the current active pg pool
Pool
the pool
▸ getSelectBuilder(): SelectBuilder
Provides a single select builder
a new select builder
▸ getUpdateBuilder(): UpdateBuilder
Provides a single update builder
a new update builder
▸ query(what, bindings?, useHoles?): Promise<QueryResult<any>>
Performs a query against the database and returns a query result
| Name | Type | Description |
|---|---|---|
what |
string | QueryBuilder |
what to execute, either a raw string or a query from a builder |
bindings? |
BasicBindingType[] |
the bindings to use, you should not specify them when using a builder as initial argument as they will not be used |
useHoles? |
boolean |
- |
Promise<QueryResult<any>>
a promise of a query result
▸ queryFirst(what, bindings?, useHoles?): Promise<any>
Performs a query against the database and returns only the first row
| Name | Type | Description |
|---|---|---|
what |
string | QueryBuilder |
what to execute, either a raw string or a query from a builder |
bindings? |
BasicBindingType[] |
the bindings to use, you should not specify them when using a builder as initial argument as they will not be used |
useHoles? |
boolean |
- |
Promise<any>
a promise of a single row
▸ queryRows(what, bindings?, useHoles?): Promise<any[]>
Performs a query against the database and returns only the rows
| Name | Type | Description |
|---|---|---|
what |
string | QueryBuilder |
what to execute, either a raw string or a query from a builder |
bindings? |
BasicBindingType[] |
the bindings to use, you should not specify them when using a builder as initial argument as they will not be used |
useHoles? |
boolean |
- |
Promise<any[]>
a promise of a list of rows
▸ startSingleClientOperation(arg): Promise<any>
Starts a single client operation without starting a transaction so whatever happens here cannot be rolled back nor commited
DO NOT USE for changes in the DB because they will be executed immediately USE for select cursors that are using WITH HOLD as they persist within a single client
| Name | Type |
|---|---|
arg |
(transactingClient: DatabaseConnection) => Promise<any> |
Promise<any>
▸ startTransaction(arg, options?): Promise<any>
Starts a transaction, while handling rollbacks and everything if provided a client to already use in the transaction it will not be auto-released all changes are automatically rolled back
| Name | Type | Description |
|---|---|---|
arg |
(transactingClient: DatabaseConnection) => Promise<any> |
a function that returns anything and handles the transacting client |
options |
Object |
- |
options.noAutoCommit? |
boolean |
- |
options.noAutoRollback? |
boolean |
- |
options.noBegin? |
boolean |
- |
options.useClient? |
DatabaseConnection |
- |
Promise<any>
whatever you returned in your arg function
▸ suppressLogging(): void
Suppresses console logging
void