@aradox/multi-orm
Version:
Type-safe ORM with multi-datasource support, row-level security, and Prisma-like API for PostgreSQL, SQL Server, and HTTP APIs
186 lines • 5.19 kB
TypeScript
import { IR } from '../types/ir';
import { Adapter } from '../types/adapter';
import { Stitcher } from '../runtime/stitcher';
import { MiddlewareChain, QueryContext } from '../types/middleware';
/**
* Model delegate provides type-safe methods for a specific model
*/
export declare class ModelDelegate<T = any> {
private modelName;
private stitcher;
private adapter;
private ir;
private middlewareChain;
private getContext;
constructor(modelName: string, stitcher: Stitcher, adapter: Adapter, ir: IR, middlewareChain: MiddlewareChain, getContext: () => QueryContext);
/**
* Execute query with middleware hooks
*/
private executeWithMiddleware;
findMany(args?: {
where?: any;
select?: any;
include?: any;
orderBy?: any;
skip?: number;
take?: number;
}): Promise<T[]>;
findUnique(args: {
where: any;
select?: any;
include?: any;
}): Promise<T | null>;
findFirst(args?: {
where?: any;
select?: any;
include?: any;
orderBy?: any;
}): Promise<T | null>;
count(args?: {
where?: any;
}): Promise<number>;
create(args: {
data: any;
select?: any;
}): Promise<T>;
createMany(args: {
data: any[];
skipDuplicates?: boolean;
}): Promise<{
count: number;
}>;
update(args: {
where: any;
data: any;
select?: any;
}): Promise<T>;
updateMany(args: {
where?: any;
data: any;
}): Promise<{
count: number;
}>;
delete(args: {
where: any;
select?: any;
}): Promise<T>;
deleteMany(args?: {
where?: any;
}): Promise<{
count: number;
}>;
upsert(args: {
where: any;
create: any;
update: any;
select?: any;
}): Promise<T>;
}
/**
* Generated client with model delegates
*/
export declare class GeneratedClient {
private ir;
private stitcher;
private adapters;
private middlewareChain;
private queryContext;
private delegates;
private datasourceQueryDelegates;
[modelName: string]: any;
constructor(ir: IR, stitcher: Stitcher, adapters: Map<string, Adapter>, middlewareChain: MiddlewareChain, queryContext: QueryContext);
private generateDelegates;
/**
* Generate datasource query delegates for raw SQL queries
* Creates properties like client.main_db.query(sql)
*/
private generateDatasourceQueryDelegates;
/**
* Register middleware for query interception
*
* Example:
* ```typescript
* client.use({
* name: 'tenant-isolation',
* beforeQuery: ({ model, args, context }) => {
* if (context.user?.tenantId) {
* args.where = { ...args.where, tenant_id: context.user.tenantId };
* }
* return args;
* }
* });
* ```
*/
use(middleware: any): void;
/**
* Set query context (user, tenantId, etc.)
* This context is available to all middleware hooks
*
* Example:
* ```typescript
* client.setContext({
* user: { id: 123, tenantId: 456, role: 'admin' }
* });
* ```
*/
setContext(context: QueryContext): void;
/**
* Get current query context
*/
getContext(): QueryContext;
/**
* Get a model delegate by name
*/
model(modelName: string): ModelDelegate;
/**
* Close all adapter connections
*/
$disconnect(): Promise<void>;
/**
* Raw query execution (datasource-specific)
*/
$queryRaw(datasourceName: string, query: string, params?: any[]): Promise<any>;
/**
* Transaction support - Execute multiple operations in a transaction
*
* Example:
* ```typescript
* await client.$transaction(async (tx) => {
* const user = await tx.User.create({ data: { email: 'test@example.com' } });
* const order = await tx.Orders.create({ data: { userId: user.id } });
* return { user, order };
* });
* ```
*
* With options:
* ```typescript
* await client.$transaction(async (tx) => {
* // ...operations
* }, {
* isolationLevel: 'SERIALIZABLE',
* timeout: 10000
* });
* ```
*/
$transaction<T>(callback: (client: GeneratedClient) => Promise<T>, options?: import('../types/adapter').TransactionOptions): Promise<T>;
/**
* Execute a raw SQL query on the first available SQL datasource
*
* Example:
* ```typescript
* const result = await client.generalQuery('SELECT * FROM users WHERE id = $1', [123]);
* console.log(result);
* ```
*
* Note: For MSSQL, use @p1, @p2, etc. instead of $1, $2:
* ```typescript
* const result = await client.generalQuery('SELECT * FROM users WHERE id = @p1', [123]);
* ```
*
* @param sql - The SQL query string
* @param params - Optional query parameters
* @returns Query result rows
*/
generalQuery(sql: string, params?: any[]): Promise<any>;
}
//# sourceMappingURL=generated-client.d.ts.map