epic-sql
Version:
A Simple But Powerful SQL ORM!!!
76 lines (75 loc) • 3.69 kB
TypeScript
import { Query, QueryInterface, ConditionComparison, Sorting, DefaultValueType, QueryFunction } from "epic-sql-query";
import { BaseSchema } from "./base-schema";
import { Connection } from "./connection";
import { EpicSQLManager } from "./manager";
export { QueryFunction } from "epic-sql-query";
export declare type Condition<T> = T extends Array<infer B> ? B extends BaseSchema ? Conditions<B> : DefaultValueType | ConditionComparison<DefaultValueType> : T extends object ? DefaultValueType | ConditionComparison<DefaultValueType> : T | ConditionComparison<T, DefaultValueType> | null | undefined;
export declare type Conditions<T extends BaseSchema> = {
[key in keyof T]?: Condition<T[key]>;
};
export declare class Operator<T extends typeof BaseSchema, R extends typeof BaseSchema, C extends Connection, S extends Array<typeof BaseSchema>> {
protected Schema: T;
protected Relations: R[];
protected Manager: EpicSQLManager<C, S>;
protected SchemaInstance?: T["prototype"];
protected QueryBuilder?: Query<any>;
protected prepareCreate(input: T["prototype"]): Promise<Record<string, any>>;
protected prepareUpdate(input: T["prototype"]): Promise<Record<string, any>>;
protected resolveSelect<T extends Record<string, any>>(data: T[]): T["prototype"][];
protected conditions(type: "where" | "having", ...conditions: Conditions<T["prototype"]>[]): this;
constructor(Schema: T, Relations: R[], Manager: EpicSQLManager<C, S>);
getSchema(): T["prototype"];
getQueryBuilder(): Query<any>;
create(input: T["prototype"], options?: {
returnStatements?: false;
}): Promise<T["prototype"]>;
create(input: T["prototype"], options?: {
returnStatements?: true;
}): Promise<QueryInterface[]>;
update(input: T["prototype"], options?: {
throwError?: boolean;
returnStatements?: false;
}): Promise<T["prototype"]>;
update(input: T["prototype"], options?: {
throwError?: boolean;
returnStatements?: true;
}): Promise<QueryInterface[]>;
select(columns?: (`${string}.${string}` | QueryFunction)[], options?: {
throwError?: boolean;
returnStatements?: false;
}): Promise<T["prototype"][]>;
select(columns?: (`${string}.${string}` | QueryFunction)[], options?: {
throwError?: boolean;
returnStatements?: true;
}): Promise<QueryInterface[]>;
delete(schemas: T[], options?: {
throwError?: boolean;
returnStatements?: false;
}): Promise<T["prototype"][]>;
delete(schemas: T[], options?: {
throwError?: boolean;
returnStatements?: true;
}): Promise<QueryInterface[]>;
count(column: keyof T["prototype"], options?: {
throwError?: boolean;
returnStatements?: false;
}): Promise<number>;
count(column: keyof T["prototype"], options?: {
throwError?: boolean;
returnStatements?: true;
}): Promise<QueryInterface[]>;
avg(column: keyof T["prototype"], options?: {
throwError?: boolean;
returnStatements?: false;
}): Promise<number>;
avg(column: keyof T["prototype"], options?: {
throwError?: boolean;
returnStatements?: true;
}): Promise<QueryInterface[]>;
search(target: string, ...columns: `${string}.${string}`[]): this;
where(...conditions: Conditions<T["prototype"]>[]): this;
group(...columns: `${string}.${string}`[]): this;
having(...conditions: Conditions<T["prototype"]>[]): this;
order(columns: `${string}.${string}`[], sort: Sorting): this;
limit(number: number, offset?: number): this;
}