@tragedy-labs/sprite
Version:
A TypeScript driver for ArcadeDB
75 lines (74 loc) • 3.48 kB
TypeScript
import { DatabaseSession, ISpriteDatabaseExistingSession, ISpriteDatabaseNewSession } from '../session/DatabaseSession.js';
import { ArcadeGetSchemaResponse, ArcadeSqlExplanation } from '../types/database.js';
export declare enum Dialect {
SQL = "sql",
SQLSCRIPT = "sqlscript",
GRAPHQL = "graphql",
CYPHER = "cypher",
GREMLIN = "gremlin",
MONGO = "mongo"
}
export type ArcadeQueryParameters = Record<string, boolean | string | number>;
export type ArcadeCommand = string | {
command: string;
params: Record<string, unknown>;
};
/**
* The Query languages supported by ArcadeDB, supplied as a parameter
* to `SpriteDatabase.query()` and `SpriteDatabase.command()`
*/
export type ArcadeSupportedQueryLanguages = 'sql' | 'sqlscript' | 'graphql' | 'cypher' | 'gremlin' | 'mongo';
/**
* Static methods for common database operations.
*/
declare class Database {
/**
* Set the credentials that the database client should use
* when interacting with the ArcadeDB server.
* @param username The username to authenticate with.
* @param password The password to authenticate with.
* @returns `true` if the credentials were set.
* @throws `Error` if the credentials could not be set.
*/
static createSession: (params: ISpriteDatabaseExistingSession | ISpriteDatabaseNewSession) => DatabaseSession;
/**
* Static method to execute a command on the database.s
* @param session The {@link DatabaseSession `DatabaseSession`} to execute the command on.
* @param language The language of the command.
* @param command The command to execute.
* @param transaction The transaction to execute the command in.
* @returns The result of the command.
*/
static command: <T>(session: DatabaseSession, language: ArcadeSupportedQueryLanguages, command: ArcadeCommand, parameters?: Record<string, unknown>) => Promise<T>;
/**
* Static method to query the database.
* @param session The {@link DatabaseSession `DatabaseSession`} to execute the query on.
* @param language The language of the query.
* @param command The query to execute.
* @param parameters
* @returns The result-set of the query.
*/
static query: <T>(session: DatabaseSession, language: ArcadeSupportedQueryLanguages, command: string, parameters?: ArcadeQueryParameters) => Promise<T[]>;
/**
* Static method to get the schema of the database.
* @param session The {@link DatabaseSession `DatabaseSession`} to target for the schema.
* @returns The schema of the database.
*/
static getSchema: (session: DatabaseSession) => Promise<ArcadeGetSchemaResponse>;
/**
* Static method to explain a query.
* @param session The {@link DatabaseSession `DatabaseSession`} to target for the explanation.
* @param sql The SQL query to explain.
* @returns The explanation of the query.
*/
static explain: (session: DatabaseSession, sql: string) => Promise<ArcadeSqlExplanation>;
/**
* Check to see if the database exists.
* @param session The session to use to check for the database.
* @param databaseName The name of the database to check for existence.
* @returns `true` if database exists, `false` if not
* @throws `Error` if the existence of the database could not be verified.
*/
static exists: (session: DatabaseSession, databaseName: string) => Promise<boolean>;
}
export { Database };