Skip to content

Latest commit

 

History

History
408 lines (230 loc) · 10.1 KB

File metadata and controls

408 lines (230 loc) · 10.1 KB

@onzag/itemize / Modules / database / DatabaseConnection

Class: 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

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new DatabaseConnection(info, client?, pool?): DatabaseConnection

Constructs a new database connection

Parameters

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

Returns

DatabaseConnection

Defined in

database/index.ts:62

Properties

client

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

Defined in

database/index.ts:44


forceLogs

Private forceLogs: boolean

Forces the logging even if env is not development

Defined in

database/index.ts:54


pool

Private pool: Pool

This is the pg pool

Defined in

database/index.ts:38


suppressLogs

Private suppressLogs: boolean

Suppresses console logging

Defined in

database/index.ts:49

Methods

forceLogging

forceLogging(): void

Forces console logging even if env is not development

Returns

void

Defined in

database/index.ts:84


getAlterTableBuilder

getAlterTableBuilder(): AlterTableBuilder

Provides a single alter table builder

Returns

AlterTableBuilder

a new alter table builder

Defined in

database/index.ts:225


getClient

getClient(): PoolClient

Provides the current active pg client, only really existant on transactions

Returns

PoolClient

the client

Defined in

database/index.ts:241


getCreateTableBuilder

getCreateTableBuilder(): CreateTableBuilder

Provides a single create table builder

Returns

CreateTableBuilder

a new create table builder

Defined in

database/index.ts:217


getInsertBuilder

getInsertBuilder(): InsertBuilder

Provides a single insert builder

Returns

InsertBuilder

a new insert builder

Defined in

database/index.ts:209


getPool

getPool(): Pool

Provides the current active pg pool

Returns

Pool

the pool

Defined in

database/index.ts:233


getSelectBuilder

getSelectBuilder(): SelectBuilder

Provides a single select builder

Returns

SelectBuilder

a new select builder

Defined in

database/index.ts:201


getUpdateBuilder

getUpdateBuilder(): UpdateBuilder

Provides a single update builder

Returns

UpdateBuilder

a new update builder

Defined in

database/index.ts:193


query

query(what, bindings?, useHoles?): Promise<QueryResult<any>>

Performs a query against the database and returns a query result

Parameters

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 -

Returns

Promise<QueryResult<any>>

a promise of a query result

Defined in

database/index.ts:95


queryFirst

queryFirst(what, bindings?, useHoles?): Promise<any>

Performs a query against the database and returns only the first row

Parameters

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 -

Returns

Promise<any>

a promise of a single row

Defined in

database/index.ts:185


queryRows

queryRows(what, bindings?, useHoles?): Promise<any[]>

Performs a query against the database and returns only the rows

Parameters

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 -

Returns

Promise<any[]>

a promise of a list of rows

Defined in

database/index.ts:174


startSingleClientOperation

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

Parameters

Name Type
arg (transactingClient: DatabaseConnection) => Promise<any>

Returns

Promise<any>

Defined in

database/index.ts:256


startTransaction

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

Parameters

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 -

Returns

Promise<any>

whatever you returned in your arg function

Defined in

database/index.ts:293


suppressLogging

suppressLogging(): void

Suppresses console logging

Returns

void

Defined in

database/index.ts:76