Skip to main content

IAdminForthDataSourceConnector

Extended by​

Properties​

client​

client: any


supportsCompositePrimaryKey?​

optional supportsCompositePrimaryKey?: boolean

Set to true if connector is able to work with resources which have several columns marked as AdminForthResourceColumn.primaryKey (composite primary key). Such connector must build WHERE clause from pkValues argument of IAdminForthDataSourceConnector.updateRecordOriginalValues and IAdminForthDataSourceConnector.deleteRecord instead of using getPrimaryKey().

Methods​

createRecordOriginalValues()​

createRecordOriginalValues(__namedParameters): Promise<string>

Used to create record in database. Should return value of primary key column of created record.

Parameters​

ParameterType
__namedParameters{ record: any; resource: AdminForthResource; }
__namedParameters.recordany
__namedParameters.resourceAdminForthResource

Returns​

Promise<string>


deleteRecord()​

deleteRecord(__namedParameters): Promise<boolean>

Used to delete record in database. pkValues is map of primary key column name to its value, use it to build WHERE clause (it supports both single and composite primary keys).

Parameters​

ParameterType
__namedParameters{ pkValues?: Record<string, any>; recordId: any; resource: AdminForthResource; }
__namedParameters.pkValues?Record<string, any>
__namedParameters.recordIdany
__namedParameters.resourceAdminForthResource

Returns​

Promise<boolean>


discoverFields()​

discoverFields(resource, config): Promise<{[key: string]: AdminForthResourceColumn; }>

Function should go over all columns of table defined in resource.table and try to guess data and constraints for each columns. Type should be saved to:

Parameters​

ParameterTypeDescription
resourceAdminForthResource-
configAdminForthConfig-

Returns​

Promise<{[key: string]: AdminForthResourceColumn; }>


getAggregateWithOriginalTypes()?​

optional getAggregateWithOriginalTypes(__namedParameters): Promise<object[]>

Optional. Used to perform aggregation queries on a resource table. Returns rows with aliased aggregate values and optional group key.

Parameters​

ParameterType
__namedParameters{ aggregations: {[alias: string]: IAggregationRule; }; filters: IAdminForthAndOrFilter; groupBy?: IGroupByRule | IGroupByRule[]; resource: AdminForthResource; }
__namedParameters.aggregations{[alias: string]: IAggregationRule; }
__namedParameters.filtersIAdminForthAndOrFilter
__namedParameters.groupBy?IGroupByRule | IGroupByRule[]
__namedParameters.resourceAdminForthResource

Returns​

Promise<object[]>


getAllColumnsInTable()​

getAllColumnsInTable(tableName): Promise<object[]>

Function to get all columns in table.

Parameters​

ParameterType
tableNamestring

Returns​

Promise<object[]>


getAllTables()​

getAllTables(): Promise<string[]>

Function to get all tables from database.

Returns​

Promise<string[]>


getCount()​

getCount(__namedParameters): Promise<number>

Used to get count of records in database.

Parameters​

ParameterType
__namedParameters{ filters: IAdminForthAndOrFilter; resource: AdminForthResource; }
__namedParameters.filtersIAdminForthAndOrFilter
__namedParameters.resourceAdminForthResource

Returns​

Promise<number>


getDataWithOriginalTypes()​

getDataWithOriginalTypes(__namedParameters): Promise<any[]>

Used to fetch data from database. This method is reused both to list records and show one record (by passing limit 1 and offset 0) .

Fields are returned from db "as is" then AdminForthBaseConnector.getData will transform each field using IAdminForthDataSourceConnector.getFieldValue

Parameters​

ParameterType
__namedParameters{ columns?: AdminForthResourceColumn[]; filters: IAdminForthAndOrFilter; limit: number; offset: number; resource: AdminForthResource; sort: IAdminForthSort[]; }
__namedParameters.columns?AdminForthResourceColumn[]
__namedParameters.filtersIAdminForthAndOrFilter
__namedParameters.limitnumber
__namedParameters.offsetnumber
__namedParameters.resourceAdminForthResource
__namedParameters.sortIAdminForthSort[]

Returns​

Promise<any[]>


getFieldValue()​

getFieldValue(field, value): any

Used to transform record after fetching from database. According to AdminForth convention, if AdminForthResourceColumn.type is set to AdminForthDataTypes.DATETIME then it should be transformed to ISO string.

Parameters​

ParameterTypeDescription
fieldAdminForthResourceColumn-
valueany-

Returns​

any


getMinMaxForColumnsWithOriginalTypes()​

getMinMaxForColumnsWithOriginalTypes(__namedParameters): Promise<ColumnMinMaxValue>

Optional method which used to get min and max values for columns in resource. Called only for columns which have AdminForthResourceColumn.allowMinMaxQuery set to true.

Internally should call IAdminForthDataSourceConnector.getFieldValue for both min and max values.

Parameters​

ParameterType
__namedParameters{ columns: AdminForthResourceColumn[]; resource: AdminForthResource; }
__namedParameters.columnsAdminForthResourceColumn[]
__namedParameters.resourceAdminForthResource

Returns​

Promise<ColumnMinMaxValue>


getRecordByPrimaryKeyWithOriginalTypes()​

getRecordByPrimaryKeyWithOriginalTypes(resource, recordId): Promise<any>

Optional. You an redefine this function to define how one record should be fetched from database. You you will not redefine it, AdminForth will use IAdminForthDataSourceConnector.getData with limit 1 and offset 0 and filter by primary key.

Parameters​

ParameterType
resourceAdminForthResource
recordIdstring

Returns​

Promise<any>


isDatabaseEmpty()?​

optional isDatabaseEmpty(): Promise<boolean>

Function to check whether database has no user data.

Returns​

Promise<boolean>


setFieldValue()​

setFieldValue(field, value): any

Used to transform record before saving to database. Should perform operation inverse to IAdminForthDataSourceConnector.getFieldValue

Parameters​

ParameterTypeDescription
fieldAdminForthResourceColumn-
valueany-

Returns​

any


setupClient()​

setupClient(url, options?): Promise<void>

Function to setup client connection to database.

Parameters​

ParameterTypeDescription
urlstringURL to database. Examples: clickhouse://demo:demo@localhost:8125/demo
options?{ recovery?: boolean; }Optional connection options. recovery mirrors the dataSource connectionRecovery flag (defaults to true when omitted).
options.recovery?boolean-

Returns​

Promise<void>


updateRecordOriginalValues()​

updateRecordOriginalValues(__namedParameters): Promise<void>

Update record in database. newValues might have not all fields in record, but only changed ones. recordId is value of field which is marked as AdminForthResourceColumn.primaryKey, or, for resources with composite primary key, encoded value of all such columns. pkValues is map of primary key column name to its value, use it to build WHERE clause (it supports both single and composite primary keys).

Parameters​

ParameterType
__namedParameters{ newValues: any; pkValues?: Record<string, any>; recordId: string; resource: AdminForthResource; }
__namedParameters.newValuesany
__namedParameters.pkValues?Record<string, any>
__namedParameters.recordIdstring
__namedParameters.resourceAdminForthResource

Returns​

Promise<void>