@gftdcojp/ksqldb-orm
Version:
ksqldb-orm - Server-Side TypeScript ORM for ksqlDB with enterprise security extensions
209 lines • 5.87 kB
TypeScript
/**
* サーバーサイド用Database Module
*/
import { KsqlDbConfig, SchemaRegistryConfig, EnhancedPullQueryOptions } from './types';
import { KsqlDbClient } from './ksqldb-client';
import { ResilientKsqlDbConfig } from './resilient-client';
import { ColumnNameTransformConfig } from './utils/column-name-transform';
export interface DatabaseClientConfig {
ksql: KsqlDbConfig;
schemaRegistry: SchemaRegistryConfig;
}
export interface ResilientDatabaseClientConfig {
ksql: ResilientKsqlDbConfig;
schemaRegistry: SchemaRegistryConfig;
}
/**
* サーバー環境用Database クラス
*/
export declare class DatabaseClient {
private ksqlClient;
private initialized;
constructor(config: DatabaseClientConfig);
/**
* データベースを初期化
*/
initialize(): Promise<void>;
/**
* テーブルからデータを取得(Supabaseライク)
*/
from<T = any>(table: string): DatabaseQueryBuilder<T>;
/**
* SQL文を直接実行
*/
sql(query: string, _params?: any[]): Promise<any>;
/**
* ヘルスチェック
*/
health(): Promise<{
status: 'ok' | 'error';
details?: any;
}>;
}
/**
* サーバー環境用クエリビルダー
*/
export declare class DatabaseQueryBuilder<T = any> {
protected tableName: string;
protected ksqlClient: typeof KsqlDbClient;
protected selectFields: string[];
protected whereConditions: any;
protected orderByConditions: any;
protected limitValue?: number;
protected offsetValue?: number;
protected columnTransformConfig?: ColumnNameTransformConfig;
constructor(tableName: string, ksqlClient: typeof KsqlDbClient);
/**
* 列名をクエリ用に変換するヘルパーメソッド
*/
protected transformColumnNameForQuery(columnName: string): string;
/**
* 選択するフィールドを指定
*/
select(fields?: string): this;
/**
* WHERE条件を追加
*/
eq(column: string, value: any): this;
/**
* 不等価条件を追加(NOT EQUAL)
*/
neq(column: string, value: any): this;
/**
* NULL判定条件を追加
*/
isNull(column: string): this;
/**
* NOT NULL条件を追加
*/
isNotNull(column: string): this;
/**
* LIKE条件を追加
*/
like(column: string, pattern: string): this;
/**
* NOT LIKE条件を追加
*/
notLike(column: string, pattern: string): this;
/**
* 範囲条件を追加
*/
gte(column: string, value: any): this;
lte(column: string, value: any): this;
gt(column: string, value: any): this;
lt(column: string, value: any): this;
/**
* BETWEEN条件を追加
*/
between(column: string, min: any, max: any): this;
/**
* NOT BETWEEN条件を追加
*/
notBetween(column: string, min: any, max: any): this;
/**
* IN条件を追加
*/
in(column: string, values: any[]): this;
/**
* NOT IN条件を追加
*/
notIn(column: string, values: any[]): this;
/**
* ORDER BY を追加
*/
order(column: string, ascending?: boolean): this;
/**
* LIMIT を設定
*/
limit(count: number): this;
/**
* OFFSET を設定
*/
offset(count: number): this;
/**
* クエリを実行してデータを取得
*/
execute(): Promise<{
data: T[];
error?: any;
}>;
/**
* 単一レコードを取得
*/
single(): Promise<{
data: T | null;
error?: any;
}>;
/**
* 拡張オプション付きでクエリを実行(リジリエンス機能対応)
*
* 将来的にリジリエンス機能が統合される際に使用
* 現時点では通常のexecute()と同じ動作
*/
executeEnhanced(options?: EnhancedPullQueryOptions): Promise<{
data: T[];
error?: any;
}>;
/**
* データを挿入(Supabaseライク)
*/
insert(values: Partial<T> | Partial<T>[]): Promise<{
data: T | T[] | null;
error?: any;
}>;
/**
* データを更新(Supabaseライク)
*/
update(values: Partial<T>): Promise<{
data: T[];
error?: any;
}>;
/**
* データを削除(Supabaseライク)
*/
delete(): Promise<{
data: any;
error?: any;
}>;
private buildSelectQuery;
private formatValue;
private buildInsertQuery;
private buildBatchInsertQuery;
private buildUpdateQuery;
private buildDeleteQuery;
private buildCondition;
}
/**
* サーバー環境用データベースインスタンスを作成
*/
export declare function createDatabaseClient(config: DatabaseClientConfig): DatabaseClient;
/**
* リジリエント機能付きデータベースクライアントを作成
*
* パーティション再バランシング対応の高可用性Database Client
* 既存のDatabase Clientの代替として使用可能
*
* @param config リジリエント設定を含むデータベース設定
* @returns ResilientKsqlDbClientを内包するラッパー
*/
export declare function createResilientDatabaseClient(config: ResilientDatabaseClientConfig): {
from: (table: string) => {
select: (fields?: string) => any;
eq: (column: string, value: any) => any;
execute: () => Promise<{
data: any[];
error?: any;
}>;
executeEnhanced: (options?: EnhancedPullQueryOptions) => Promise<{
data: any[];
error?: any;
}>;
};
health: () => Promise<{
status: 'healthy' | 'degraded' | 'unhealthy';
details: any;
}>;
getMetrics: () => any;
dispose: () => void;
};
//# sourceMappingURL=database-client.d.ts.map