@evolplus/evo-utils
Version:
Simple utilities solution.
33 lines (32 loc) • 1.24 kB
TypeScript
import { Connection, Pool } from "mysql2/promise";
export type Entity<T extends readonly string[]> = {
[key in T[number]]: any;
};
export type ComrarisonOperator = '=' | '<' | '<=' | '>' | '>=' | '!=';
export declare class EntityRepository<T extends readonly string[]> {
private conn;
private table;
private primaryKey;
private cache;
private dbPK;
private data2Db;
private db2Data;
constructor(conn: Pool | Connection, table: string, fields: T, primaryKey: T[number], cacheSize?: number);
get(id: string): Promise<Entity<T> | undefined>;
put(entity: Entity<T>): Promise<void>;
delete(id: string): Promise<void>;
query(field: T[number], operator: ComrarisonOperator, value: any): Promise<Entity<T>[]>;
}
export declare class StaticRepository<T extends readonly string[]> {
private conn;
private table;
private primaryKey;
private values;
private promiseReady;
constructor(conn: Pool | Connection, table: string, fields: T, primaryKey: T[number]);
waitForReady(): Promise<void>;
get(id: string): Entity<T> | undefined;
getAll(): Entity<T>[];
private fetchAll;
query(field: T[number], operator: ComrarisonOperator, value: any): Entity<T>[];
}