@iarayan/ch-orm
Version:
A Developer-First ClickHouse ORM with Powerful CLI Tools
165 lines • 6.41 kB
TypeScript
import { Connection } from "../connection/Connection";
import { ConnectionPool } from "../connection/ConnectionPool";
import { ColumnMetadata } from "../decorators/ModelDecorators";
import { QueryBuilder } from "../query/QueryBuilder";
import { QueryOptions, QueryResult } from "../types/connection";
/**
* Base Model class with ORM functionality
* Provides static and instance methods for interacting with ClickHouse tables
*/
export declare abstract class Model {
/**
* Connection provider for database access
*/
private static connectionProvider;
/**
* Set the database connection for all models
* @param connection - ClickHouse connection or connection pool
*/
static setConnection(connection: Connection | ConnectionPool): void;
/**
* Get the database connection
* @returns ClickHouse connection
*/
protected static getConnection(): Connection;
/**
* Get the table name for this model
* @returns Table name
*/
static getTableName(): string;
/**
* Get the column metadata for this model
* @returns Map of property names to column metadata
*/
static getColumns(): Map<string, ColumnMetadata>;
/**
* Get the primary key columns for this model
* @returns Array of primary key column names
*/
static getPrimaryKeys(): string[];
/**
* Create a new query builder for this model
* @returns Query builder instance
*/
static query(): QueryBuilder;
/**
* Get all records from the table
* @param options - Query options
* @returns Promise that resolves to array of model instances
*/
static all<T extends Model>(options?: QueryOptions): Promise<T[]>;
/**
* Find a record by its primary key
* @param id - Primary key value
* @param options - Query options
* @returns Promise that resolves to model instance or null if not found
*/
static find<T extends Model>(id: string | number, options?: QueryOptions): Promise<T | null>;
/**
* Find a record by some conditions or throw an error if not found
* @param id - Primary key value
* @param options - Query options
* @returns Promise that resolves to model instance
* @throws Error if record not found
*/
static findOrFail<T extends Model>(id: string | number, options?: QueryOptions): Promise<T>;
/**
* Find first record matching the conditions
* @param conditions - Conditions to match
* @param options - Query options
* @returns Promise that resolves to model instance or null if not found
*/
static findBy<T extends Model>(conditions: Record<string, any>, options?: QueryOptions): Promise<T | null>;
/**
* Create a new model instance with the given attributes
* @param attributes - Attributes to set on the model
* @returns Model instance
*/
static create<T extends Model>(attributes: Record<string, any>): T;
/**
* Create a new model instance with the given attributes and save it to the database
* @param attributes - Attributes to set on the model
* @param options - Query options
* @returns Promise that resolves to model instance
*/
static createAndSave<T extends Model>(attributes: Record<string, any>, options?: QueryOptions): Promise<T>;
/**
* Convert raw database records to model instances
* @param records - Raw database records
* @returns Array of model instances
*/
protected static hydrate<T extends Model>(records: Record<string, any>[]): T[];
/**
* Count records in the table
* @param options - Query options
* @returns Promise that resolves to record count
*/
static count(options?: QueryOptions): Promise<number>;
/**
* Get the maximum value of a column
* @param column - Column name
* @param options - Query options
* @returns Promise that resolves to maximum value
*/
static max<T = any>(column: string, options?: QueryOptions): Promise<T | null>;
/**
* Get the minimum value of a column
* @param column - Column name
* @param options - Query options
* @returns Promise that resolves to minimum value
*/
static min<T = any>(column: string, options?: QueryOptions): Promise<T | null>;
/**
* Get the sum of values in a column
* @param column - Column name
* @param options - Query options
* @returns Promise that resolves to sum of values
*/
static sum<T = number>(column: string, options?: QueryOptions): Promise<T | null>;
/**
* Get the average of values in a column
* @param column - Column name
* @param options - Query options
* @returns Promise that resolves to average of values
*/
static avg<T = number>(column: string, options?: QueryOptions): Promise<T | null>;
/**
* Insert records into the table
* @param data - Data to insert (single record or array of records)
* @param options - Query options
* @returns Promise that resolves to query result
*/
static insert(data: Record<string, any> | Record<string, any>[], options?: QueryOptions): Promise<QueryResult>;
/**
* Convert the model instance to a database record
* @returns Record with column names and values
*/
toRecord(): Record<string, any>;
/**
* Save the model to the database
* @param options - Query options
* @returns Promise that resolves to query result
*/
save(options?: QueryOptions): Promise<QueryResult>;
/**
* Delete records by condition
* @param conditions - Conditions to match for deletion
* @param options - Query options
* @returns Promise that resolves to query result
*/
static deleteWhere(conditions: Record<string, any>, options?: QueryOptions): Promise<QueryResult>;
/**
* Delete a record by its primary key
* @param id - Primary key value
* @param options - Query options
* @returns Promise that resolves to query result
*/
static deleteById(id: string | number, options?: QueryOptions): Promise<QueryResult>;
/**
* Delete the current model instance from the database
* @param options - Query options
* @returns Promise that resolves to query result
*/
delete(options?: QueryOptions): Promise<QueryResult>;
}
//# sourceMappingURL=Model.d.ts.map