Skip to main content

IAdminForthDataSourceConnectorBase

Interface that exposes methods to interact with AdminForth in standard way

Extends​

Properties​

client​

client: any

Inherited from​

IAdminForthDataSourceConnector.client


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().

Inherited from​

IAdminForthDataSourceConnector.supportsCompositePrimaryKey

Methods​

aggregate()​

aggregate(__namedParameters): Promise<object[]>

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[]>


createRecord()​

createRecord(__namedParameters): Promise<{ createdRecord?: any; error?: string; ok: boolean; }>

Parameters​

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

Returns​

Promise<{ createdRecord?: any; error?: string; ok: boolean; }>


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>

Inherited from​

IAdminForthDataSourceConnector.createRecordOriginalValues


deleteMany()?​

optional deleteMany(__namedParameters): Promise<number>

Parameters​

ParameterType
__namedParameters{ recordIds: any[]; resource: AdminForthResource; }
__namedParameters.recordIdsany[]
__namedParameters.resourceAdminForthResource

Returns​

Promise<number>


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>

Inherited from​

IAdminForthDataSourceConnector.deleteRecord


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; }>

Inherited from​

IAdminForthDataSourceConnector.discoverFields


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[]>

Inherited from​

IAdminForthDataSourceConnector.getAggregateWithOriginalTypes


getAllColumnsInTable()​

getAllColumnsInTable(tableName): Promise<object[]>

Function to get all columns in table.

Parameters​

ParameterType
tableNamestring

Returns​

Promise<object[]>

Inherited from​

IAdminForthDataSourceConnector.getAllColumnsInTable


getAllTables()​

getAllTables(): Promise<string[]>

Function to get all tables from database.

Returns​

Promise<string[]>

Inherited from​

IAdminForthDataSourceConnector.getAllTables


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>

Inherited from​

IAdminForthDataSourceConnector.getCount


getData()​

getData(__namedParameters): Promise<{ data: any[]; total: number; }>

Parameters​

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

Returns​

Promise<{ data: any[]; total: 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[]>

Inherited from​

IAdminForthDataSourceConnector.getDataWithOriginalTypes


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

Inherited from​

IAdminForthDataSourceConnector.getFieldValue


getMinMaxForColumns()​

getMinMaxForColumns(__namedParameters): Promise<ColumnMinMaxValue>

Parameters​

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

Returns​

Promise<ColumnMinMaxValue>


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>

Inherited from​

IAdminForthDataSourceConnector.getMinMaxForColumnsWithOriginalTypes


getPrimaryKey()​

getPrimaryKey(resource): string

Returns name of first column marked as primaryKey. For resources with composite primary key use getPrimaryKeys.

Parameters​

ParameterType
resourceAdminForthResource

Returns​

string


getPrimaryKeyFilters()?​

optional getPrimaryKeyFilters(resource, recordId): IAdminForthSingleFilter[]

Builds filters which select exactly one record with given recordId. Optional for the same reason as getPrimaryKeys.

Parameters​

ParameterType
resourceAdminForthResource
recordIdany

Returns​

IAdminForthSingleFilter[]


getPrimaryKeys()?​

optional getPrimaryKeys(resource): string[]

Returns names of all columns marked as primaryKey (more then one for composite primary key). Optional: connectors which extend AdminForthBaseConnector get it for free, connectors which implement this interface on their own may not have it, so core always calls it optionally.

Parameters​

ParameterType
resourceAdminForthResource

Returns​

string[]


getPrimaryKeyValues()?​

optional getPrimaryKeyValues(resource, recordId): Record<string, any>

Splits recordId into values of primary key columns, casted to data source types. Optional for the same reason as getPrimaryKeys.

Parameters​

ParameterType
resourceAdminForthResource
recordIdany

Returns​

Record<string, any>


getRecordByPrimaryKey()​

getRecordByPrimaryKey(resource, recordId): Promise<any>

Parameters​

ParameterType
resourceAdminForthResource
recordIdstring

Returns​

Promise<any>


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>

Inherited from​

IAdminForthDataSourceConnector.getRecordByPrimaryKeyWithOriginalTypes


isDatabaseEmpty()?​

optional isDatabaseEmpty(): Promise<boolean>

Function to check whether database has no user data.

Returns​

Promise<boolean>

Inherited from​

IAdminForthDataSourceConnector.isDatabaseEmpty


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

Inherited from​

IAdminForthDataSourceConnector.setFieldValue


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>

Inherited from​

IAdminForthDataSourceConnector.setupClient


updateRecord()​

updateRecord(__namedParameters): Promise<{ error?: string; ok: boolean; }>

Parameters​

ParameterType
__namedParameters{ newValues: any; recordId: string; resource: AdminForthResource; }
__namedParameters.newValuesany
__namedParameters.recordIdstring
__namedParameters.resourceAdminForthResource

Returns​

Promise<{ error?: string; ok: boolean; }>


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>

Inherited from​

IAdminForthDataSourceConnector.updateRecordOriginalValues


validateAndNormalizeInputFilters()​

validateAndNormalizeInputFilters(filter): IAdminForthAndOrFilter

Parameters​

ParameterType
filterIAdminForthSingleFilter | IAdminForthAndOrFilter | (IAdminForthSingleFilter | IAdminForthAndOrFilter)[]

Returns​

IAdminForthAndOrFilter