Database
Overview
Module
- package:
@aerokit/sdk/db - source: db/database.ts
- last updated:
This module provides a Database class that serves as an interface for interacting with relational databases in the Dirigible environment. It includes functionalities for executing SQL queries, managing database connections, and retrieving metadata about the database structure. The module also defines a set of SQL type constants and helper functions for handling specific data types like CLOBs and BLOBs.
Key Features
- SQL Execution: Execute arbitrary SQL queries and updates against the connected database.
- Metadata Retrieval: Access detailed metadata about database schemas, tables, columns, and other structural elements.
- Type Handling: Provides utilities for working with various SQL data types, including CLOBs and BLOBs, with special handling for HANA databases.
- Database System Detection: Automatically detects the underlying database system to apply appropriate handling for specific data types and features.
- Prepared Statements: Support for prepared statements to enhance security and performance when executing parameterized queries.
Use Cases
- Performing database operations such as querying, inserting, updating, and deleting records in a relational database.
- Retrieving and analyzing database metadata to understand the structure of the database and its components.
- Handling large data types like CLOBs and BLOBs in a way that is compatible with different database systems, including HANA.
- Implementing data access layers in applications that require interaction with relational databases, while abstracting away database-specific details.
Example Usage
import { Database, SQLTypes } from "@aerokit/sdk/db";
// Execute a simple query
const resultSet = Database.executeQuery("SELECT * FROM Users WHERE age > ?", [30], [SQLTypes.INTEGER]);
while (resultSet.next()) {
console.log(resultSet.getString("name"));
}
// Retrieve database metadata
const metadata = Database.getMetadata();
console.log(metadata.databaseProductName);Classes
PreparedStatement
close()
tsclose(): void;Returns
- Type:
void- Description:
getResultSet()
tsgetResultSet(): ResultSet;Returns
- Type:
ResultSet- Description:
execute()
tsexecute(): boolean;Returns
- Type:
boolean- Description:
executeQuery()
tsexecuteQuery(): ResultSet;Returns
- Type:
ResultSet- Description:
executeUpdate()
tsexecuteUpdate(): number;Returns
- Type:
number- Description:
setNull()
tssetNull(index: number, sqlType: number): void;
Parameter Type Description indexnumbersqlTypenumberReturns
- Type:
void- Description:
setBinaryStream()
tssetBinaryStream(parameterIndex: number, inputStream: InputStream, length: number): void;
Parameter Type Description parameterIndexnumberinputStreamInputStreamlengthnumberReturns
- Type:
void- Description:
setBoolean()
tssetBoolean(index: number, value: boolean): void;
Parameter Type Description indexnumbervaluebooleanReturns
- Type:
void- Description:
setByte()
tssetByte(index: number, value: any): void;
Parameter Type Description indexnumbervalueanyReturns
- Type:
void- Description:
setBlob()
tssetBlob(index: number, value: any): void;
Parameter Type Description indexnumbervalueanyReturns
- Type:
void- Description:
setClob()
tssetClob(index: number, value: any): void;
Parameter Type Description indexnumbervalueanyReturns
- Type:
void- Description:
setNClob()
tssetNClob(index: number, value: any): void;
Parameter Type Description indexnumbervalueanyReturns
- Type:
void- Description:
setBytesNative()
tssetBytesNative(index: number, value: any): void;
Parameter Type Description indexnumbervalueanyReturns
- Type:
void- Description:
setBytes()
tssetBytes(index: number, value: any): void;
Parameter Type Description indexnumbervalueanyReturns
- Type:
void- Description:
setDate()
tssetDate(index: number, value: any): void;
Parameter Type Description indexnumbervalueanyReturns
- Type:
void- Description:
setDouble()
tssetDouble(index: number, value: number): void;
Parameter Type Description indexnumbervaluenumberReturns
- Type:
void- Description:
setFloat()
tssetFloat(index: number, value: number): void;
Parameter Type Description indexnumbervaluenumberReturns
- Type:
void- Description:
setInt()
tssetInt(index: number, value: number): void;
Parameter Type Description indexnumbervaluenumberReturns
- Type:
void- Description:
setLong()
tssetLong(index: number, value: number): void;
Parameter Type Description indexnumbervaluenumberReturns
- Type:
void- Description:
setShort()
tssetShort(index: number, value: number): void;
Parameter Type Description indexnumbervaluenumberReturns
- Type:
void- Description:
setString()
tssetString(index: number, value: string): void;
Parameter Type Description indexnumbervaluestringReturns
- Type:
void- Description:
setTime()
tssetTime(index: number, value: any): void;
Parameter Type Description indexnumbervalueanyReturns
- Type:
void- Description:
setTimestamp()
tssetTimestamp(index: number, value: any): void;
Parameter Type Description indexnumbervalueanyReturns
- Type:
void- Description:
setBigDecimal()
tssetBigDecimal(index: number, value: number): void;
Parameter Type Description indexnumbervaluenumberReturns
- Type:
void- Description:
setNString()
tssetNString(index: number, value: string): void;
Parameter Type Description indexnumbervaluestringReturns
- Type:
void- Description:
addBatch()
tsaddBatch(): void;Returns
- Type:
void- Description:
executeBatch()
tsexecuteBatch(): void;Returns
- Type:
void- Description:
getMetaData()
tsgetMetaData(): any;Returns
- Type:
any- Description:
getMoreResults()
tsgetMoreResults(): boolean;Returns
- Type:
boolean- Description:
getParameterMetaData()
tsgetParameterMetaData(): any;Returns
- Type:
any- Description:
getSQLWarning()
tsgetSQLWarning(): any;Returns
- Type:
any- Description:
isClosed()
tsisClosed(): boolean;Returns
- Type:
boolean- Description:
CallableStatement
getResultSet()
tsgetResultSet(): ResultSet;Returns
- Type:
ResultSet- Description:
executeQuery()
tsexecuteQuery(): ResultSet;Returns
- Type:
ResultSet- Description:
executeUpdate()
tsexecuteUpdate(): number;Returns
- Type:
number- Description:
registerOutParameter()
tsregisterOutParameter(parameterIndex: number, sqlType: any): void;
Parameter Type Description parameterIndexnumbersqlTypeanyReturns
- Type:
void- Description:
registerOutParameterByScale()
tsregisterOutParameterByScale(parameterIndex: number, sqlType: any, scale: number): void;
Parameter Type Description parameterIndexnumbersqlTypeanyscalenumberReturns
- Type:
void- Description:
registerOutParameterByTypeName()
tsregisterOutParameterByTypeName(parameterIndex: number, sqlType: any, typeName: string): void;
Parameter Type Description parameterIndexnumbersqlTypeanytypeNamestringReturns
- Type:
void- Description:
wasNull()
tswasNull(): boolean;Returns
- Type:
boolean- Description:
getString()
tsgetString(parameterIndex: number): string;
Parameter Type Description parameterIndexnumberReturns
- Type:
string- Description:
getBoolean()
tsgetBoolean(parameterIndex: number): boolean;
Parameter Type Description parameterIndexnumberReturns
- Type:
boolean- Description:
getByte()
tsgetByte(parameterIndex: number): any;
Parameter Type Description parameterIndexnumberReturns
- Type:
any- Description:
getShort()
tsgetShort(parameterIndex: number): number;
Parameter Type Description parameterIndexnumberReturns
- Type:
number- Description:
getInt()
tsgetInt(parameterIndex: number): number;
Parameter Type Description parameterIndexnumberReturns
- Type:
number- Description:
getLong()
tsgetLong(parameterIndex: number): number;
Parameter Type Description parameterIndexnumberReturns
- Type:
number- Description:
getFloat()
tsgetFloat(parameterIndex: number): number;
Parameter Type Description parameterIndexnumberReturns
- Type:
number- Description:
getDouble()
tsgetDouble(parameterIndex: number): number;
Parameter Type Description parameterIndexnumberReturns
- Type:
number- Description:
getDate()
tsgetDate(parameterIndex: number): Date;
Parameter Type Description parameterIndexnumberReturns
- Type:
Date- Description:
getTime()
tsgetTime(parameterIndex: number): Date;
Parameter Type Description parameterIndexnumberReturns
- Type:
Date- Description:
getTimestamp()
tsgetTimestamp(parameterIndex: number): Date;
Parameter Type Description parameterIndexnumberReturns
- Type:
Date- Description:
getObject()
tsgetObject(parameterIndex: number): any;
Parameter Type Description parameterIndexnumberReturns
- Type:
any- Description:
getBigDecimal()
tsgetBigDecimal(parameterIndex: number): number;
Parameter Type Description parameterIndexnumberReturns
- Type:
number- Description:
getRef()
tsgetRef(parameterIndex: number): any;
Parameter Type Description parameterIndexnumberReturns
- Type:
any- Description:
getBytes()
tsgetBytes(parameterIndex: number): void;
Parameter Type Description parameterIndexnumberReturns
- Type:
void- Description:
getBytesNative()
tsgetBytesNative(parameterIndex: number): void;
Parameter Type Description parameterIndexnumberReturns
- Type:
void- Description:
getBlob()
tsgetBlob(parameterIndex: number): any;
Parameter Type Description parameterIndexnumberReturns
- Type:
any- Description:
getBlobNative()
tsgetBlobNative(parameterIndex: number): any;
Parameter Type Description parameterIndexnumberReturns
- Type:
any- Description:
getClob()
tsgetClob(parameterIndex: number): any;
Parameter Type Description parameterIndexnumberReturns
- Type:
any- Description:
getNClob()
tsgetNClob(parameterIndex: any): any;
Parameter Type Description parameterIndexanyReturns
- Type:
any- Description:
getNString()
tsgetNString(parameterIndex: any): string;
Parameter Type Description parameterIndexanyReturns
- Type:
string- Description:
getArray()
tsgetArray(parameterIndex: any): void;
Parameter Type Description parameterIndexanyReturns
- Type:
void- Description:
getURL()
tsgetURL(parameterIndex: any): any;
Parameter Type Description parameterIndexanyReturns
- Type:
any- Description:
getRowId()
tsgetRowId(parameterIndex: any): any;
Parameter Type Description parameterIndexanyReturns
- Type:
any- Description:
getSQLXML()
tsgetSQLXML(parameterIndex: any): any;
Parameter Type Description parameterIndexanyReturns
- Type:
any- Description:
setURL()
tssetURL(parameterIndex: number, value: any): void;
Parameter Type Description parameterIndexnumbervalueanyReturns
- Type:
void- Description:
setNull()
tssetNull(parameterIndex: number, sqlTypeStr: any, typeName: string): void;
Parameter Type Description parameterIndexnumbersqlTypeStranytypeNamestringReturns
- Type:
void- Description:
setBoolean()
tssetBoolean(parameterIndex: number, value: boolean): void;
Parameter Type Description parameterIndexnumbervaluebooleanReturns
- Type:
void- Description:
setByte()
tssetByte(parameterIndex: number, value: any): void;
Parameter Type Description parameterIndexnumbervalueanyReturns
- Type:
void- Description:
setShort()
tssetShort(parameterIndex: number, value: number): void;
Parameter Type Description parameterIndexnumbervaluenumberReturns
- Type:
void- Description:
setInt()
tssetInt(parameterIndex: number, value: number): void;
Parameter Type Description parameterIndexnumbervaluenumberReturns
- Type:
void- Description:
setLong()
tssetLong(parameterIndex: number, value: number): void;
Parameter Type Description parameterIndexnumbervaluenumberReturns
- Type:
void- Description:
setFloat()
tssetFloat(parameterIndex: number, value: number): void;
Parameter Type Description parameterIndexnumbervaluenumberReturns
- Type:
void- Description:
setDouble()
tssetDouble(parameterIndex: number, value: number): void;
Parameter Type Description parameterIndexnumbervaluenumberReturns
- Type:
void- Description:
setBigDecimal()
tssetBigDecimal(parameterIndex: number, value: number): void;
Parameter Type Description parameterIndexnumbervaluenumberReturns
- Type:
void- Description:
setString()
tssetString(parameterIndex: number, value: string): void;
Parameter Type Description parameterIndexnumbervaluestringReturns
- Type:
void- Description:
setBytes()
tssetBytes(parameterIndex: number, value: any): void;
Parameter Type Description parameterIndexnumbervalueanyReturns
- Type:
void- Description:
setDate()
tssetDate(parameterIndex: number, value: any): void;
Parameter Type Description parameterIndexnumbervalueanyReturns
- Type:
void- Description:
setTime()
tssetTime(parameterIndex: number, value: any): void;
Parameter Type Description parameterIndexnumbervalueanyReturns
- Type:
void- Description:
setTimestamp()
tssetTimestamp(parameterIndex: number, value: any): void;
Parameter Type Description parameterIndexnumbervalueanyReturns
- Type:
void- Description:
setAsciiStream()
tssetAsciiStream(parameterIndex: number, inputStream: InputStream, length: number): void;
Parameter Type Description parameterIndexnumberinputStreamInputStreamlengthnumberReturns
- Type:
void- Description:
setBinaryStream()
tssetBinaryStream(parameterIndex: number, inputStream: InputStream, length: number): void;
Parameter Type Description parameterIndexnumberinputStreamInputStreamlengthnumberReturns
- Type:
void- Description:
setObject()
tssetObject(parameterIndex: number, value: any, targetSqlType: number, scale: number): void;
Parameter Type Description parameterIndexnumbervalueanytargetSqlTypenumberscalenumberReturns
- Type:
void- Description:
setRowId()
tssetRowId(parameterIndex: number, value: number): void;
Parameter Type Description parameterIndexnumbervaluenumberReturns
- Type:
void- Description:
setNString()
tssetNString(parameterIndex: number, value: string): void;
Parameter Type Description parameterIndexnumbervaluestringReturns
- Type:
void- Description:
setSQLXML()
tssetSQLXML(parameterIndex: number, value: any): void;
Parameter Type Description parameterIndexnumbervalueanyReturns
- Type:
void- Description:
setBlob()
tssetBlob(parameterIndex: number, value: any): void;
Parameter Type Description parameterIndexnumbervalueanyReturns
- Type:
void- Description:
setClob()
tssetClob(parameterIndex: number, value: any): void;
Parameter Type Description parameterIndexnumbervalueanyReturns
- Type:
void- Description:
setNClob()
tssetNClob(parameterIndex: number, value: any): void;
Parameter Type Description parameterIndexnumbervalueanyReturns
- Type:
void- Description:
execute()
tsexecute(): boolean;Returns
- Type:
boolean- Description:
getMoreResults()
tsgetMoreResults(): boolean;Returns
- Type:
boolean- Description:
getParameterMetaData()
tsgetParameterMetaData(): any;Returns
- Type:
any- Description:
isClosed()
tsisClosed(): boolean;Returns
- Type:
boolean- Description:
close()
tsclose(): void;Returns
- Type:
void- Description:
ResultSet
toJson()
Converts the ResultSet into a JSON array of objects.
tstoJson(limited: boolean, stringify: boolean): void;
Parameter Type Description limitedbooleanWhether to use limited JSON conversion (optimized). stringifybooleanWhether to return the JSON as a string or a parsed array. Returns
- Type:
void- Description: A JavaScript array of objects representing the result set, or a string if stringify is true.
close()
tsclose(): void;Returns
- Type:
void- Description:
getBigDecimal()
tsgetBigDecimal(identifier: any): any;
Parameter Type Description identifieranyReturns
- Type:
any- Description:
getBoolean()
tsgetBoolean(identifier: any): boolean;
Parameter Type Description identifieranyReturns
- Type:
boolean- Description:
getByte()
tsgetByte(identifier: any): any;
Parameter Type Description identifieranyReturns
- Type:
any- Description:
getBytes()
tsgetBytes(identifier: any): void;
Parameter Type Description identifieranyReturns
- Type:
void- Description:
getBytesNative()
tsgetBytesNative(identifier: any): void;
Parameter Type Description identifieranyReturns
- Type:
void- Description:
getBlob()
tsgetBlob(identifier: any): any;
Parameter Type Description identifieranyReturns
- Type:
any- Description:
getBlobNative()
tsgetBlobNative(identifier: any): any;
Parameter Type Description identifieranyReturns
- Type:
any- Description:
getClob()
tsgetClob(identifier: any): any;
Parameter Type Description identifieranyReturns
- Type:
any- Description:
getNClob()
tsgetNClob(identifier: any): any;
Parameter Type Description identifieranyReturns
- Type:
any- Description:
getDate()
tsgetDate(identifier: any): Date;
Parameter Type Description identifieranyReturns
- Type:
Date- Description:
getDouble()
tsgetDouble(identifier: any): number;
Parameter Type Description identifieranyReturns
- Type:
number- Description:
getFloat()
tsgetFloat(identifier: any): number;
Parameter Type Description identifieranyReturns
- Type:
number- Description:
getInt()
tsgetInt(identifier: any): number;
Parameter Type Description identifieranyReturns
- Type:
number- Description:
getLong()
tsgetLong(identifier: any): number;
Parameter Type Description identifieranyReturns
- Type:
number- Description:
getShort()
tsgetShort(identifier: any): number;
Parameter Type Description identifieranyReturns
- Type:
number- Description:
getString()
tsgetString(identifier: any): string;
Parameter Type Description identifieranyReturns
- Type:
string- Description:
getTime()
tsgetTime(identifier: any): Date;
Parameter Type Description identifieranyReturns
- Type:
Date- Description:
getTimestamp()
tsgetTimestamp(identifier: any): Date;
Parameter Type Description identifieranyReturns
- Type:
Date- Description:
isAfterLast()
tsisAfterLast(): boolean;Returns
- Type:
boolean- Description:
isBeforeFirst()
tsisBeforeFirst(): boolean;Returns
- Type:
boolean- Description:
isClosed()
tsisClosed(): boolean;Returns
- Type:
boolean- Description:
isFirst()
tsisFirst(): boolean;Returns
- Type:
boolean- Description:
isLast()
tsisLast(): boolean;Returns
- Type:
boolean- Description:
next()
tsnext(): boolean;Returns
- Type:
boolean- Description:
getMetaData()
tsgetMetaData(): any;Returns
- Type:
any- Description:
getNString()
tsgetNString(columnIndex: number): string;
Parameter Type Description columnIndexnumberReturns
- Type:
string- Description:
Connection
isOfType()
Checks if the connection is for a specific database system.
tsisOfType(databaseSystem: DatabaseSystem): boolean;
Parameter Type Description databaseSystemDatabaseSystemReturns
- Type:
boolean- Description:
getDatabaseSystem()
Returns the type of the underlying database system as a DatabaseSystem enum.
tsgetDatabaseSystem(): DatabaseSystem;Returns
- Type:
DatabaseSystem- Description:
prepareStatement()
Creates a new PreparedStatement object for sending parameterized SQL statements to the database.
tsprepareStatement(sql: string): PreparedStatement;
Parameter Type Description sqlstringReturns
- Type:
PreparedStatement- Description:
prepareCall()
Creates a CallableStatement object for calling database stored procedures or functions.
tsprepareCall(sql: string): CallableStatement;
Parameter Type Description sqlstringReturns
- Type:
CallableStatement- Description:
close()
tsclose(): void;Returns
- Type:
void- Description:
commit()
tscommit(): void;Returns
- Type:
void- Description:
getAutoCommit()
tsgetAutoCommit(): boolean;Returns
- Type:
boolean- Description:
getCatalog()
tsgetCatalog(): string;Returns
- Type:
string- Description:
getSchema()
tsgetSchema(): string;Returns
- Type:
string- Description:
getTransactionIsolation()
tsgetTransactionIsolation(): number;Returns
- Type:
number- Description:
isClosed()
tsisClosed(): boolean;Returns
- Type:
boolean- Description:
isReadOnly()
tsisReadOnly(): boolean;Returns
- Type:
boolean- Description:
isValid()
tsisValid(): boolean;Returns
- Type:
boolean- Description:
rollback()
tsrollback(): void;Returns
- Type:
void- Description:
setAutoCommit()
tssetAutoCommit(autoCommit: boolean): void;
Parameter Type Description autoCommitbooleanReturns
- Type:
void- Description:
setCatalog()
tssetCatalog(catalog: string): void;
Parameter Type Description catalogstringReturns
- Type:
void- Description:
setReadOnly()
tssetReadOnly(readOnly: boolean): void;
Parameter Type Description readOnlybooleanReturns
- Type:
void- Description:
setSchema()
tssetSchema(schema: string): void;
Parameter Type Description schemastringReturns
- Type:
void- Description:
setTransactionIsolation()
tssetTransactionIsolation(transactionIsolation: number): void;
Parameter Type Description transactionIsolationnumberReturns
- Type:
void- Description:
getMetaData()
tsgetMetaData(): any;Returns
- Type:
any- Description:
Database
getDataSources()
Returns a list of available data source names.
tsstatic getDataSources(): void;Returns
- Type:
void- Description:
getMetadata()
Returns database metadata for the specified data source.
tsstatic getMetadata(datasourceName: string): DatabaseMetadata;
Parameter Type Description datasourceNamestringReturns
- Type:
DatabaseMetadata- Description:
getProductName()
Returns the product name of the underlying database system.
tsstatic getProductName(datasourceName: string): string;
Parameter Type Description datasourceNamestringReturns
- Type:
string- Description:
getConnection()
Gets a new database connection object.
tsstatic getConnection(datasourceName: string): Connection;
Parameter Type Description datasourceNamestringReturns
- Type:
Connection- Description:
