import { Knex } from "knex"; import { DataSourceAdapterType, FieldInput, JsType, RelationalDatabaseSchema, RelationalDatabaseSchemaColumn, TablePageDeleteRecordInput, TablePageCreateRecordInput, TablePageGetRecordsInput, TablePageUpdateRecordInput, TablePageCreateRecordResult, TablePageGetRecordsResult, TablePageUpdateRecordResult, TablePageGetRecordInput, TablePageGetRecordResult, DataSourceTablesConfig, TablePageConfig, FilterItem, DataSource, DashboardPageGetStatDataInput, DashboardPageGetStatDataResult, DashboardPageConfigStat, DashboardPageConfigCard, DashboardPageGetCardDataResult, DashboardPageGetCardDataInput } from "@kottster/common"; import { KottsterApp } from "../core/app"; import { Readable } from "stream"; /** * The base class for all data source adapters * @abstract */ export declare abstract class DataSourceAdapter { protected client: Knex; abstract type: DataSourceAdapterType; protected databaseSchemas: string[]; private app?; private tablesConfig; private cachedFullDatabaseSchemaSchema; private cachingService; protected name: string; private readonly STREAM_CHUNK_SIZE; constructor(client: Knex); /** * Set the app instance */ setApp(app: KottsterApp): void; /** * Set the data source data */ setData(data: Omit): void; /** * Set the tables config */ setTablesConfig(tablesConfig: DataSourceTablesConfig): void; /** * Get the database schemas */ setDatabaseSchemas(databaseSchemas: string[]): void; /** * Get the client * @returns The client */ getClient(): Knex; /** * Remove excluded tables and columns from the schema * @returns The schema without the excluded tables and columns based on the tables config */ removeExcludedTablesAndColumns(schema: RelationalDatabaseSchema): RelationalDatabaseSchema; checkIfAnyTableHasPrimaryKey(schema: RelationalDatabaseSchema): boolean; abstract getDatabaseTableCount(): Promise; abstract getDatabaseSchemaRaw(): Promise; private sortColumnsByPriority; /** * Get the database schema * @returns The database schema */ getDatabaseSchema(): Promise; /** * Process the column * @returns The processed column */ abstract processColumn(column: RelationalDatabaseSchemaColumn): { isArray: boolean; fieldInput: FieldInput; returnedJsType: keyof typeof JsType; returnedAsArray: boolean; }; /** * Prepare the record value before returning it to the client * @example Convert date to ISO string, pg string-like array to js array, etc. * @returns The transformed value */ abstract prepareRecordValue(value: any, columnSchema: RelationalDatabaseSchemaColumn): Promise; /** * Prepare the record value before inserting/updating it into the database * @example Remove timezone from date for MySQL, etc. * @returns The transformed value */ abstract prepareRecordValueBeforeUpsert(value: any, columnSchema: RelationalDatabaseSchemaColumn): Promise; /** * Get the search builder that will apply the search query * @returns The search builder */ abstract getSearchBuilder(searchableColumns: string[], searchValue: string): (builder: Knex.QueryBuilder) => void; /** * Apply the filters to the query */ applyFilters(query: Knex.QueryBuilder, filterItems: FilterItem[], mainTable: string, databaseSchema: RelationalDatabaseSchema): void; abstract applyFilterCondition(builder: Knex.QueryBuilder, filterItem: FilterItem, columnReference: string): void; /** * Get the stat data (Dashboard RPC) * @returns The stat data */ getStatData(input: DashboardPageGetStatDataInput, stat: DashboardPageConfigStat): Promise; /** * Get the card data (Dashboard RPC) * @returns The card data */ getCardData(input: DashboardPageGetCardDataInput, card: DashboardPageConfigCard): Promise; /** * Build the base query for table records */ private buildTableRecordsQuery; /** * Get the table records (Table RPC) - UPDATED */ getTableRecords(rootTablePageConfig: TablePageConfig, input: TablePageGetRecordsInput, databaseSchema: RelationalDatabaseSchema): Promise; /** * Process records array */ private processTableRecords; getTableRecordsStream(rootTablePageConfig: TablePageConfig, input: TablePageGetRecordsInput, databaseSchema: RelationalDatabaseSchema): Promise; /** * Enrich the records with related data for visible relationships in the table * @returns The enriched records */ private enrichRecordsWithRelatedData; private prepareRecords; executeRawQueryForSingleValue(query: string, vars?: Record): Promise; executeRawQuery(query: string, vars?: Record): Promise; /** * Get the table record * @description Used for one-to-one RecordSelect fields * @returns The table record */ getOneTableRecord(rootTablePageConfig: TablePageConfig, input: TablePageGetRecordInput, databaseSchema: RelationalDatabaseSchema): Promise; /** * Insert the table records (Table RPC) * @returns The table records */ insertTableRecord(rootTablePageConfig: TablePageConfig, input: TablePageCreateRecordInput, databaseSchema: RelationalDatabaseSchema): Promise; /** * Update the table records (Table RPC) * @returns The table records */ updateTableRecords(rootTablePageConfig: TablePageConfig, input: TablePageUpdateRecordInput, databaseSchema: RelationalDatabaseSchema): Promise; private executeUpsertAndGetId; /** * Delete the table records (Table RPC) * @returns The table records */ deleteTableRecords(rootTablePageConfig: TablePageConfig, input: TablePageDeleteRecordInput, databaseSchema: RelationalDatabaseSchema): Promise; /** * Connect to the database * @param reloadOnFailure - If true, will attempt to reconnect to the database on failure */ connect(reloadOnFailure?: boolean): void; /** * Ping the database to check if the connection is successful * @returns True if the connection is successful */ pingDatabase(): Promise; /** * Destroy the database connection */ destroyConnection(): void; }