Dataloader

Dataloader acts as a link between react-adminer and your data (database/api).

These are simply configurations of internal react-adminer queries and commands based on the original database.

Usage

dataProvider={{ select, count, insert, update }}

Example

Here is an example of dataloader configuration when connecting to a database.

import type { UpdateOptions, SelectOptions, CountOptions, TableConfig } from 'react-adminer';
import { Database } from './Database';
import { SCHEMA } from './schema';

const db = new Database();

export const select = (entityName: string, options?: SelectOptions): Promise<any[]> =>
	db.select(entityName, options, SCHEMA) as Promise<any[]>;

export const count = (entityName: string, options?: CountOptions): Promise<number> =>
	db.count(entityName, options?.where, SCHEMA) as unknown as Promise<number>;

export const insert = (entityName: string, object: Record<string, any>): Promise<string | number> =>
	db.insert(entityName, object) as any;

export const update = (
	entityName: string,
	object: Record<string, any>,
	entityConfig: TableConfig,
	options?: UpdateOptions,
): Promise<boolean> => {
	db.update(entityName, object, entityConfig, options);
	return Promise.resolve(true);
};

Arguments

Select

The select argument in the dataloader is used to select specific data of the input data file. This way you can exclude unnecessary entries and work only with the necessary ones.

The return type value is: Promise<any[]>

Select-Parameters

entityName -Required - type: string - Specifies the entity for which the select is to be used

options - not Required - type: SeletOptions - Represents the possibility of specific detailed settings

Count

The count argument in the dataloader is used to specify the number of elements to be selected from the datastore.

The return type value is: Promise<number>

Count-Parameters

entityName -Required - type: string - Specifies the entity for which the count is to be used

options - not Required - type: CountOptions - Represents the possibility of specific detailed settings

Insert

The insert argument is used to insert/import data, here specifically to a particular entity of a particular object that contains data.

The return type value is: Promise<string | number>

Insert-Parameters

entityName -Required - type: string - Specifies the entity for which the entry is to be added

object -Required - type: Record<string, any> - Represents the packed data/record to be imported/added

Update

The update argument allows you to edit an already created record.

The return type value is: Promise<boolean>

Update-Parameters

entityName -Required - type: string - Specifies the entity for which to apply the update

object -Required - type: Record<string, any> - Represents the packed data/record that will replace the previous data/record

entityConfig -Required - type: TableConfig - Allows to select, filter and fields

options - not Required - type: UpdateOptions - Represents the possibility of specific detailed settings

Last updated