multibridge
Version:
A multi-database connection framework with centralized configuration
103 lines (102 loc) • 3.6 kB
TypeScript
/**
* Cassandra ORM adapter for MultiBridge
* Provides an ORM-like interface using cassandra-driver
* Supports: Cassandra
*/
import { Client, types } from "cassandra-driver";
/**
* Model definition interface for Cassandra
*/
export interface CassandraModelDefinition {
tableName: string;
keyspace?: string;
partitionKeys: string[];
clusteringKeys?: string[];
columns: Record<string, string>;
indexes?: string[];
}
/**
* Get or create a Cassandra client for the current tenant
*
* @returns Cassandra Client instance configured for the current tenant
*
* @example
* ```typescript
* await runWithTenant(tenant, async () => {
* const client = await getCassandraClient();
* const result = await client.execute("SELECT * FROM users WHERE id = ?", [userId]);
* });
* ```
*/
export declare function getCassandraClient(): Promise<Client>;
/**
* Execute a CQL query with prepared statement
*
* @param query - CQL query string
* @param params - Query parameters
* @param options - Execution options
* @returns Query result
*/
export declare function executeCQL(query: string, params?: any[], options?: {
consistency?: types.consistencies;
prepare?: boolean;
}): Promise<types.ResultSet>;
/**
* Create a table based on model definition
*
* @param model - Model definition
* @param ifNotExists - Add IF NOT EXISTS clause
*/
export declare function createTable(model: CassandraModelDefinition, ifNotExists?: boolean): Promise<void>;
/**
* Insert a row into a table
*
* @param tableName - Table name
* @param data - Data to insert (column -> value mapping)
* @param keyspace - Optional keyspace (defaults to tenant's keyspace)
* @param ttl - Optional TTL in seconds
*/
export declare function insert(tableName: string, data: Record<string, any>, keyspace?: string, ttl?: number): Promise<types.ResultSet>;
/**
* Select rows from a table
*
* @param tableName - Table name
* @param whereClause - WHERE clause (e.g., "id = ? AND name = ?")
* @param params - Parameters for WHERE clause
* @param keyspace - Optional keyspace (defaults to tenant's keyspace)
* @param limit - Optional LIMIT clause
* @param allowFiltering - Enable ALLOW FILTERING (use with caution)
*/
export declare function select(tableName: string, whereClause?: string, params?: any[], keyspace?: string, limit?: number, allowFiltering?: boolean): Promise<types.ResultSet>;
/**
* Update rows in a table
*
* @param tableName - Table name
* @param data - Data to update (column -> value mapping)
* @param whereClause - WHERE clause (e.g., "id = ?")
* @param whereParams - Parameters for WHERE clause
* @param keyspace - Optional keyspace (defaults to tenant's keyspace)
* @param ttl - Optional TTL in seconds
*/
export declare function update(tableName: string, data: Record<string, any>, whereClause: string, whereParams: any[], keyspace?: string, ttl?: number): Promise<types.ResultSet>;
/**
* Delete rows from a table
*
* @param tableName - Table name
* @param whereClause - WHERE clause (e.g., "id = ?")
* @param params - Parameters for WHERE clause
* @param keyspace - Optional keyspace (defaults to tenant's keyspace)
*/
export declare function remove(tableName: string, whereClause: string, params: any[], keyspace?: string): Promise<types.ResultSet>;
/**
* Close Cassandra client for a specific tenant
*/
export declare function closeCassandraClient(tenant?: {
appid: string;
orgid: string;
appdbname: string;
}): Promise<void>;
/**
* Close all Cassandra clients
*/
export declare function closeAllCassandraClients(): Promise<void>;