qeasy
Version:
Query Easy: Simple SQL helper like Mongoose for MySQL/MariaDB
71 lines (58 loc) • 1.49 kB
TypeScript
export interface DBConfig {
host?: string;
user: string;
password: string;
database: string;
port?: number;
}
export function connectDB(config: DBConfig): void;
export function checkConnection(): any;
export function insert(
table: string,
data: Record<string, any>
): Promise<any>;
export function findAll(
table: string
): Promise<any[]>;
export function findById(
table: string,
idField: string,
id: string | number
): Promise<any>;
export function findByIdAndUpdate(
table: string,
idField: string,
id: string | number,
data: Record<string, any>
): Promise<any>;
export function findByIdAndDelete(
table: string,
idField: string,
id: string | number
): Promise<any>;
export interface JoinOption {
table: string;
as?: string;
type?: "INNER" | "LEFT" | "RIGHT";
on: { [key: string]: string }; // e.g., { "u.id": "o.user_id" }
}
export interface WhereCondition {
column: string; // e.g., "u.id"
operator?: string; // e.g., '=', '>', '<', 'LIKE'
value: any;
}
export interface OrderByOption {
column: string; // e.g., "u.name"
direction?: "ASC" | "DESC";
}
export interface FindWithJoinsOptions {
table: string;
as?: string;
selectedColumns?: string[];
joins?: JoinOption[];
where?: WhereCondition[];
orderBy?: OrderByOption[];
limit?: number;
offset?: number;
}
export function findWithJoins(options: FindWithJoinsOptions): Promise<any[]>;