54 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-06-17 16:17:15 +02:00
type BooleanWhere<T> = {
$and?: WhereParams<T>[];
$or?: WhereParams<T>[];
$not?: WhereParams<T>;
};
type WhereParams<T> = {
[K in keyof T]?: T[K];
} &
BooleanWhere<T>;
type Sortables<T> = {
// check sortable
[P in keyof T]: P;
}[keyof T];
type Direction = 'asc' | 'ASC' | 'DESC' | 'desc';
type FindParams<T> = {
select?: (keyof T)[];
// TODO: add nested operators & relations
where?: WhereParams<T>;
limit?: number;
offset?: number;
orderBy?: // TODO: add relations
| Sortables<T>
| Sortables<T>[]
| { [K in Sortables<T>]?: Direction }
| { [K in Sortables<T>]?: Direction }[];
};
interface QueryFromContentType<T extends keyof AllTypes> {
findOne(params: FindParams<AllTypes[T]>): AllTypes[T];
findMany(params: FindParams<AllTypes[T]>): AllTypes[T][];
}
interface ModelConfig {
tableName: string;
[k: string]: any;
}
2021-06-28 12:34:29 +02:00
interface ConnectionConfig {}
interface DatabaseConfig {
connection: ConnectionConfig;
models: ModelConfig[];
}
2021-06-17 16:17:15 +02:00
export class Database {
static transformContentTypes(contentTypes: any[]): ModelConfig[];
2021-06-28 12:34:29 +02:00
static init(config: DatabaseConfig): Database;
2021-06-17 16:17:15 +02:00
query<T extends keyof AllTypes>(uid: T): QueryFromContentType<T>;
}