Skip to main content

Class: DBResult

@divine/uri.DBResult

A raw database result set.

This Array subclass hold rows of cells in a tabular format and metadata about the columns (name, type etc) in the columns property. Additional metadata such as row count and row key is also available.

This is an abstract class. Each database driver is expected to provide a full implementation and a concrete subclass.

Hierarchy

  • Array<unknown[]>

    DBResult

Constructors

constructor

new DBResult(_db, columns, records, rowCount?, rowKey?)

Constructs a new DBResult.

Parameters

NameTypeDescription
_dbDatabaseURIThe DatabaseURI this result set belongs to.
columnsDBColumnInfo[]Metadata abount the columns in this result set.
recordsunknown[][]The records to adopt. May be an empty array if no actual result was produced by the query.
rowCount?numberThe number of rows the query producing the result set affected.
rowKey?stringThe primary key/unique row key the the query producing the result set generated.

Overrides

Array<unknown[]\>.constructor

Defined in

uri/src/protocols/database.ts:555

Properties

_db

Protected _db: DatabaseURI

The DatabaseURI this result set belongs to.

Defined in

uri/src/protocols/database.ts:555


columns

Readonly columns: DBColumnInfo[]

Metadata abount the columns in this result set.

Defined in

uri/src/protocols/database.ts:555


rowCount

Optional rowCount: number

The number of rows the query producing the result set affected.

Defined in

uri/src/protocols/database.ts:555


rowKey

Optional rowKey: string

The primary key/unique row key the the query producing the result set generated.

Defined in

uri/src/protocols/database.ts:555

Accessors

[species]

Static get [species](): ArrayConstructor

Array functions return a new Array, not a DBResult.

Returns

ArrayConstructor

Overrides

Array.[species]

Defined in

uri/src/protocols/database.ts:542

Methods

_fixColumnInfo

Protected _fixColumnInfo(columnRow): Partial<DBColumnInfo>

A helper method for database driver implementations that converts a DBColumnInfo-like object into an actual DBColumnInfo entry.

Parameters

NameTypeDescription
columnRowobjectA DBColumnInfo-like object. Keys may be non-lowercase and values may be all strings, for instance.

Returns

Partial<DBColumnInfo>

A DBColumnInfo.

Defined in

uri/src/protocols/database.ts:622


toObject

toObject<T>(fields?): T & DBMetadata

Converts this result set into a single object/record.

The result is an object where keys are the column labels holding the values (unlike the rows in this class, where each row is just an array of values).

This method is used by watch if the event contains only a single row, which is usually the case.

Throws

TypeError If the length of this result set is not exactly 1.

Type parameters

NameTypeDescription
Textends objectThe actual record type.

Parameters

NameTypeDescription
fields?DBResult[]What to set [FIELDS] to. Defaults to [ this ].

Returns

T & DBMetadata

A single record (where keys are the column labels) of the first (and only) row in the result set.

Defined in

uri/src/protocols/database.ts:669


toObjects

toObjects<T>(fields?): T[] & DBMetadata

Converts this result set into an array of object/records.

The result is an array of object where keys are the column labels holding the values (unlike the rows in this class, where each row is just an array of values).

This method is used by DatabaseURI to convert all result sets created by the database drivers before returning them to the caller.

Type parameters

NameTypeDescription
Textends objectThe actual record type.

Parameters

NameTypeDescription
fields?DBResult[]What to set [FIELDS] to. Defaults to [ this ].

Returns

T[] & DBMetadata

An array of records (where keys are the column labels) of all the row in the result set.

Defined in

uri/src/protocols/database.ts:697


updateColumnInfo

updateColumnInfo(): Promise<DBColumnInfo[]>

Initially, the column metatdata will include just the bare minumum, like the label, possibly data type and the origins of the value. By calling this method, the metadata will be expanded to everything that is known about the column by querying the database for more information.

The base class implementation of this method queries the INFORMATION_SCHEMA.COLUMNS view based on table_catalog, table_schema, table_name and column_name. Subclasses may override or extend this method, based on how the actual database provides column metadata.

Throws

DBError On database/query errors.

Returns

Promise<DBColumnInfo[]>

The updated/expanded column metadata (also available in columns after this call has completed).

Defined in

uri/src/protocols/database.ts:586