IAdminForthDataSourceConnectorBase
Interface that exposes methods to interact with AdminForth in standard way
Extends
Properties
client
client:
any
Inherited from
IAdminForthDataSourceConnector.client
supportsCompositePrimaryKey?
optionalsupportsCompositePrimaryKey?: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
| Parameter | Type |
|---|---|
__namedParameters | { aggregations: {[alias: string]: IAggregationRule; }; filters: IAdminForthAndOrFilter; groupBy?: IGroupByRule | IGroupByRule[]; resource: AdminForthResource; } |
__namedParameters.aggregations | {[alias: string]: IAggregationRule; } |
__namedParameters.filters | IAdminForthAndOrFilter |
__namedParameters.groupBy? | IGroupByRule | IGroupByRule[] |
__namedParameters.resource | AdminForthResource |
Returns
Promise<object[]>
createRecord()
createRecord(
__namedParameters):Promise<{createdRecord?:any;error?:string;ok:boolean; }>
Parameters
| Parameter | Type |
|---|---|
__namedParameters | { adminUser: AdminUser; record: any; resource: AdminForthResource; } |
__namedParameters.adminUser | AdminUser |
__namedParameters.record | any |
__namedParameters.resource | AdminForthResource |
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
| Parameter | Type |
|---|---|
__namedParameters | { record: any; resource: AdminForthResource; } |
__namedParameters.record | any |
__namedParameters.resource | AdminForthResource |
Returns
Promise<string>
Inherited from
IAdminForthDataSourceConnector.createRecordOriginalValues
deleteMany()?
optionaldeleteMany(__namedParameters):Promise<number>
Parameters
| Parameter | Type |
|---|---|
__namedParameters | { recordIds: any[]; resource: AdminForthResource; } |
__namedParameters.recordIds | any[] |
__namedParameters.resource | AdminForthResource |
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
| Parameter | Type |
|---|---|
__namedParameters | { pkValues?: Record<string, any>; recordId: any; resource: AdminForthResource; } |
__namedParameters.pkValues? | Record<string, any> |
__namedParameters.recordId | any |
__namedParameters.resource | AdminForthResource |
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:
- AdminForthResourceColumn.type Constraints:
- AdminForthResourceColumn.required
- AdminForthResourceColumn.primaryKey For string fields:
- AdminForthResourceColumn.maxLength For numbers: // min/max are used inside getMinMaxForColumns from base connector
- AdminForthResourceColumn.min
- AdminForthResourceColumn.max
- AdminForthResourceColumn.minValue,
- AdminForthResourceColumn.maxValue,
- AdminForthResourceColumn.enum,
- AdminForthResourceColumn.foreignResource,
- AdminForthResourceColumn.sortable,
- AdminForthResourceColumn.backendOnly,
- AdminForthResourceColumn.masked,
- AdminForthResourceColumn.virtual,
- AdminForthResourceColumn.components,
- AdminForthResourceColumn.allowMinMaxQuery,
- AdminForthResourceColumn.editingNote,
- AdminForthResourceColumn.showIn,
- AdminForthResourceColumn.isUnique,
- AdminForthResourceColumn.validation) Also you can additionally save original column type to AdminForthResourceColumn._underlineType. This might be later used in IAdminForthDataSourceConnector.getFieldValue and IAdminForthDataSourceConnector.setFieldValue methods.
Parameters
| Parameter | Type | Description |
|---|---|---|
resource | AdminForthResource | - |
config | AdminForthConfig | - |
Returns
Promise<{[key: string]: AdminForthResourceColumn; }>
Inherited from
IAdminForthDataSourceConnector.discoverFields
getAggregateWithOriginalTypes()?
optionalgetAggregateWithOriginalTypes(__namedParameters):Promise<object[]>
Optional. Used to perform aggregation queries on a resource table. Returns rows with aliased aggregate values and optional group key.
Parameters
| Parameter | Type |
|---|---|
__namedParameters | { aggregations: {[alias: string]: IAggregationRule; }; filters: IAdminForthAndOrFilter; groupBy?: IGroupByRule | IGroupByRule[]; resource: AdminForthResource; } |
__namedParameters.aggregations | {[alias: string]: IAggregationRule; } |
__namedParameters.filters | IAdminForthAndOrFilter |
__namedParameters.groupBy? | IGroupByRule | IGroupByRule[] |
__namedParameters.resource | AdminForthResource |
Returns
Promise<object[]>
Inherited from
IAdminForthDataSourceConnector.getAggregateWithOriginalTypes
getAllColumnsInTable()
getAllColumnsInTable(
tableName):Promise<object[]>
Function to get all columns in table.
Parameters
| Parameter | Type |
|---|---|
tableName | string |
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
| Parameter | Type |
|---|---|
__namedParameters | { filters: IAdminForthAndOrFilter; resource: AdminForthResource; } |
__namedParameters.filters | IAdminForthAndOrFilter |
__namedParameters.resource | AdminForthResource |
Returns
Promise<number>
Inherited from
IAdminForthDataSourceConnector.getCount
getData()
getData(
__namedParameters):Promise<{data:any[];total:number; }>
Parameters
| Parameter | Type |
|---|---|
__namedParameters | { columns?: AdminForthResourceColumn[]; filters: IAdminForthAndOrFilter; getTotals?: boolean; limit: number; offset: number; resource: AdminForthResource; sort: IAdminForthSort[]; } |
__namedParameters.columns? | AdminForthResourceColumn[] |
__namedParameters.filters | IAdminForthAndOrFilter |
__namedParameters.getTotals? | boolean |
__namedParameters.limit | number |
__namedParameters.offset | number |
__namedParameters.resource | AdminForthResource |
__namedParameters.sort | IAdminForthSort[] |
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
| Parameter | Type |
|---|---|
__namedParameters | { columns?: AdminForthResourceColumn[]; filters: IAdminForthAndOrFilter; limit: number; offset: number; resource: AdminForthResource; sort: IAdminForthSort[]; } |
__namedParameters.columns? | AdminForthResourceColumn[] |
__namedParameters.filters | IAdminForthAndOrFilter |
__namedParameters.limit | number |
__namedParameters.offset | number |
__namedParameters.resource | AdminForthResource |
__namedParameters.sort | IAdminForthSort[] |
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
| Parameter | Type | Description |
|---|---|---|
field | AdminForthResourceColumn | - |
value | any | - |
Returns
any
Inherited from
IAdminForthDataSourceConnector.getFieldValue
getMinMaxForColumns()
getMinMaxForColumns(
__namedParameters):Promise<ColumnMinMaxValue>
Parameters
| Parameter | Type |
|---|---|
__namedParameters | { columns: AdminForthResourceColumn[]; resource: AdminForthResource; } |
__namedParameters.columns | AdminForthResourceColumn[] |
__namedParameters.resource | AdminForthResource |
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
| Parameter | Type |
|---|---|
__namedParameters | { columns: AdminForthResourceColumn[]; resource: AdminForthResource; } |
__namedParameters.columns | AdminForthResourceColumn[] |
__namedParameters.resource | AdminForthResource |
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
| Parameter | Type |
|---|---|
resource | AdminForthResource |
Returns
string
getPrimaryKeyFilters()?
optionalgetPrimaryKeyFilters(resource,recordId):IAdminForthSingleFilter[]
Builds filters which select exactly one record with given recordId. Optional for the same reason as getPrimaryKeys.
Parameters
| Parameter | Type |
|---|---|
resource | AdminForthResource |
recordId | any |
Returns
getPrimaryKeys()?
optionalgetPrimaryKeys(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
| Parameter | Type |
|---|---|
resource | AdminForthResource |
Returns
string[]
getPrimaryKeyValues()?
optionalgetPrimaryKeyValues(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
| Parameter | Type |
|---|---|
resource | AdminForthResource |
recordId | any |
Returns
Record<string, any>
getRecordByPrimaryKey()
getRecordByPrimaryKey(
resource,recordId):Promise<any>
Parameters
| Parameter | Type |
|---|---|
resource | AdminForthResource |
recordId | string |
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
| Parameter | Type |
|---|---|
resource | AdminForthResource |
recordId | string |
Returns
Promise<any>
Inherited from
IAdminForthDataSourceConnector.getRecordByPrimaryKeyWithOriginalTypes
isDatabaseEmpty()?
optionalisDatabaseEmpty():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
| Parameter | Type | Description |
|---|---|---|
field | AdminForthResourceColumn | - |
value | any | - |
Returns
any
Inherited from
IAdminForthDataSourceConnector.setFieldValue
setupClient()
setupClient(
url,options?):Promise<void>
Function to setup client connection to database.
Parameters
| Parameter | Type | Description |
|---|---|---|
url | string | URL 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
| Parameter | Type |
|---|---|
__namedParameters | { newValues: any; recordId: string; resource: AdminForthResource; } |
__namedParameters.newValues | any |
__namedParameters.recordId | string |
__namedParameters.resource | AdminForthResource |
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
| Parameter | Type |
|---|---|
__namedParameters | { newValues: any; pkValues?: Record<string, any>; recordId: string; resource: AdminForthResource; } |
__namedParameters.newValues | any |
__namedParameters.pkValues? | Record<string, any> |
__namedParameters.recordId | string |
__namedParameters.resource | AdminForthResource |
Returns
Promise<void>
Inherited from
IAdminForthDataSourceConnector.updateRecordOriginalValues
validateAndNormalizeInputFilters()
validateAndNormalizeInputFilters(
filter):IAdminForthAndOrFilter
Parameters
| Parameter | Type |
|---|---|
filter | IAdminForthSingleFilter | IAdminForthAndOrFilter | (IAdminForthSingleFilter | IAdminForthAndOrFilter)[] |