2022-03-24 09:50:40 +00:00
|
|
|
import { Field, RawValue } from '../../schemas/types';
|
2022-04-11 06:04:55 +00:00
|
|
|
import DatabaseCore from './core';
|
2022-03-25 10:12:39 +00:00
|
|
|
import { DatabaseManager } from './manager';
|
2022-03-24 09:50:40 +00:00
|
|
|
|
2022-03-23 06:16:13 +00:00
|
|
|
export interface GetQueryBuilderOptions {
|
2022-03-25 10:12:39 +00:00
|
|
|
offset?: number;
|
|
|
|
limit?: number;
|
2023-01-05 05:44:05 +00:00
|
|
|
groupBy?: string | string[];
|
|
|
|
orderBy?: string | string[];
|
2022-03-25 10:12:39 +00:00
|
|
|
order?: 'desc' | 'asc';
|
2022-03-23 06:16:13 +00:00
|
|
|
}
|
2022-03-24 09:50:40 +00:00
|
|
|
|
|
|
|
export type ColumnDiff = { added: Field[]; removed: string[] };
|
|
|
|
export type FieldValueMap = Record<
|
|
|
|
string,
|
|
|
|
RawValue | undefined | FieldValueMap[]
|
|
|
|
>;
|
2022-03-24 13:13:59 +00:00
|
|
|
|
2023-07-11 07:11:22 +00:00
|
|
|
export type AlterConfig = {
|
|
|
|
schemaName: string;
|
|
|
|
diff: ColumnDiff;
|
|
|
|
newForeignKeys: Field[];
|
|
|
|
};
|
|
|
|
|
|
|
|
export type NonExtantConfig = {
|
|
|
|
schemaName: string;
|
|
|
|
nonExtant: {
|
|
|
|
fieldname: string;
|
|
|
|
value: RawValue;
|
|
|
|
}[];
|
|
|
|
};
|
|
|
|
|
|
|
|
export type UpdateSinglesConfig = {
|
|
|
|
update: string[];
|
|
|
|
updateNonExtant: NonExtantConfig[];
|
|
|
|
};
|
|
|
|
|
|
|
|
export type MigrationConfig = {
|
|
|
|
pre?: () => Promise<void> | void;
|
|
|
|
post?: () => Promise<void> | void;
|
|
|
|
};
|
|
|
|
|
2022-03-24 13:13:59 +00:00
|
|
|
export interface Patch {
|
|
|
|
name: string;
|
|
|
|
version: string;
|
|
|
|
patch: {
|
2022-03-25 10:12:39 +00:00
|
|
|
execute: (dm: DatabaseManager) => Promise<void>;
|
2022-03-24 13:13:59 +00:00
|
|
|
beforeMigrate?: boolean;
|
|
|
|
};
|
2022-05-24 19:06:54 +00:00
|
|
|
priority?: number;
|
2022-03-24 13:13:59 +00:00
|
|
|
}
|
2022-03-25 10:12:39 +00:00
|
|
|
|
|
|
|
export type KnexColumnType =
|
|
|
|
| 'text'
|
|
|
|
| 'integer'
|
|
|
|
| 'float'
|
|
|
|
| 'boolean'
|
|
|
|
| 'date'
|
|
|
|
| 'datetime'
|
|
|
|
| 'time'
|
|
|
|
| 'binary';
|
2022-03-28 10:01:29 +00:00
|
|
|
|
|
|
|
// Returned by pragma table_info
|
|
|
|
export interface SqliteTableInfo {
|
|
|
|
pk: number;
|
|
|
|
cid: number;
|
|
|
|
name: string;
|
|
|
|
type: string;
|
|
|
|
notnull: number; // 0 | 1
|
|
|
|
dflt_value: string | null;
|
|
|
|
}
|
2022-04-11 06:04:55 +00:00
|
|
|
|
2022-05-24 19:06:54 +00:00
|
|
|
export type BespokeFunction = (
|
|
|
|
db: DatabaseCore,
|
|
|
|
...args: unknown[]
|
|
|
|
) => Promise<unknown>;
|
2023-07-10 09:12:20 +00:00
|
|
|
|
2022-04-18 11:29:20 +00:00
|
|
|
export type SingleValue<T> = {
|
|
|
|
fieldname: string;
|
|
|
|
parent: string;
|
|
|
|
value: T;
|
2022-05-24 19:06:54 +00:00
|
|
|
}[];
|