Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@singlestore/client

Package Overview
Dependencies
Maintainers
0
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@singlestore/client - npm Package Compare versions

Comparing version 0.0.31 to 0.0.32

781

dist/index.d.ts

@@ -6,56 +6,13 @@ import { AnyAI, CreateChatCompletionResult } from '@singlestore/ai';

/**
* Configuration object for initializing a database connection.
*
* Extends `Partial<Omit<PoolOptions, "name" | "database">>` to allow the configuration of any `PoolOptions`
* properties except `name` and `database`, which are omitted.
*/
interface ConnectionConfig extends Partial<Omit<PoolOptions, "name" | "database">> {
}
/**
* Class representing a database connection, providing methods to manage the connection pool.
*
* @property {Pool} client - The MySQL connection pool created with the provided configuration.
*/
declare class Connection {
config: ConnectionConfig;
client: Pool;
/**
* Constructs a new `Connection` instance and initializes the connection pool.
*
* @param {ConnectionConfig} config - The configuration object for the connection pool.
*/
constructor(config: ConnectionConfig);
/**
* Factory method to create a new `Connection` instance.
*
* @param {ConnectionConfig} config - The configuration object for the connection pool.
*
* @returns {Connection} A new `Connection` instance.
*/
static create(config: ConnectionConfig): Connection;
/**
* Disconnects from the database by closing the connection pool.
*
* @returns {Promise<void>} A promise that resolves when the connection pool is closed.
*/
disconnect(): Promise<void>;
}
/**
* Represents a type for database column definitions. This is currently set to `any`
* to allow flexibility in defining various column types.
*/
type ColumnType = any;
/**
* Interface representing the schema of a database column.
*
* @property {string} name - The name of the column.
* @property {string} type - The SQL data type of the column.
* @property {boolean} [nullable] - Indicates whether the column allows NULL values.
* @property {boolean} [primaryKey] - Indicates whether the column is a primary key.
* @property {boolean} [autoIncrement] - Indicates whether the column is auto-incremented.
* @property {any} [default] - The default value for the column.
* @property {string[]} [clauses] - Additional SQL clauses for the column definition.
*/
interface ColumnSchema {

@@ -70,14 +27,2 @@ name: string;

}
/**
* Interface representing information about a column in the database.
*
* @typeParam T - A string literal representing the column name.
*
* @property {T} name - The name of the column.
* @property {string} type - The SQL data type of the column.
* @property {string} null - Indicates whether the column allows NULL values (`"YES"` or `"NO"`).
* @property {string} key - The key type of the column (`"PRI"` for primary key, `"UNI"` for unique key, etc.).
* @property {any} default - The default value for the column.
* @property {string} extra - Any extra information about the column (e.g., `auto_increment`).
*/
interface ColumnInfo<T extends string = string> {

@@ -91,5 +36,2 @@ name: T;

}
/**
* Class representing a database column and providing methods to manage its schema.
*/
declare class Column {

@@ -101,82 +43,34 @@ private _connection;

private _path;
/**
* Constructs a new `Column` instance.
*
* @param {Connection} _connection - The database connection used to execute queries.
* @param {string} databaseName - The name of the database containing the column.
* @param {string} tableName - The name of the table containing the column.
* @param {string} name - The name of the column.
*/
constructor(_connection: Connection, databaseName: string, tableName: string, name: string);
/**
* Normalizes raw database column information into a structured `ColumnInfo` object.
*
* @typeParam T - A string literal representing the column name.
*
* @param {any} info - Raw column information from the database.
*
* @returns {ColumnInfo<T>} A structured `ColumnInfo` object.
*/
static normalizeInfo<T extends string = string>(info: any): ColumnInfo<T>;
/**
* Converts a `ColumnSchema` object into an SQL column definition string.
*
* @param {ColumnSchema} schema - The schema of the column to be converted.
*
* @returns {string} An SQL string representing the column definition.
*/
static schemaToClauses(schema: ColumnSchema): string;
/**
* Adds a new column to a specified table in the database.
*
* @param {Connection} connection - The database connection used to execute the query.
* @param {string} databaseName - The name of the database where the table is located.
* @param {string} tableName - The name of the table where the column will be added.
* @param {ColumnSchema} schema - The schema of the column to be added.
*
* @returns {Promise<Column>} A promise that resolves to the created `Column` instance.
*/
static add(connection: Connection, databaseName: string, tableName: string, schema: ColumnSchema): Promise<Column>;
/**
* Drops a column from a specified table in the database.
*
* @param {Connection} connection - The database connection used to execute the query.
* @param {string} databaseName - The name of the database where the table is located.
* @param {string} tableName - The name of the table containing the column.
* @param {string} name - The name of the column to be dropped.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the column is dropped.
*/
static drop(connection: Connection, databaseName: string, tableName: string, name: string): Promise<[ResultSetHeader, FieldPacket[]]>;
/**
* Retrieves information about the current column from the database.
*
* @returns {Promise<ColumnInfo<string>>} A promise that resolves to the `ColumnInfo` object containing details about the column.
*/
showInfo(): Promise<ColumnInfo<string>>;
/**
* Drops the current column from the table.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the column is dropped.
*/
drop(): Promise<[ResultSetHeader, FieldPacket[]]>;
/**
* Modifies the current column in the table based on the provided schema.
*
* @param {Partial<Omit<ColumnSchema, "name">>} schema - The schema containing modifications to be applied to the column.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the column is modified.
*/
modify(schema: Partial<Omit<ColumnSchema, "name">>): Promise<[ResultSetHeader, FieldPacket[]]>;
/**
* Renames the current column in the table.
*
* @param {string} newName - The new name for the column.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the column is renamed.
*/
rename(newName: string): Promise<[ResultSetHeader, FieldPacket[]]>;
}
type SelectClause<TTableName extends string, TTableType extends TableType, TDatabaseType extends DatabaseType, _TTableColumns = TTableType["columns"]> = ((string & {}) | keyof _TTableColumns)[];
type MergeUnion<T> = (T extends any ? (i: T) => void : never) extends (i: infer U) => void ? {
[K in keyof U]: U[K];
} : never;
type JoinType = "INNER" | "LEFT" | "RIGHT" | "FULL";
type JoinOperator = "=" | "<" | ">" | "<=" | ">=" | "!=";
type JoinClause<TTableType extends TableType, TDatabaseType extends DatabaseType, TAs extends string> = {
[K in keyof TDatabaseType["tables"]]: {
type?: JoinType;
table: K;
as: TAs;
on: [
(string & {}) | keyof TTableType["columns"],
JoinOperator,
(string & {}) | keyof TDatabaseType["tables"][K]["columns"]
];
};
}[keyof TDatabaseType["tables"]];
type ExtractJoinClauseColumns<TTableType extends TableType, TDatabaseType extends DatabaseType, TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[]> = {
[K in TJoinClauses[number] as K["as"]]: `${K["as"]}.${Extract<keyof TDatabaseType["tables"][K["table"]]["columns"], string>}`;
}[TJoinClauses[number]["as"]];
type SelectClause<TTableType extends TableType, TDatabaseType extends DatabaseType, TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[]> = ("*" | keyof TTableType["columns"] | ExtractJoinClauseColumns<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses> | `${TJoinClauseAs}.*` | `${string} AS ${string}`)[];
type WhereOperator<TColumnValue> = TColumnValue extends string ? {

@@ -198,40 +92,57 @@ eq?: TColumnValue;

} : never;
type WhereClause<TTableName extends string, TTableType extends TableType, TDatabaseType extends DatabaseType, _TTableColumns = TTableType["columns"]> = {
[K in keyof _TTableColumns]?: WhereOperator<_TTableColumns[K]> | _TTableColumns[K];
type WhereClause<TTableType extends TableType, TDatabaseType extends DatabaseType, TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[]> = ({
[K in keyof TTableType["columns"]]?: WhereOperator<TTableType["columns"][K]> | TTableType["columns"][K];
} & {
OR?: WhereClause<TTableName, TTableType, TDatabaseType>[];
NOT?: WhereClause<TTableName, TTableType, TDatabaseType>;
[K in TJoinClauses[number] as K["as"]]: {
[C in keyof TDatabaseType["tables"][K["table"]]["columns"] as `${K["as"]}.${Extract<C, string>}`]?: WhereOperator<TDatabaseType["tables"][K["table"]]["columns"][C]> | TDatabaseType["tables"][K["table"]]["columns"][C];
};
}[TJoinClauses[number]["as"]]) & {
OR?: WhereClause<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>[];
NOT?: WhereClause<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>;
};
type GroupByClause<TTableName extends string, TTableType extends TableType, TDatabaseType extends DatabaseType, _TTableColumns = TTableType["columns"]> = ((string & {}) | keyof _TTableColumns)[];
type GroupByClause<TTableType extends TableType, TDatabaseType extends DatabaseType, TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[]> = ((string & {}) | keyof TTableType["columns"] | ExtractJoinClauseColumns<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>)[];
type OrderByDirection = "asc" | "desc";
type OrderByClause<TTableName extends string, TTableType extends TableType, TDatabaseType extends DatabaseType, _TTableColumns = TTableType["columns"]> = {
[K in string & {}]: OrderByDirection;
} & {
[K in keyof _TTableColumns]?: OrderByDirection;
type OrderByClause<TTableType extends TableType, TDatabaseType extends DatabaseType, TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[]> = {
[K in (string & {}) | keyof TTableType["columns"] | Extract<ExtractJoinClauseColumns<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>, string>]?: OrderByDirection;
};
interface QueryBuilderParams<TTableName extends string, TTableType extends TableType, TDatabaseType extends DatabaseType> {
select?: SelectClause<TTableName, TTableType, TDatabaseType>;
where?: WhereClause<TTableName, TTableType, TDatabaseType>;
groupBy?: GroupByClause<TTableName, TTableType, TDatabaseType>;
orderBy?: OrderByClause<TTableName, TTableType, TDatabaseType>;
interface QueryBuilderParams<TTableType extends TableType, TDatabaseType extends DatabaseType, TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[], TSelectClause extends SelectClause<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>> {
join?: TJoinClauses;
select?: TSelectClause;
where?: WhereClause<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>;
groupBy?: GroupByClause<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>;
orderBy?: OrderByClause<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>;
limit?: number;
offset?: number;
}
type AnyQueryBuilderParams = QueryBuilderParams<any, any, any>;
type ExtractQuerySelectedColumn<TTableName extends string, TDatabaseType extends DatabaseType, TParams extends AnyQueryBuilderParams | undefined, _Table extends TDatabaseType["tables"][TTableName] = TDatabaseType["tables"][TTableName]> = TParams extends AnyQueryBuilderParams ? TParams["select"] extends (keyof _Table["columns"])[] ? Pick<_Table["columns"], TParams["select"][number]> : _Table["columns"] : _Table["columns"];
declare class QueryBuilder<TName extends string, TTableType extends TableType, TDatabaseType extends DatabaseType> {
type AnyQueryBuilderParams = QueryBuilderParams<any, any, any, any, any>;
type ExtractSelectedQueryColumns<TTableType extends TableType, TDatabaseType extends DatabaseType, TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[], TSelectClause extends SelectClause<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>> = TSelectClause extends (infer TColumn)[] ? MergeUnion<TColumn extends "*" ? TTableType["columns"] : TColumn extends keyof TTableType["columns"] ? {
[K in TColumn]: TTableType["columns"][K];
} : TColumn extends `${infer TJoinAs}.${infer TJoinColumn}` ? TJoinAs extends TJoinClauseAs ? TJoinColumn extends keyof TDatabaseType["tables"][Extract<TJoinClauses[number], {
as: TJoinAs;
}>["table"]]["columns"] ? {
[K in `${TJoinAs}_${TJoinColumn}`]: TDatabaseType["tables"][Extract<TJoinClauses[number], {
as: TJoinAs;
}>["table"]]["columns"][TJoinColumn];
} : never : never : TColumn extends `${infer TAlias}.*` ? TAlias extends TJoinClauseAs ? TDatabaseType["tables"][Extract<TJoinClauses[number], {
as: TAlias;
}>["table"]]["columns"] : never : TColumn extends `${string} AS ${infer TAs}` ? {
[K in TAs]: any;
} : never> : never;
declare class QueryBuilder<TTableType extends TableType, TDatabaseType extends DatabaseType> {
private _databaseName;
private _tableName;
constructor(_databaseName: string, _tableName: TName);
buildSelectClause(select?: SelectClause<any, any, any>): string;
buildFromClause(): string;
constructor(_databaseName: string, _tableName: string);
buildJoinClause<TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[]>(clauses?: TJoinClauses): string;
buildSelectClause<TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[]>(clauses?: SelectClause<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>, joinClauses?: TJoinClauses): string;
buildFromClause(hasJoinClauses?: boolean): string;
buildWhereCondition(column: string, operator: string, value: any): string;
buildWhereClause(conditions?: WhereClause<any, any, any>): string;
buildGroupByClause(columns?: GroupByClause<any, any, any>): string;
buildOrderByClause(clauses?: OrderByClause<any, any, any>): string;
buildWhereClause<TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[]>(clauses?: WhereClause<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>, joinClauses?: TJoinClauses): string;
buildGroupByClause<TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[]>(clauses?: GroupByClause<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>, joinClauses?: TJoinClauses, aliases?: string[]): string;
buildOrderByClause<TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[]>(clauses?: OrderByClause<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>, joinClauses?: TJoinClauses, aliases?: string[]): string;
buildLimitClause(limit?: number): string;
buildOffsetClause(offset?: number): string;
buildClauses<TParams extends QueryBuilderParams<TName, TTableType, TDatabaseType>>(params?: TParams): {
buildClauses<TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[], TSelectClause extends SelectClause<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>>(params?: QueryBuilderParams<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses, TSelectClause>): {
select: string;
from: string;
join: string;
where: string;

@@ -243,27 +154,11 @@ groupBy: string;

};
buildQuery<TParams extends QueryBuilderParams<TName, TTableType, TDatabaseType>>(params?: TParams): string;
buildQuery<TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[], TSelectClause extends SelectClause<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>>(params?: QueryBuilderParams<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses, TSelectClause>): string;
}
/**
* Interface representing the structure of a table type, including its columns.
*
* @property {Record<string, ColumnType>} columns - A record where the keys are column names and the values are their respective column types.
*/
interface TableType {
name: string;
columns: Record<string, ColumnType>;
}
/**
* Interface representing the schema of a table, including its columns, primary keys, full-text keys, and additional clauses.
*
* @typeParam TName - A type extending `string` that defines the name of the table.
* @typeParam TType - A type extending `TableType` that defines the structure of the table.
*
* @property {TName} name - The name of the table.
* @property {Object} columns - An object where each key is a column name and each value is the schema of that column, excluding the name.
* @property {string[]} [primaryKeys] - An optional array of column names that form the primary key.
* @property {string[]} [fulltextKeys] - An optional array of column names that form full-text keys.
* @property {string[]} [clauses] - An optional array of additional SQL clauses for the table definition.
*/
interface TableSchema<TName extends string, TType extends TableType> {
name: TName;
interface TableSchema<TType extends TableType> {
name: TType["name"];
columns: {

@@ -276,21 +171,5 @@ [K in keyof TType["columns"]]: Omit<ColumnSchema, "name">;

}
/**
* Interface representing basic information about a table.
*
* @typeParam TName - A string literal representing the table name.
*
* @property {TName} name - The name of the table.
*/
interface TableInfo<TName extends string> {
name: TName;
}
/**
* Interface extending `TableInfo` to include additional details about the table's type, distribution, and storage.
*
* @typeParam TName - A string literal representing the table name.
*
* @property {string} tableType - The type of the table.
* @property {boolean} distributed - Indicates whether the table is distributed.
* @property {string} storageType - The storage type of the table.
*/
interface TableInfoExtended<TName extends string> extends TableInfo<TName> {

@@ -301,291 +180,54 @@ tableType: string;

}
/**
* Type representing the name of a column within a specific table type.
*
* @typeParam TType - The type of the table.
*/
type TableColumnName<TType extends TableType> = Extract<keyof TType["columns"], string>;
/**
* Type representing a key used for vector scoring in vector search queries.
*/
type VectorScoreKey = "v_score";
/**
* Class representing a table in SingleStore, providing methods to manage its columns, query data, and perform vector search.
*
* @typeParam TDatabaseType - The type of the database, which extends `DatabaseType`.
* @typeParam TType - The type of the table, which extends `TableType`.
* @typeParam TAi - The type of AI functionalities integrated with the table, which can be undefined.
*
* @property {Connection} _connection - The connection to the database containing the table.
* @property {string} databaseName - The name of the database containing the table.
* @property {string} name - The name of the table.
* @property {U} [ai] - Optional AI functionalities associated with the table.
* @property {string} _path - The full path of the table, composed of the database name and table name.
* @property {VectorScoreKey} vScoreKey - The key used for vector scoring in vector search queries, defaulting to `"v_score"`.
*/
declare class Table<TName extends string = string, TType extends TableType = TableType, TDatabaseType extends DatabaseType = DatabaseType, TAi extends AnyAI | undefined = undefined> {
declare class Table<TTableType extends TableType = TableType, TDatabaseType extends DatabaseType = DatabaseType, TAi extends AnyAI | undefined = undefined> {
private _connection;
databaseName: string;
name: TName;
name: TTableType["name"];
private _ai?;
private _path;
vScoreKey: VectorScoreKey;
constructor(_connection: Connection, databaseName: string, name: TName, _ai?: TAi | undefined);
constructor(_connection: Connection, databaseName: string, name: TTableType["name"], _ai?: TAi | undefined);
private get ai();
/**
* Normalizes raw table information into a structured object.
*
* @typeParam TName - A string literal representing the table name.
* @typeParam TExtended - A boolean indicating whether extended information is requested.
*
* @param {any} info - The raw table information to normalize.
* @param {TExtended} [extended] - Whether to include extended information.
*
* @returns {TExtended extends true ? TableInfoExtended<TName> : TableInfo<TName>} A structured object containing normalized table information.
*/
static normalizeInfo<TName extends string, TExtended extends boolean>(info: any, extended?: TExtended): TExtended extends true ? TableInfoExtended<TName> : TableInfo<TName>;
/**
* Converts a `TableSchema` object into an SQL table definition string.
*
* @param {TableSchema<any>} schema - The schema of the table to be converted.
*
* @returns {string} An SQL string representing the table definition.
*/
static schemaToClauses(schema: TableSchema<any, any>): string;
/**
* Creates a new table in the database with the specified schema.
*
* @typeParam TName - The name of the table, which extends `string`.
* @typeParam TType - The type of the table, which extends `TableType`.
* @typeParam TDatabaseType - The type of the database, which extends `DatabaseType`.
* @typeParam TAi - The type of AI functionalities integrated with the table, which can be undefined.
*
* @param {Connection} connection - The connection to the database.
* @param {string} databaseName - The name of the database where the table will be created.
* @param {TableSchema<TType>} schema - The schema defining the structure of the table.
* @param {TAi} [ai] - Optional AI functionalities to associate with the table.
*
* @returns {Promise<Table<TName, TType, TDatabaseType, TAi>>} A promise that resolves to the created `Table` instance.
*/
static create<TName extends string = string, TType extends TableType = TableType, TDatabaseType extends DatabaseType = DatabaseType, TAi extends AnyAI | undefined = undefined>(connection: Connection, databaseName: string, schema: TableSchema<TName, TType>, ai?: TAi): Promise<Table<TName, TType, TDatabaseType, TAi>>;
/**
* Drops an existing table from the database by name.
*
* @param {Connection} connection - The connection to the database.
* @param {string} databaseName - The name of the database where the table is located.
* @param {string} name - The name of the table to drop.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the table is dropped.
*/
static schemaToClauses(schema: TableSchema<TableType>): string;
static create<TType extends TableType = TableType, TDatabaseType extends DatabaseType = DatabaseType, TAi extends AnyAI | undefined = undefined>(connection: Connection, databaseName: string, schema: TableSchema<TType>, ai?: TAi): Promise<Table<TType, TDatabaseType, TAi>>;
static drop(connection: Connection, databaseName: string, name: string): Promise<[ResultSetHeader, FieldPacket[]]>;
/**
* Retrieves information about the table, optionally including extended details.
*
* @typeParam TExtended - A boolean indicating whether extended information is requested.
*
* @param {TExtended} [extended] - Whether to include extended information.
*
* @returns {Promise<TExtended extends true ? TableInfoExtended<string> : TableInfo<string>>} A promise that resolves to the table information.
*/
showInfo<TExtended extends boolean = false>(extended?: TExtended): Promise<TExtended extends true ? TableInfoExtended<string> : TableInfo<string>>;
/**
* Drops the current table from the database.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the table is dropped.
*/
drop(): Promise<[ResultSetHeader, FieldPacket[]]>;
/**
* Retrieves a `Column` instance representing a specific column in the table.
*
* @param {TableColumnName<TType> | (string & {})} name - The name of the column to retrieve.
*
* @returns {Column} A `Column` instance representing the specified column.
*/
column(name: TableColumnName<TType> | (string & {})): Column;
/**
* Retrieves information about all columns in the table.
*
* @returns {Promise<ColumnInfo<TableColumnName<TType>>[]>} A promise that resolves to an array of column information objects.
*/
showColumnsInfo(): Promise<ColumnInfo<TableColumnName<TType>>[]>;
/**
* Adds a new column to the table with the specified schema.
*
* @param {ColumnSchema} schema - The schema defining the structure of the column to be added.
*
* @returns {Promise<Column>} A promise that resolves to the created `Column` instance.
*/
column(name: TableColumnName<TTableType> | (string & {})): Column;
showColumnsInfo(): Promise<ColumnInfo<TableColumnName<TTableType>>[]>;
addColumn(schema: ColumnSchema): Promise<Column>;
/**
* Drops a specific column from the table by name.
*
* @param {TableColumnName<TType> | (string & {})} name - The name of the column to drop.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the column is dropped.
*/
dropColumn(name: TableColumnName<TType> | (string & {})): Promise<[ResultSetHeader, FieldPacket[]]>;
/**
* Truncates the table, removing all rows while keeping the table structure intact.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the table is truncated.
*/
dropColumn(name: TableColumnName<TTableType> | (string & {})): Promise<[ResultSetHeader, FieldPacket[]]>;
truncate(): Promise<[ResultSetHeader, FieldPacket[]]>;
/**
* Renames the current table to a new name.
*
* @param {string} newName - The new name for the table.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the table is renamed.
*/
rename(newName: string): Promise<[ResultSetHeader, FieldPacket[]]>;
/**
* Inserts one or more rows into the table.
*
* @param {Partial<TType["columns"]> | Partial<TType["columns"]>[]} values - The values to insert into the table. Can be a single row or an array of rows.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]][]>} A promise that resolves to an array of `ResultSetHeader` objects for each inserted row.
*/
insert(values: Partial<TType["columns"]> | Partial<TType["columns"]>[]): Promise<[ResultSetHeader, FieldPacket[]][]>;
/**
* Finds rows from the table based on the specified query arguments.
*
* @typeParam TParams - The type of the query builder arguments.
*
* @param {TParams} params - The arguments defining the query, including selected columns, filters, and other options.
*
* @returns {Promise<(ExtractQuerySelectedColumn<TName, TDatabaseType, TParams> & RowDataPacket)[]>} A promise that resolves to an array of selected rows.
*/
find<TParams extends QueryBuilderParams<TName, TType, TDatabaseType>>(params?: TParams): Promise<(ExtractQuerySelectedColumn<TName, TDatabaseType, TParams> & RowDataPacket)[]>;
/**
* Updates rows in the table based on the specified values and filters.
*
* @param {Partial<TType["columns"]>} values - The values to update in the table.
* @param {WhereClause<TName, TDatabaseType>} where - The where clause to apply to the update query.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the update is complete.
*/
update(values: Partial<TType["columns"]>, where: WhereClause<TName, TType, TDatabaseType>): Promise<[ResultSetHeader, FieldPacket[]]>;
/**
* Deletes rows from the table based on the specified filters. If no filters are provided, the table is truncated.
*
* @param {WhereClause<TName, TDatabaseType>} [where] - The where clause to apply to the delete query.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the delete operation is complete.
*/
delete(where?: WhereClause<TName, TType, TDatabaseType>): Promise<[ResultSetHeader, FieldPacket[]]>;
/**
* Performs a vector search on the table using a prompt and a specified vector column.
*
* This method generates an embedding for the provided prompt, then performs a vector similarity search
* using the specified vector column of the table. The search results are ordered by vector similarity score
* in descending order, unless an additional ordering is specified in the query builder parameters.
*
* @typeParam TSearch - The parameters required for the vector search, including the prompt, vector column,
* and optional embedding parameters specific to the AI model being used.
* @typeParam TParams - The query builder parameters used to refine the search query, such as filters,
* groupings, orderings, limits, and offsets.
*
* @param {TParams} params - The search parameters object containing:
* - `prompt`: The search prompt to be converted into an embedding.
* - `vectorColumn`: The name of the vector column in the table to compare against the prompt embedding.
* - `embeddingParams` (optional): Additional parameters for creating the prompt embedding, if supported by the AI model.
* @param {TQueryParams} [queryParams] - Optional query builder parameters to refine the search, such as filters,
* groupings, orderings, limits, and offsets.
*
* @returns {Promise<(ExtractQuerySelectedColumn<TName, TDatabaseType, TQueryParams> & { v_score: number } & RowDataPacket)[]>}
* A promise that resolves to an array of rows matching the vector search criteria, each row including
* the selected columns and a vector similarity score.
*/
vectorSearch<TParams extends {
insert(values: Partial<TTableType["columns"]> | Partial<TTableType["columns"]>[]): Promise<[ResultSetHeader, FieldPacket[]][]>;
find<TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[], TSelectClause extends SelectClause<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>>(params?: QueryBuilderParams<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses, TSelectClause>): Promise<(ExtractSelectedQueryColumns<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses, TSelectClause> & RowDataPacket)[]>;
update(values: Partial<TTableType["columns"]>, where: WhereClause<TTableType, TDatabaseType, any, any>): Promise<[ResultSetHeader, FieldPacket[]]>;
delete(where?: WhereClause<TTableType, TDatabaseType, any, any>): Promise<[ResultSetHeader, FieldPacket[]]>;
vectorSearch<TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[], TSelectClause extends SelectClause<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>, TParams extends {
prompt: string;
vectorColumn: TableColumnName<TType>;
vectorColumn: TableColumnName<TTableType>;
embeddingParams?: TAi extends AnyAI ? Parameters<TAi["embeddings"]["create"]>[1] : never;
}, TQueryParams extends QueryBuilderParams<TName, TType, TDatabaseType>>(params: TParams, queryParams?: TQueryParams): Promise<(ExtractQuerySelectedColumn<TName, TDatabaseType, TQueryParams> & {
}>(params: TParams, queryParams?: QueryBuilderParams<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses, TSelectClause>): Promise<(ExtractSelectedQueryColumns<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses, TSelectClause> & {
v_score: number;
} & RowDataPacket)[]>;
/**
* Creates a chat completion based on a provided prompt, system role, and optional template.
*
* This method first performs a vector search to find the most relevant context for the given prompt.
* It then formats the prompt using a template and generates a chat completion using an AI model.
* The system role can be customized to guide the AI's behavior during the completion.
*
* @typeParam TParams - The parameters required to create a chat completion, including the prompt, vector search parameters,
* optional system role, template, and additional parameters specific to the AI model being used.
* @typeParam TQueryParams - The query builder parameters used to refine the vector search query, such as filters,
* groupings, orderings, limits, and offsets.
*
* @param {TParams} params - The parameters object containing:
* - `prompt`: The initial user prompt to generate a response for.
* - `systemRole` (optional): The system role for guiding the AI's behavior during the chat completion.
* - `template` (optional): A template to structure the prompt for the chat completion.
* - `vectorColumn`: The name of the vector column to be used in the vector search.
* - `embeddingParams` (optional): Additional parameters for creating the prompt embedding, if supported by the AI model.
* - Additional parameters required by the AI's `chatCompletions.create` method.
* @param {TQueryParams} [queryParams] - Optional query builder parameters to refine the vector search, such as filters,
* groupings, orderings, limits, and offsets.
*
* @returns {Promise<CreateChatCompletionResult<TParams["stream"]>>}
* A promise that resolves to the result of the chat completion, containing the generated response
* based on the input parameters and the provided context.
*/
createChatCompletion<TParams extends Parameters<this["vectorSearch"]>[0] & (TAi extends AnyAI ? Parameters<TAi["chatCompletions"]["create"]>[0] : never) & {
createChatCompletion<TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[], TSelectClause extends SelectClause<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>, TParams extends Parameters<this["vectorSearch"]>[0] & (TAi extends AnyAI ? Parameters<TAi["chatCompletions"]["create"]>[0] : never) & {
template?: string;
}, TQueryParams extends QueryBuilderParams<TName, TType, TDatabaseType>>(params: TParams, queryParams?: TQueryParams): Promise<CreateChatCompletionResult<TParams["stream"]>>;
}>(params: TParams, queryParams?: QueryBuilderParams<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses, TSelectClause>): Promise<CreateChatCompletionResult<TParams["stream"]>>;
}
/**
* Interface representing the structure of a database type, which includes a record of tables.
*
* @property {Record<string, TableType>} tables - A record where the keys are table names and the values are their respective table types.
*/
interface DatabaseType {
name: string;
tables: Record<string, TableType>;
}
/**
* Interface representing the schema of a database, including its name and optional table schemas.
*
* @typeParam TType - A type extending `DatabaseType` that defines the structure of the database.
*
* @property {string} name - The name of the database.
* @property {Object} [tables] - An optional object where each key is a table name and each value is the schema of that table, excluding the name.
*/
interface DatabaseSchema<TType extends DatabaseType> {
name: string;
name: TType["name"];
tables?: {
[K in keyof TType["tables"]]: Omit<TableSchema<any, TType["tables"][K]>, "name">;
[K in keyof TType["tables"]]: Omit<TableSchema<TType["tables"][K]>, "name">;
};
}
/**
* Interface representing basic information about a database.
*
* @typeParam T - A string literal representing the database name.
*
* @property {T} name - The name of the database.
*/
interface DatabaseInfo<T extends string = string> {
name: T;
}
/**
* Interface extending `DatabaseInfo` to include additional details about the database's state and performance.
*
* @typeParam T - A string literal representing the database name.
*
* @property {number} commits - The number of commits made in the database.
* @property {string} role - The role of the database in the cluster.
* @property {string} state - The current state of the database.
* @property {string} position - The current replication position of the database.
* @property {string} details - Additional details about the database.
* @property {number} asyncSlaves - The number of asynchronous slaves connected to the database.
* @property {string} syncSlaves - The identifier of the synchronous slave.
* @property {number} consensusSlaves - The number of consensus slaves in the cluster.
* @property {string} committedPosition - The position of the last committed transaction.
* @property {string} hardenedPosition - The position of the last hardened transaction.
* @property {string} replayPosition - The position of the last replayed transaction.
* @property {number} term - The current term in the database's consensus protocol.
* @property {number} lastPageTerm - The term of the last page in the database.
* @property {number} memoryMBs - The amount of memory used by the database in megabytes.
* @property {number} pendingIOs - The number of pending I/O operations.
* @property {number} pendingBlobFSyncs - The number of pending blob fsync operations.
*/
interface DatabaseInfoExtended<T extends string> extends DatabaseInfo<T> {

@@ -609,88 +251,18 @@ commits: number;

}
/**
* Type representing a mapping of database tables to their respective records.
*
* @typeParam TTables - A record of tables where each key is the table name and each value is the table type.
*/
type DatabaseTablesToRecords<TTables extends DatabaseType["tables"]> = {
[K in keyof TTables]: TTables[K]["columns"][];
};
/**
* Type representing any database instance, with its associated `Embeddings` and `AI` functionalities.
*/
type AnyDatabase = Database<any, AnyAI | undefined>;
/**
* Type representing the name of a table within a specific database type.
*
* @typeParam TType - The type of the database.
*/
type DatabaseTableName<TType extends DatabaseType> = Extract<keyof TType["tables"], string>;
type InferDatabaseType<T> = T extends Database<infer U, any> ? U : never;
/**
* Class representing a database and providing methods to manage its tables and query data.
*
* @typeParam TDatabaseType - The type of the database, which extends `DatabaseType`.
* @typeParam TAi - The type of AI functionalities integrated with the database, which can be undefined.
*
* @property {Connection} _connection - The connection to the database.
* @property {string} name - The name of the database.
* @property {string} [workspaceName] - The name of the workspace the database is associated with.
* @property {TAi} [ai] - Optional AI functionalities associated with the database.
*/
declare class Database<TDatabaseType extends DatabaseType = DatabaseType, TAi extends AnyAI | undefined = undefined> {
private _connection;
name: string;
name: TDatabaseType["name"];
workspaceName?: string | undefined;
private _ai?;
constructor(_connection: Connection, name: string, workspaceName?: string | undefined, _ai?: TAi | undefined);
/**
* Normalizes raw database information into a structured object.
*
* @typeParam TName - A string literal representing the database name.
* @typeParam TExtended - A boolean indicating whether extended information is requested.
*
* @param {any} info - The raw database information to normalize.
* @param {TExtended} [extended] - Whether to include extended information.
*
* @returns {TExtended extends true ? DatabaseInfoExtended<TName> : DatabaseInfo<TName>} A structured object containing normalized database information.
*/
constructor(_connection: Connection, name: TDatabaseType["name"], workspaceName?: string | undefined, _ai?: TAi | undefined);
static normalizeInfo<TName extends string = string, TExtended extends boolean = false>(info: any, extended?: TExtended): TExtended extends true ? DatabaseInfoExtended<TName> : DatabaseInfo<TName>;
/**
* Creates a new database with the specified schema and initializes its tables.
*
* @typeParam TType - The type of the database to create.
* @typeParam TAi - The type of AI functionalities associated with the database, which can be undefined.
*
* @param {Connection} connection - The connection to the database.
* @param {DatabaseSchema<TType>} schema - The schema defining the structure of the database.
* @param {string} [workspaceName] - The name of the workspace the database is associated with.
* @param {TAi} [ai] - Optional AI functionalities to associate with the database.
*
* @returns {Promise<Database<TType, TAi>>} A promise that resolves to the created `Database` instance.
*/
static create<TType extends DatabaseType = DatabaseType, TAi extends AnyAI | undefined = undefined>(connection: Connection, schema: DatabaseSchema<TType>, workspaceName?: string, ai?: TAi): Promise<Database<TType, TAi>>;
/**
* Drops an existing database by name.
*
* @param {Connection} connection - The connection to the database.
* @param {string} name - The name of the database to drop.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the database is dropped.
*/
static drop(connection: Connection, name: string): Promise<[ResultSetHeader, FieldPacket[]]>;
/**
* Retrieves information about the database, optionally including extended details.
*
* @typeParam TExtended - A boolean indicating whether extended information is requested.
*
* @param {TExtended} [extended] - Whether to include extended information.
*
* @returns {Promise<TExtended extends true ? DatabaseInfoExtended<string> : DatabaseInfo<string>>} A promise that resolves to the database information.
*/
showInfo<TExtended extends boolean = false>(extended?: TExtended): Promise<TExtended extends true ? DatabaseInfoExtended<string> : DatabaseInfo<string>>;
/**
* Describes the database by providing its detailed information along with the structure of its tables.
*
* @returns {Promise<any>} A promise that resolves to an object containing the database's details and table structures.
*/
showInfo<TExtended extends boolean = false>(extended?: TExtended): Promise<TExtended extends true ? DatabaseInfoExtended<TDatabaseType["name"]> : DatabaseInfo<TDatabaseType["name"]>>;
describe(): Promise<{

@@ -720,77 +292,15 @@ tables: {

pendingBlobFSyncs: number;
name: string;
name: TDatabaseType["name"];
}>;
/**
* Drops the current database.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the database is dropped.
*/
drop(): Promise<[ResultSetHeader, FieldPacket[]]>;
/**
* Retrieves a `Table` instance representing a specific table in the database.
*
* @typeParam TType - The type of the table.
* @typeParam TName - The name of the table, which can be a string literal or a generic string.
*
* @param {TName} name - The name of the table to retrieve.
*
* @returns {Table<TName, TType extends TableType ? TType : TDatabaseType["tables"][TName] extends TableType ? TDatabaseType["tables"][TName] : TableType, TDatabaseType, TAi>} A `Table` instance representing the specified table.
*/
table<TType, TName extends DatabaseTableName<TDatabaseType> | (string & {}) = DatabaseTableName<TDatabaseType> | (string & {})>(name: TName): Table<TName, TType extends TableType ? TType : TDatabaseType["tables"][TName] extends TableType ? TDatabaseType["tables"][TName] : TableType, TDatabaseType, TAi>;
/**
* Retrieves information about all tables in the database, optionally including extended details.
*
* @typeParam TExtended - A boolean indicating whether extended information is requested.
*
* @param {TExtended} [extended] - Whether to include extended information.
*
* @returns {Promise<Result<Extract<keyof TDatabaseType["tables"], string>, TExtended>[]>} A promise that resolves to an array of table information objects.
*/
table<TType, TName extends DatabaseTableName<TDatabaseType> | (string & {}) = DatabaseTableName<TDatabaseType> | (string & {})>(name: TName): Table<TType extends TableType ? TType : TDatabaseType["tables"][TName] extends TableType ? TDatabaseType["tables"][TName] : TableType, TDatabaseType, TAi>;
showTablesInfo<TExtended extends boolean = false>(extended?: TExtended): Promise<(TExtended extends true ? TableInfoExtended<Extract<keyof TDatabaseType["tables"], string>> : TableInfo<Extract<keyof TDatabaseType["tables"], string>>)[]>;
/**
* Creates a new table in the database with the specified schema.
*
* @typeParam TType - The type of the table to create.
*
* @param {TableSchema<TType>} schema - The schema defining the structure of the table.
*
* @returns {Promise<Table<TType, TDatabaseType, TAi>>} A promise that resolves to the created `Table` instance.
*/
createTable<TName extends string = string, TType extends TableType = TableType>(schema: TableSchema<TName, TType>): Promise<Table<TName, TType, TDatabaseType, TAi>>;
/**
* Drops a specific table from the database.
*
* @param {DatabaseTableName<TDatabaseType> | (string & {})} name - The name of the table to drop.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the table is dropped.
*/
createTable<TType extends TableType = TableType>(schema: TableSchema<TType>): Promise<Table<TType, TDatabaseType, TAi>>;
dropTable(name: DatabaseTableName<TDatabaseType> | (string & {})): Promise<[ResultSetHeader, FieldPacket[]]>;
/**
* Executes a query against the database after selecting the current database context.
*
* @typeParam T - The expected result type of the query.
*
* @param {string} statement - The SQL query statement to execute.
*
* @returns {Promise<T[]>} A promise that resolves to the result of the query.
*/
query<T extends any[]>(statement: string): Promise<T[]>;
}
/**
* Interface representing the structure of a workspace type, which includes a record of databases.
*
* @property {Record<string, DatabaseType>} databases - A record where the keys are database names and the values are their respective database types.
*/
interface WorkspaceType {
databases: Record<string, DatabaseType>;
}
/**
* Interface representing the schema of a workspace, including its name and database schemas.
*
* @typeParam TWorkspaceType - A type extending `WorkspaceType` that defines the structure of the workspace.
*
* @property {string} name - The name of the workspace.
* @property {Object} databases - An object where each key is a database name and each value is the schema of that database, excluding the name.
*/
interface WorkspaceSchema<TWorkspaceType extends WorkspaceType> {

@@ -802,13 +312,2 @@ name: string;

}
/**
* Configuration object for connecting to a workspace within `Workspace`.
*
* Extends `ConnectionConfig` to include optional properties `name` and `ai`.
*
* @typeParam TWorkspaceType - The type of the workspace to connect to.
* @typeParam TAi - The type of AI functionalities integrated with the workspace, which can be undefined.
*
* @property {string} [name] - The name of the workspace.
* @property {TAi} [ai] - Optional AI functionalities to associate with the workspace.
*/
interface ConnectWorkspaceConfig<TWorkspaceType extends WorkspaceType, TAi extends AnyAI | undefined> extends ConnectionConfig {

@@ -818,18 +317,3 @@ name?: WorkspaceSchema<TWorkspaceType>["name"];

}
/**
* Type representing the name of a database within a specific workspace type.
*
* @typeParam TWorkspaceType - The type of the workspace.
*/
type WorkspaceDatabaseName<TWorkspaceType extends WorkspaceType> = Extract<keyof TWorkspaceType["databases"], string>;
/**
* Class representing a workspace in SingleStore, providing methods to manage its databases and perform operations.
*
* @typeParam TWorkspaceType - The type of the workspace, which extends `WorkspaceType`.
* @typeParam TAi - The type of AI functionalities integrated with the workspace, which can be undefined.
*
* @property {Connection} connection - The connection to the workspace.
* @property {string} [name] - The name of the workspace.
* @property {TAi} [ai] - Optional AI functionalities associated with the workspace.
*/
declare class Workspace<TWorkspaceType extends WorkspaceType = WorkspaceType, TAi extends AnyAI | undefined = undefined> {

@@ -840,99 +324,20 @@ connection: Connection;

constructor(connection: Connection, name?: string | undefined, _ai?: TAi | undefined);
/**
* Connects to a workspace in SingleStore, establishing a connection and associating AI functionalities if provided.
*
* @typeParam TWorkspaceType - The type of the workspace to connect to.
* @typeParam TAi - The type of AI functionalities associated with the workspace, which can be undefined.
*
* @param {ConnectWorkspaceConfig<TWorkspaceType, TAi>} config - The configuration object for connecting to the workspace.
*
* @returns {Workspace<TWorkspaceType, TAi>} A `Workspace` instance representing the connected workspace.
*/
static connect<TWorkspaceType extends WorkspaceType = WorkspaceType, TAi extends AnyAI | undefined = undefined>({ ai, name, ...config }: ConnectWorkspaceConfig<TWorkspaceType, TAi>): Workspace<TWorkspaceType, TAi>;
/**
* Retrieves a `Database` instance representing a specific database in the workspace.
*
* @typeParam TType - The type of the database.
* @typeParam TName - The name of the database, which can be a string literal or a generic string.
*
* @param {TName} name - The name of the database to retrieve.
*
* @returns {Database<TType extends DatabaseType ? TType : TWorkspaceType["databases"][TName] extends DatabaseType ? TWorkspaceType["databases"][TName] : DatabaseType, TAi>} A `Database` instance representing the specified database.
*/
database<TType, TName extends WorkspaceDatabaseName<TWorkspaceType> | (string & {}) = WorkspaceDatabaseName<TWorkspaceType> | (string & {})>(name: TName): Database<TType extends DatabaseType ? TType : TWorkspaceType["databases"][TName] extends DatabaseType ? TWorkspaceType["databases"][TName] : DatabaseType, TAi>;
/**
* Creates a new database in the workspace with the specified schema.
*
* @typeParam TType - The type of the database to create.
*
* @param {DatabaseSchema<TType>} schema - The schema defining the structure of the database.
*
* @returns {Promise<Database<TType, TAi>>} A promise that resolves to the created `Database` instance.
*/
createDatabase<TType extends DatabaseType = DatabaseType>(schema: DatabaseSchema<TType>): Promise<Database<TType, TAi>>;
/**
* Drops a specific database from the workspace.
*
* @param {WorkspaceDatabaseName<TWorkspaceType> | (string & {})} name - The name of the database to drop.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the database is dropped.
*/
dropDatabase(name: WorkspaceDatabaseName<TWorkspaceType> | (string & {})): Promise<[ResultSetHeader, FieldPacket[]]>;
/**
* Retrieves information about all databases in the workspace, optionally including extended details.
*
* @typeParam TExtended - A boolean indicating whether extended information is requested.
*
* @param {TExtended} [extended] - Whether to include extended information.
*
* @returns {Promise<(TExtended extends true ? DatabaseInfoExtended<WorkspaceDatabaseName<TWorkspaceType>> : DatabaseInfo<WorkspaceDatabaseName<TWorkspaceType>>)[]>} A promise that resolves to an array of database information objects.
*/
showDatabasesInfo<TExtended extends boolean = false>(extended?: TExtended): Promise<(TExtended extends true ? DatabaseInfoExtended<WorkspaceDatabaseName<TWorkspaceType>> : DatabaseInfo<WorkspaceDatabaseName<TWorkspaceType>>)[]>;
}
/**
* Configuration object for initializing a `SingleStoreClient` instance.
*
* @typeParam TAi - The type of AI functionalities integrated with the client, which can be undefined.
*
* @property {TAi} [ai] - Optional AI functionalities to associate with the `SingleStoreClient`.
*/
interface SingleStoreClientConfig<TAi extends AnyAI | undefined> {
ai?: TAi;
}
/**
* Configuration object for connecting to a workspace within `SingleStoreClient`.
*
* @typeParam TWorkspaceType - The type of the workspace to connect to.
* @typeParam TAi - The type of AI functionalities integrated with the workspace, which can be undefined.
*/
interface WorkspaceConfig<TWorkspaceType extends WorkspaceType, TAi extends AnyAI | undefined> extends Omit<ConnectWorkspaceConfig<TWorkspaceType, TAi>, "ai"> {
}
/**
* Main client class for interacting with SingleStore, including the ability to connect to workspaces.
*
* @typeParam TAi - The type of AI functionalities integrated with the client, which can be undefined.
*
* @property {TAi} _ai - The AI functionalities associated with the `SingleStoreClient`.
*/
declare class SingleStoreClient<TAi extends AnyAI | undefined = undefined> {
private _ai;
/**
* Constructs a new `SingleStoreClient` instance.
*
* @param {SingleStoreClientConfig<TAi>} [config] - The configuration object for initializing the `SingleStoreClient`.
*/
constructor(config?: SingleStoreClientConfig<TAi>);
/**
* Connects to a workspace within the SingleStore environment.
*
* @typeParam TWorkspaceType - The type of the workspace to connect to.
*
* @param {WorkspaceConfig<TWorkspaceType, TAi>} config - The configuration object for connecting to the workspace.
*
* @returns {Workspace<TWorkspaceType, TAi>} A `Workspace` instance representing the connected workspace.
*/
workspace<TWorkspaceType extends WorkspaceType = WorkspaceType>(config: WorkspaceConfig<TWorkspaceType, TAi>): Workspace<TWorkspaceType, TAi>;
}
export { type AnyDatabase, type AnyQueryBuilderParams, Column, type ColumnInfo, type ColumnSchema, type ColumnType, type ConnectWorkspaceConfig, Connection, type ConnectionConfig, Database, type DatabaseInfo, type DatabaseInfoExtended, type DatabaseSchema, type DatabaseTableName, type DatabaseTablesToRecords, type DatabaseType, type ExtractQuerySelectedColumn, type GroupByClause, type InferDatabaseType, type OrderByClause, type OrderByDirection, QueryBuilder, type QueryBuilderParams, type SelectClause, SingleStoreClient, type SingleStoreClientConfig, Table, type TableColumnName, type TableInfo, type TableInfoExtended, type TableSchema, type TableType, type WhereClause, type WhereOperator, Workspace, type WorkspaceConfig, type WorkspaceDatabaseName, type WorkspaceSchema, type WorkspaceType };
export { type AnyDatabase, type AnyQueryBuilderParams, Column, type ColumnInfo, type ColumnSchema, type ColumnType, type ConnectWorkspaceConfig, Connection, type ConnectionConfig, Database, type DatabaseInfo, type DatabaseInfoExtended, type DatabaseSchema, type DatabaseTableName, type DatabaseTablesToRecords, type DatabaseType, type ExtractJoinClauseColumns, type ExtractSelectedQueryColumns, type GroupByClause, type InferDatabaseType, type JoinClause, type OrderByClause, type OrderByDirection, QueryBuilder, type QueryBuilderParams, type SelectClause, SingleStoreClient, type SingleStoreClientConfig, Table, type TableColumnName, type TableInfo, type TableInfoExtended, type TableSchema, type TableType, type WhereClause, type WhereOperator, Workspace, type WorkspaceConfig, type WorkspaceDatabaseName, type WorkspaceSchema, type WorkspaceType };

@@ -32,7 +32,2 @@ "use strict";

var Connection = class _Connection {
/**
* Constructs a new `Connection` instance and initializes the connection pool.
*
* @param {ConnectionConfig} config - The configuration object for the connection pool.
*/
constructor(config) {

@@ -43,17 +38,5 @@ this.config = config;

client;
/**
* Factory method to create a new `Connection` instance.
*
* @param {ConnectionConfig} config - The configuration object for the connection pool.
*
* @returns {Connection} A new `Connection` instance.
*/
static create(config) {
return new _Connection(config);
}
/**
* Disconnects from the database by closing the connection pool.
*
* @returns {Promise<void>} A promise that resolves when the connection pool is closed.
*/
async disconnect() {

@@ -66,10 +49,2 @@ await this.client.end();

var Column = class _Column {
/**
* Constructs a new `Column` instance.
*
* @param {Connection} _connection - The database connection used to execute queries.
* @param {string} databaseName - The name of the database containing the column.
* @param {string} tableName - The name of the table containing the column.
* @param {string} name - The name of the column.
*/
constructor(_connection, databaseName, tableName, name) {

@@ -83,11 +58,2 @@ this._connection = _connection;

_path;
/**
* Normalizes raw database column information into a structured `ColumnInfo` object.
*
* @typeParam T - A string literal representing the column name.
*
* @param {any} info - Raw column information from the database.
*
* @returns {ColumnInfo<T>} A structured `ColumnInfo` object.
*/
static normalizeInfo(info) {

@@ -103,9 +69,2 @@ return {

}
/**
* Converts a `ColumnSchema` object into an SQL column definition string.
*
* @param {ColumnSchema} schema - The schema of the column to be converted.
*
* @returns {string} An SQL string representing the column definition.
*/
static schemaToClauses(schema) {

@@ -120,12 +79,2 @@ const clauses = [`\`${schema.name}\``];

}
/**
* Adds a new column to a specified table in the database.
*
* @param {Connection} connection - The database connection used to execute the query.
* @param {string} databaseName - The name of the database where the table is located.
* @param {string} tableName - The name of the table where the column will be added.
* @param {ColumnSchema} schema - The schema of the column to be added.
*
* @returns {Promise<Column>} A promise that resolves to the created `Column` instance.
*/
static async add(connection, databaseName, tableName, schema) {

@@ -137,12 +86,2 @@ const clauses = _Column.schemaToClauses(schema);

}
/**
* Drops a column from a specified table in the database.
*
* @param {Connection} connection - The database connection used to execute the query.
* @param {string} databaseName - The name of the database where the table is located.
* @param {string} tableName - The name of the table containing the column.
* @param {string} name - The name of the column to be dropped.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the column is dropped.
*/
static drop(connection, databaseName, tableName, name) {

@@ -152,7 +91,2 @@ return connection.client.execute(` ALTER TABLE ${databaseName}.${tableName} DROP COLUMN ${name}

}
/**
* Retrieves information about the current column from the database.
*
* @returns {Promise<ColumnInfo<string>>} A promise that resolves to the `ColumnInfo` object containing details about the column.
*/
async showInfo() {

@@ -164,17 +98,5 @@ const [rows] = await this._connection.client.query(

}
/**
* Drops the current column from the table.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the column is dropped.
*/
drop() {
return _Column.drop(this._connection, this.databaseName, this.tableName, this.name);
}
/**
* Modifies the current column in the table based on the provided schema.
*
* @param {Partial<Omit<ColumnSchema, "name">>} schema - The schema containing modifications to be applied to the column.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the column is modified.
*/
modify(schema) {

@@ -185,9 +107,2 @@ const clauses = _Column.schemaToClauses({ type: "", ...schema, name: this.name });

}
/**
* Renames the current column in the table.
*
* @param {string} newName - The new name for the column.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the column is renamed.
*/
async rename(newName) {

@@ -203,2 +118,17 @@ const result = await this._connection.client.execute(` ALTER TABLE ${this._path} CHANGE ${this.name} ${newName}

var import_mysql2 = require("mysql2");
var ALIAS_PATTERN = /(.+)\s+AS\s+(.+)/i;
function extractSelectClauseAliases(selectClauses = []) {
return selectClauses.map((column) => {
const match = column.match(ALIAS_PATTERN);
return match ? match[2]?.trim() : null;
}).filter((alias) => alias !== null);
}
function isJoinColumn(column, joinClauses = []) {
for (const clause of joinClauses) {
if (column.startsWith(`${clause.as}.`)) {
return true;
}
}
return false;
}
var QueryBuilder = class {

@@ -209,9 +139,41 @@ constructor(_databaseName, _tableName) {

}
buildSelectClause(select) {
const columns = select ? select : ["*"];
return `SELECT ${columns.join(", ")}`;
buildJoinClause(clauses) {
if (!clauses || clauses.length === 0) return "";
return clauses.map((clause) => {
let left = String(clause.on[0]);
left = isJoinColumn(left, clauses) ? left : `${this._tableName}.${left}`;
let right = String(clause.on[2]);
right = isJoinColumn(right, clauses) ? right : `${clause.as}.${right}`;
const joinType = clause.type ? `${clause.type} JOIN` : "JOIN";
const tableName = `${this._databaseName}.${String(clause.table)} AS ${clause.as}`;
const onCondition = `${left} ${clause.on[1]} ${right}`;
return `${joinType} ${tableName} ON ${onCondition}`;
}).join(" ");
}
buildFromClause() {
return `FROM ${this._databaseName}.${String(this._tableName)}`;
buildSelectClause(clauses, joinClauses) {
let _clauses = clauses?.length ? clauses : [];
if (!clauses?.length) {
_clauses.push("*");
}
if (joinClauses?.length) {
if (!clauses?.length) {
_clauses = [..._clauses, ...joinClauses.map((join) => `${join.as}.*`)];
}
_clauses = _clauses.map((column) => {
const _column = String(column);
if (isJoinColumn(_column, joinClauses)) {
const [tableName, columnName] = _column.split(".");
return `${_column}${!_column.endsWith("*") ? ` AS ${tableName}_${columnName}` : ""}`;
}
if (ALIAS_PATTERN.test(_column)) {
return _column;
}
return `${this._tableName}.${_column}${!_column.endsWith("*") ? ` AS ${_column}` : ""}`;
});
}
return `SELECT ${_clauses.join(", ")}`;
}
buildFromClause(hasJoinClauses) {
return `FROM ${this._databaseName}.${this._tableName}${hasJoinClauses ? ` AS ${this._tableName}` : ""}`;
}
buildWhereCondition(column, operator, value) {

@@ -241,29 +203,43 @@ switch (operator) {

}
buildWhereClause(conditions) {
if (!conditions || !Object.keys(conditions).length) return "";
const clauses = [];
for (const [key, value] of Object.entries(conditions)) {
if (key === "OR" && Array.isArray(value)) {
clauses.push(`(${value.map((v) => `(${this.buildWhereClause(v)})`).join(" OR ")})`);
} else if (key === "NOT" && typeof value === "object") {
clauses.push(`NOT (${this.buildWhereClause(value)})`);
buildWhereClause(clauses, joinClauses) {
if (!clauses || !Object.keys(clauses).length) return "";
const _clauses = [];
for (const [column, value] of Object.entries(clauses)) {
if (column === "OR" && Array.isArray(value)) {
_clauses.push(`(${value.map((v) => `(${this.buildWhereClause(v, joinClauses)})`).join(" OR ")})`);
} else if (column === "NOT" && typeof value === "object") {
_clauses.push(`NOT (${this.buildWhereClause(value, joinClauses)})`);
} else if (typeof value === "object" && !Array.isArray(value)) {
for (const [operator, _value] of Object.entries(value)) {
clauses.push(this.buildWhereCondition(key, operator, _value));
const _column = joinClauses?.length ? isJoinColumn(column, joinClauses) ? column : `${this._tableName}.${column}` : column;
_clauses.push(this.buildWhereCondition(_column, operator, _value));
}
} else {
clauses.push(this.buildWhereCondition(key, "eq", value));
const _column = joinClauses?.length ? isJoinColumn(column, joinClauses) ? column : `${this._tableName}.${column}` : column;
_clauses.push(this.buildWhereCondition(_column, "eq", value));
}
}
return `WHERE ${clauses.join(" AND ")}`;
return `WHERE ${_clauses.join(" AND ")}`;
}
buildGroupByClause(columns) {
return columns?.length ? `GROUP BY ${columns.join(", ")}` : "";
buildGroupByClause(clauses, joinClauses, aliases) {
if (!clauses || !clauses.length) return "";
const _clauses = clauses.map((column) => {
const _column = String(column);
if (aliases?.includes(_column)) {
return _column;
}
return joinClauses?.length ? isJoinColumn(_column, joinClauses) ? _column : `${this._tableName}.${_column}` : _column;
});
return `GROUP BY ${_clauses.join(", ")}`;
}
buildOrderByClause(clauses) {
buildOrderByClause(clauses, joinClauses, aliases) {
if (!clauses) return "";
const condition = Object.entries(clauses).map((condition2) => {
const [column, direction = ""] = condition2;
return `${column} ${direction.toUpperCase()}`;
}).filter(Boolean).join(", ");
const condition = Object.entries(clauses).map(([column, direction = "asc"]) => {
let _column = String(column);
if (aliases?.includes(_column)) {
return _column;
}
_column = joinClauses?.length ? isJoinColumn(_column, joinClauses) ? _column : `${this._tableName}.${_column}` : _column;
return `${_column} ${direction.toUpperCase()}`;
}).join(", ");
return condition ? `ORDER BY ${condition}` : "";

@@ -278,8 +254,10 @@ }

buildClauses(params) {
const aliases = extractSelectClauseAliases(params?.select);
return {
select: this.buildSelectClause(params?.select),
from: this.buildFromClause(),
where: this.buildWhereClause(params?.where),
groupBy: this.buildGroupByClause(params?.groupBy),
orderBy: this.buildOrderByClause(params?.orderBy),
select: this.buildSelectClause(params?.select, params?.join),
from: this.buildFromClause(Boolean(params?.join?.length)),
join: this.buildJoinClause(params?.join),
where: this.buildWhereClause(params?.where, params?.join),
groupBy: this.buildGroupByClause(params?.groupBy, params?.join, aliases),
orderBy: this.buildOrderByClause(params?.orderBy, params?.join, aliases),
limit: this.buildLimitClause(params?.limit),

@@ -290,3 +268,3 @@ offset: this.buildOffsetClause(params?.offset)

buildQuery(params) {
return Object.values(this.buildClauses(params)).join(" ").trim();
return Object.values(this.buildClauses(params)).filter(Boolean).join(" ").trim();
}

@@ -312,13 +290,2 @@ };

}
/**
* Normalizes raw table information into a structured object.
*
* @typeParam TName - A string literal representing the table name.
* @typeParam TExtended - A boolean indicating whether extended information is requested.
*
* @param {any} info - The raw table information to normalize.
* @param {TExtended} [extended] - Whether to include extended information.
*
* @returns {TExtended extends true ? TableInfoExtended<TName> : TableInfo<TName>} A structured object containing normalized table information.
*/
static normalizeInfo(info, extended) {

@@ -334,9 +301,2 @@ const name = info[Object.keys(info).find((key) => key.startsWith("Tables_in_"))];

}
/**
* Converts a `TableSchema` object into an SQL table definition string.
*
* @param {TableSchema<any>} schema - The schema of the table to be converted.
*
* @returns {string} An SQL string representing the table definition.
*/
static schemaToClauses(schema) {

@@ -352,17 +312,2 @@ const clauses = [

}
/**
* Creates a new table in the database with the specified schema.
*
* @typeParam TName - The name of the table, which extends `string`.
* @typeParam TType - The type of the table, which extends `TableType`.
* @typeParam TDatabaseType - The type of the database, which extends `DatabaseType`.
* @typeParam TAi - The type of AI functionalities integrated with the table, which can be undefined.
*
* @param {Connection} connection - The connection to the database.
* @param {string} databaseName - The name of the database where the table will be created.
* @param {TableSchema<TType>} schema - The schema defining the structure of the table.
* @param {TAi} [ai] - Optional AI functionalities to associate with the table.
*
* @returns {Promise<Table<TName, TType, TDatabaseType, TAi>>} A promise that resolves to the created `Table` instance.
*/
static async create(connection, databaseName, schema, ai) {

@@ -374,11 +319,2 @@ const clauses = _Table.schemaToClauses(schema);

}
/**
* Drops an existing table from the database by name.
*
* @param {Connection} connection - The connection to the database.
* @param {string} databaseName - The name of the database where the table is located.
* @param {string} name - The name of the table to drop.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the table is dropped.
*/
static drop(connection, databaseName, name) {

@@ -388,11 +324,2 @@ return connection.client.execute(` DROP TABLE IF EXISTS ${databaseName}.${name}

}
/**
* Retrieves information about the table, optionally including extended details.
*
* @typeParam TExtended - A boolean indicating whether extended information is requested.
*
* @param {TExtended} [extended] - Whether to include extended information.
*
* @returns {Promise<TExtended extends true ? TableInfoExtended<string> : TableInfo<string>>} A promise that resolves to the table information.
*/
async showInfo(extended) {

@@ -405,25 +332,8 @@ const clauses = [`SHOW TABLES IN ${this.databaseName}`];

}
/**
* Drops the current table from the database.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the table is dropped.
*/
drop() {
return _Table.drop(this._connection, this.databaseName, this.name);
}
/**
* Retrieves a `Column` instance representing a specific column in the table.
*
* @param {TableColumnName<TType> | (string & {})} name - The name of the column to retrieve.
*
* @returns {Column} A `Column` instance representing the specified column.
*/
column(name) {
return new Column(this._connection, this.databaseName, this.name, name);
}
/**
* Retrieves information about all columns in the table.
*
* @returns {Promise<ColumnInfo<TableColumnName<TType>>[]>} A promise that resolves to an array of column information objects.
*/
async showColumnsInfo() {

@@ -433,27 +343,8 @@ const [rows] = await this._connection.client.query(`SHOW COLUMNS IN ${this.name} IN ${this.databaseName}`);

}
/**
* Adds a new column to the table with the specified schema.
*
* @param {ColumnSchema} schema - The schema defining the structure of the column to be added.
*
* @returns {Promise<Column>} A promise that resolves to the created `Column` instance.
*/
addColumn(schema) {
return Column.add(this._connection, this.databaseName, this.name, schema);
}
/**
* Drops a specific column from the table by name.
*
* @param {TableColumnName<TType> | (string & {})} name - The name of the column to drop.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the column is dropped.
*/
dropColumn(name) {
return Column.drop(this._connection, this.databaseName, this.name, name);
}
/**
* Truncates the table, removing all rows while keeping the table structure intact.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the table is truncated.
*/
truncate() {

@@ -463,9 +354,2 @@ return this._connection.client.execute(` TRUNCATE TABLE ${this._path}

}
/**
* Renames the current table to a new name.
*
* @param {string} newName - The new name for the table.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the table is renamed.
*/
async rename(newName) {

@@ -478,9 +362,2 @@ const result = await this._connection.client.execute(` ALTER TABLE ${this._path} RENAME TO ${newName}

}
/**
* Inserts one or more rows into the table.
*
* @param {Partial<TType["columns"]> | Partial<TType["columns"]>[]} values - The values to insert into the table. Can be a single row or an array of rows.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]][]>} A promise that resolves to an array of `ResultSetHeader` objects for each inserted row.
*/
insert(values) {

@@ -497,11 +374,2 @@ const _values = Array.isArray(values) ? values : [values];

}
/**
* Finds rows from the table based on the specified query arguments.
*
* @typeParam TParams - The type of the query builder arguments.
*
* @param {TParams} params - The arguments defining the query, including selected columns, filters, and other options.
*
* @returns {Promise<(ExtractQuerySelectedColumn<TName, TDatabaseType, TParams> & RowDataPacket)[]>} A promise that resolves to an array of selected rows.
*/
async find(params) {

@@ -513,10 +381,2 @@ const queryBuilder = new QueryBuilder(this.databaseName, this.name);

}
/**
* Updates rows in the table based on the specified values and filters.
*
* @param {Partial<TType["columns"]>} values - The values to update in the table.
* @param {WhereClause<TName, TDatabaseType>} where - The where clause to apply to the update query.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the update is complete.
*/
update(values, where) {

@@ -528,9 +388,2 @@ const _where = new QueryBuilder(this.databaseName, this.name).buildWhereClause(where);

}
/**
* Deletes rows from the table based on the specified filters. If no filters are provided, the table is truncated.
*
* @param {WhereClause<TName, TDatabaseType>} [where] - The where clause to apply to the delete query.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the delete operation is complete.
*/
delete(where) {

@@ -542,25 +395,2 @@ if (!where) return this.truncate();

}
/**
* Performs a vector search on the table using a prompt and a specified vector column.
*
* This method generates an embedding for the provided prompt, then performs a vector similarity search
* using the specified vector column of the table. The search results are ordered by vector similarity score
* in descending order, unless an additional ordering is specified in the query builder parameters.
*
* @typeParam TSearch - The parameters required for the vector search, including the prompt, vector column,
* and optional embedding parameters specific to the AI model being used.
* @typeParam TParams - The query builder parameters used to refine the search query, such as filters,
* groupings, orderings, limits, and offsets.
*
* @param {TParams} params - The search parameters object containing:
* - `prompt`: The search prompt to be converted into an embedding.
* - `vectorColumn`: The name of the vector column in the table to compare against the prompt embedding.
* - `embeddingParams` (optional): Additional parameters for creating the prompt embedding, if supported by the AI model.
* @param {TQueryParams} [queryParams] - Optional query builder parameters to refine the search, such as filters,
* groupings, orderings, limits, and offsets.
*
* @returns {Promise<(ExtractQuerySelectedColumn<TName, TDatabaseType, TQueryParams> & { v_score: number } & RowDataPacket)[]>}
* A promise that resolves to an array of rows matching the vector search criteria, each row including
* the selected columns and a vector similarity score.
*/
async vectorSearch(params, queryParams) {

@@ -581,28 +411,2 @@ const clauses = new QueryBuilder(this.databaseName, this.name).buildClauses(queryParams);

}
/**
* Creates a chat completion based on a provided prompt, system role, and optional template.
*
* This method first performs a vector search to find the most relevant context for the given prompt.
* It then formats the prompt using a template and generates a chat completion using an AI model.
* The system role can be customized to guide the AI's behavior during the completion.
*
* @typeParam TParams - The parameters required to create a chat completion, including the prompt, vector search parameters,
* optional system role, template, and additional parameters specific to the AI model being used.
* @typeParam TQueryParams - The query builder parameters used to refine the vector search query, such as filters,
* groupings, orderings, limits, and offsets.
*
* @param {TParams} params - The parameters object containing:
* - `prompt`: The initial user prompt to generate a response for.
* - `systemRole` (optional): The system role for guiding the AI's behavior during the chat completion.
* - `template` (optional): A template to structure the prompt for the chat completion.
* - `vectorColumn`: The name of the vector column to be used in the vector search.
* - `embeddingParams` (optional): Additional parameters for creating the prompt embedding, if supported by the AI model.
* - Additional parameters required by the AI's `chatCompletions.create` method.
* @param {TQueryParams} [queryParams] - Optional query builder parameters to refine the vector search, such as filters,
* groupings, orderings, limits, and offsets.
*
* @returns {Promise<CreateChatCompletionResult<TParams["stream"]>>}
* A promise that resolves to the result of the chat completion, containing the generated response
* based on the input parameters and the provided context.
*/
async createChatCompletion(params, queryParams) {

@@ -631,13 +435,2 @@ const { prompt, systemRole, template, vectorColumn, embeddingParams, ...createChatCompletionParams } = params;

}
/**
* Normalizes raw database information into a structured object.
*
* @typeParam TName - A string literal representing the database name.
* @typeParam TExtended - A boolean indicating whether extended information is requested.
*
* @param {any} info - The raw database information to normalize.
* @param {TExtended} [extended] - Whether to include extended information.
*
* @returns {TExtended extends true ? DatabaseInfoExtended<TName> : DatabaseInfo<TName>} A structured object containing normalized database information.
*/
static normalizeInfo(info, extended) {

@@ -666,15 +459,2 @@ const name = info[Object.keys(info).find((key) => key.startsWith("Database"))];

}
/**
* Creates a new database with the specified schema and initializes its tables.
*
* @typeParam TType - The type of the database to create.
* @typeParam TAi - The type of AI functionalities associated with the database, which can be undefined.
*
* @param {Connection} connection - The connection to the database.
* @param {DatabaseSchema<TType>} schema - The schema defining the structure of the database.
* @param {string} [workspaceName] - The name of the workspace the database is associated with.
* @param {TAi} [ai] - Optional AI functionalities to associate with the database.
*
* @returns {Promise<Database<TType, TAi>>} A promise that resolves to the created `Database` instance.
*/
static async create(connection, schema, workspaceName, ai) {

@@ -693,22 +473,5 @@ const clauses = [`CREATE DATABASE IF NOT EXISTS ${schema.name}`];

}
/**
* Drops an existing database by name.
*
* @param {Connection} connection - The connection to the database.
* @param {string} name - The name of the database to drop.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the database is dropped.
*/
static drop(connection, name) {
return connection.client.execute(`DROP DATABASE IF EXISTS ${name}`);
}
/**
* Retrieves information about the database, optionally including extended details.
*
* @typeParam TExtended - A boolean indicating whether extended information is requested.
*
* @param {TExtended} [extended] - Whether to include extended information.
*
* @returns {Promise<TExtended extends true ? DatabaseInfoExtended<string> : DatabaseInfo<string>>} A promise that resolves to the database information.
*/
async showInfo(extended) {

@@ -721,7 +484,2 @@ const clauses = ["SHOW DATABASES"];

}
/**
* Describes the database by providing its detailed information along with the structure of its tables.
*
* @returns {Promise<any>} A promise that resolves to an object containing the database's details and table structures.
*/
async describe() {

@@ -736,32 +494,8 @@ const [info, tablesInfo] = await Promise.all([this.showInfo(true), this.showTablesInfo(true)]);

}
/**
* Drops the current database.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the database is dropped.
*/
drop() {
return _Database.drop(this._connection, this.name);
}
/**
* Retrieves a `Table` instance representing a specific table in the database.
*
* @typeParam TType - The type of the table.
* @typeParam TName - The name of the table, which can be a string literal or a generic string.
*
* @param {TName} name - The name of the table to retrieve.
*
* @returns {Table<TName, TType extends TableType ? TType : TDatabaseType["tables"][TName] extends TableType ? TDatabaseType["tables"][TName] : TableType, TDatabaseType, TAi>} A `Table` instance representing the specified table.
*/
table(name) {
return new Table(this._connection, this.name, name, this._ai);
}
/**
* Retrieves information about all tables in the database, optionally including extended details.
*
* @typeParam TExtended - A boolean indicating whether extended information is requested.
*
* @param {TExtended} [extended] - Whether to include extended information.
*
* @returns {Promise<Result<Extract<keyof TDatabaseType["tables"], string>, TExtended>[]>} A promise that resolves to an array of table information objects.
*/
async showTablesInfo(extended) {

@@ -773,33 +507,8 @@ const clauses = [`SHOW TABLES IN ${this.name}`];

}
/**
* Creates a new table in the database with the specified schema.
*
* @typeParam TType - The type of the table to create.
*
* @param {TableSchema<TType>} schema - The schema defining the structure of the table.
*
* @returns {Promise<Table<TType, TDatabaseType, TAi>>} A promise that resolves to the created `Table` instance.
*/
createTable(schema) {
return Table.create(this._connection, this.name, schema, this._ai);
}
/**
* Drops a specific table from the database.
*
* @param {DatabaseTableName<TDatabaseType> | (string & {})} name - The name of the table to drop.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the table is dropped.
*/
dropTable(name) {
return Table.drop(this._connection, this.name, name);
}
/**
* Executes a query against the database after selecting the current database context.
*
* @typeParam T - The expected result type of the query.
*
* @param {string} statement - The SQL query statement to execute.
*
* @returns {Promise<T[]>} A promise that resolves to the result of the query.
*/
async query(statement) {

@@ -819,12 +528,2 @@ const statements = [`USE ${this.name}`, statement].join(";\n");

}
/**
* Connects to a workspace in SingleStore, establishing a connection and associating AI functionalities if provided.
*
* @typeParam TWorkspaceType - The type of the workspace to connect to.
* @typeParam TAi - The type of AI functionalities associated with the workspace, which can be undefined.
*
* @param {ConnectWorkspaceConfig<TWorkspaceType, TAi>} config - The configuration object for connecting to the workspace.
*
* @returns {Workspace<TWorkspaceType, TAi>} A `Workspace` instance representing the connected workspace.
*/
static connect({

@@ -838,46 +537,11 @@ ai,

}
/**
* Retrieves a `Database` instance representing a specific database in the workspace.
*
* @typeParam TType - The type of the database.
* @typeParam TName - The name of the database, which can be a string literal or a generic string.
*
* @param {TName} name - The name of the database to retrieve.
*
* @returns {Database<TType extends DatabaseType ? TType : TWorkspaceType["databases"][TName] extends DatabaseType ? TWorkspaceType["databases"][TName] : DatabaseType, TAi>} A `Database` instance representing the specified database.
*/
database(name) {
return new Database(this.connection, name, this.name, this._ai);
}
/**
* Creates a new database in the workspace with the specified schema.
*
* @typeParam TType - The type of the database to create.
*
* @param {DatabaseSchema<TType>} schema - The schema defining the structure of the database.
*
* @returns {Promise<Database<TType, TAi>>} A promise that resolves to the created `Database` instance.
*/
createDatabase(schema) {
return Database.create(this.connection, schema, this.name, this._ai);
}
/**
* Drops a specific database from the workspace.
*
* @param {WorkspaceDatabaseName<TWorkspaceType> | (string & {})} name - The name of the database to drop.
*
* @returns {Promise<[ResultSetHeader, FieldPacket[]]>} A promise that resolves when the database is dropped.
*/
dropDatabase(name) {
return Database.drop(this.connection, name);
}
/**
* Retrieves information about all databases in the workspace, optionally including extended details.
*
* @typeParam TExtended - A boolean indicating whether extended information is requested.
*
* @param {TExtended} [extended] - Whether to include extended information.
*
* @returns {Promise<(TExtended extends true ? DatabaseInfoExtended<WorkspaceDatabaseName<TWorkspaceType>> : DatabaseInfo<WorkspaceDatabaseName<TWorkspaceType>>)[]>} A promise that resolves to an array of database information objects.
*/
async showDatabasesInfo(extended) {

@@ -895,19 +559,5 @@ const clauses = ["SHOW DATABASES"];

_ai;
/**
* Constructs a new `SingleStoreClient` instance.
*
* @param {SingleStoreClientConfig<TAi>} [config] - The configuration object for initializing the `SingleStoreClient`.
*/
constructor(config) {
this._ai = config?.ai;
}
/**
* Connects to a workspace within the SingleStore environment.
*
* @typeParam TWorkspaceType - The type of the workspace to connect to.
*
* @param {WorkspaceConfig<TWorkspaceType, TAi>} config - The configuration object for connecting to the workspace.
*
* @returns {Workspace<TWorkspaceType, TAi>} A `Workspace` instance representing the connected workspace.
*/
workspace(config) {

@@ -914,0 +564,0 @@ return Workspace.connect({ ...config, ai: this._ai });

2

package.json
{
"name": "@singlestore/client",
"version": "0.0.31",
"version": "0.0.32",
"license": "Apache-2.0",

@@ -5,0 +5,0 @@ "sideEffects": false,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc