db/sql
Documentation
- source: db/sql.ts
Overview
Classes
SQLBuilder
prepareBuilder()
Hook for subclasses to set up the native builder object (e.g., calling .select()).
tsprepareBuilder(builder: any): any;
Parameter Type Description builderanyReturns
- Type:
any- Description:
parameters()
tsparameters(): void;Returns
- Type:
void- Description:
addParameter()
Adds parameter(s) to the internal list. Handles single values and arrays of values.
tsaddParameter(value: any): void;
Parameter Type Description valueanyReturns
- Type:
void- Description:
build()
Builds and returns the final SQL string.
tsbuild(): string;Returns
- Type:
string- Description:
getDialect()
Factory method to get a dialect-specific SQLBuilder instance.
tsstatic getDialect(connection: Connection): SQLBuilder;
Parameter Type Description connectionConnectionReturns
- Type:
SQLBuilder- Description:
select()
tsselect(): SelectBuilder;Returns
- Type:
SelectBuilder- Description:
insert()
tsinsert(): InsertBuilder;Returns
- Type:
InsertBuilder- Description:
update()
tsupdate(): UpdateBuilder;Returns
- Type:
UpdateBuilder- Description:
delete()
tsdelete(): DeleteBuilder;Returns
- Type:
DeleteBuilder- Description:
nextval()
tsnextval(name: string): NextvalBuilder;
Parameter Type Description namestringReturns
- Type:
NextvalBuilder- Description:
create()
tscreate(): CreateBuilder;Returns
- Type:
CreateBuilder- Description:
drop()
tsdrop(): DropBuilder;Returns
- Type:
DropBuilder- Description:
SelectBuilder
parameters()
tsparameters(): void;Returns
- Type:
void- Description:
addParameter()
Adds parameter(s) to the internal list. Handles single values and arrays of values.
tsaddParameter(value: any): void;
Parameter Type Description valueanyReturns
- Type:
void- Description:
build()
Builds and returns the final SQL string.
tsbuild(): string;Returns
- Type:
string- Description:
prepareBuilder()
Hook for subclasses to set up the native builder object (e.g., calling .select()).
tsprepareBuilder(builder: any): any;
Parameter Type Description builderanyReturns
- Type:
any- Description:
distinct()
tsdistinct(): SelectBuilder;Returns
- Type:
SelectBuilder- Description:
forUpdate()
tsforUpdate(): SelectBuilder;Returns
- Type:
SelectBuilder- Description:
column()
tscolumn(column: string): SelectBuilder;
Parameter Type Description columnstringReturns
- Type:
SelectBuilder- Description:
from()
tsfrom(table: string, alias: string): SelectBuilder;
Parameter Type Description tablestringaliasstringReturns
- Type:
SelectBuilder- Description:
join()
tsjoin(table: string, on: string, alias: string, parameters: any): SelectBuilder;
Parameter Type Description tablestringonstringaliasstringparametersanyReturns
- Type:
SelectBuilder- Description:
innerJoin()
tsinnerJoin(table: string, on: string, alias: string, parameters: any): SelectBuilder;
Parameter Type Description tablestringonstringaliasstringparametersanyReturns
- Type:
SelectBuilder- Description:
outerJoin()
tsouterJoin(table: string, on: string, alias: string, parameters: any): SelectBuilder;
Parameter Type Description tablestringonstringaliasstringparametersanyReturns
- Type:
SelectBuilder- Description:
leftJoin()
tsleftJoin(table: string, on: string, alias: string, parameters: any): SelectBuilder;
Parameter Type Description tablestringonstringaliasstringparametersanyReturns
- Type:
SelectBuilder- Description:
rightJoin()
tsrightJoin(table: string, on: string, alias: string, parameters: any): SelectBuilder;
Parameter Type Description tablestringonstringaliasstringparametersanyReturns
- Type:
SelectBuilder- Description:
fullJoin()
tsfullJoin(table: string, on: string, alias: string, parameters: any): SelectBuilder;
Parameter Type Description tablestringonstringaliasstringparametersanyReturns
- Type:
SelectBuilder- Description:
where()
Sets the WHERE condition.
tswhere(condition: string, parameters: any): SelectBuilder;
Parameter Type Description conditionstringThe SQL condition string (e.g., "column1 = ?"). parametersanyOptional parameters to replace '?' in the condition. Returns
- Type:
SelectBuilder- Description:
order()
tsorder(column: string, asc: boolean): SelectBuilder;
Parameter Type Description columnstringascbooleanReturns
- Type:
SelectBuilder- Description:
group()
tsgroup(column: string): SelectBuilder;
Parameter Type Description columnstringReturns
- Type:
SelectBuilder- Description:
limit()
tslimit(limit: number): SelectBuilder;
Parameter Type Description limitnumberReturns
- Type:
SelectBuilder- Description:
offset()
tsoffset(offset: number): SelectBuilder;
Parameter Type Description offsetnumberReturns
- Type:
SelectBuilder- Description:
having()
tshaving(having: string): SelectBuilder;
Parameter Type Description havingstringReturns
- Type:
SelectBuilder- Description:
union()
tsunion(select: string): SelectBuilder;
Parameter Type Description selectstringReturns
- Type:
SelectBuilder- Description:
InsertBuilder
parameters()
tsparameters(): void;Returns
- Type:
void- Description:
addParameter()
Adds parameter(s) to the internal list. Handles single values and arrays of values.
tsaddParameter(value: any): void;
Parameter Type Description valueanyReturns
- Type:
void- Description:
build()
Builds and returns the final SQL string.
tsbuild(): string;Returns
- Type:
string- Description:
prepareBuilder()
Hook for subclasses to set up the native builder object (e.g., calling .select()).
tsprepareBuilder(builder: any): any;
Parameter Type Description builderanyReturns
- Type:
any- Description:
into()
tsinto(table: string): InsertBuilder;
Parameter Type Description tablestringReturns
- Type:
InsertBuilder- Description:
column()
tscolumn(column: string): InsertBuilder;
Parameter Type Description columnstringReturns
- Type:
InsertBuilder- Description:
value()
Sets the value for the last column specified.
tsvalue(value: string, parameters: any): InsertBuilder;
Parameter Type Description valuestringThe value placeholder (e.g., "?") or literal. parametersanyOptional parameters if a placeholder was used. Returns
- Type:
InsertBuilder- Description:
select()
tsselect(select: string): InsertBuilder;
Parameter Type Description selectstringReturns
- Type:
InsertBuilder- Description:
UpdateBuilder
parameters()
tsparameters(): void;Returns
- Type:
void- Description:
addParameter()
Adds parameter(s) to the internal list. Handles single values and arrays of values.
tsaddParameter(value: any): void;
Parameter Type Description valueanyReturns
- Type:
void- Description:
build()
Builds and returns the final SQL string.
tsbuild(): string;Returns
- Type:
string- Description:
prepareBuilder()
Hook for subclasses to set up the native builder object (e.g., calling .select()).
tsprepareBuilder(builder: any): any;
Parameter Type Description builderanyReturns
- Type:
any- Description:
table()
tstable(table: string): UpdateBuilder;
Parameter Type Description tablestringReturns
- Type:
UpdateBuilder- Description:
set()
Sets a column to a value.
tsset(column: string, value: string, parameters: any): UpdateBuilder;
Parameter Type Description columnstringThe column name. valuestringThe value placeholder (e.g., "?") or literal. parametersanyOptional parameters if a placeholder was used. Returns
- Type:
UpdateBuilder- Description:
where()
Sets the WHERE condition for the update.
tswhere(condition: string, parameters: any): UpdateBuilder;
Parameter Type Description conditionstringThe SQL condition string (e.g., "column1 = ?"). parametersanyOptional parameters to replace '?' in the condition. Returns
- Type:
UpdateBuilder- Description:
DeleteBuilder
parameters()
tsparameters(): void;Returns
- Type:
void- Description:
addParameter()
Adds parameter(s) to the internal list. Handles single values and arrays of values.
tsaddParameter(value: any): void;
Parameter Type Description valueanyReturns
- Type:
void- Description:
build()
Builds and returns the final SQL string.
tsbuild(): string;Returns
- Type:
string- Description:
prepareBuilder()
Hook for subclasses to set up the native builder object (e.g., calling .select()).
tsprepareBuilder(builder: any): any;
Parameter Type Description builderanyReturns
- Type:
any- Description:
from()
tsfrom(table: string): DeleteBuilder;
Parameter Type Description tablestringReturns
- Type:
DeleteBuilder- Description:
where()
Sets the WHERE condition for the deletion.
tswhere(condition: string, parameters: any): DeleteBuilder;
Parameter Type Description conditionstringThe SQL condition string (e.g., "column1 = ?"). parametersanyOptional parameters to replace '?' in the condition. Returns
- Type:
DeleteBuilder- Description:
NextvalBuilder
parameters()
tsparameters(): void;Returns
- Type:
void- Description:
addParameter()
Adds parameter(s) to the internal list. Handles single values and arrays of values.
tsaddParameter(value: any): void;
Parameter Type Description valueanyReturns
- Type:
void- Description:
build()
Builds and returns the final SQL string.
tsbuild(): string;Returns
- Type:
string- Description:
prepareBuilder()
Hook for subclasses to set up the native builder object (e.g., calling .select()).
tsprepareBuilder(builder: any): any;
Parameter Type Description builderanyReturns
- Type:
any- Description:
CreateBuilder
prepareBuilder()
Hook for subclasses to set up the native builder object (e.g., calling .select()).
tsprepareBuilder(builder: any): any;
Parameter Type Description builderanyReturns
- Type:
any- Description:
parameters()
tsparameters(): void;Returns
- Type:
void- Description:
addParameter()
Adds parameter(s) to the internal list. Handles single values and arrays of values.
tsaddParameter(value: any): void;
Parameter Type Description valueanyReturns
- Type:
void- Description:
build()
Builds and returns the final SQL string.
tsbuild(): string;Returns
- Type:
string- Description:
table()
tstable(table: string): CreateTableBuilder;
Parameter Type Description tablestringReturns
- Type:
CreateTableBuilder- Description:
view()
tsview(view: string): CreateViewBuilder;
Parameter Type Description viewstringReturns
- Type:
CreateViewBuilder- Description:
sequence()
tssequence(sequence: string): CreateSequenceBuilder;
Parameter Type Description sequencestringReturns
- Type:
CreateSequenceBuilder- Description:
CreateTableBuilder
prepareBuilder()
Hook for subclasses to set up the native builder object (e.g., calling .select()).
tsprepareBuilder(builder: any): any;
Parameter Type Description builderanyReturns
- Type:
any- Description:
parameters()
tsparameters(): void;Returns
- Type:
void- Description:
addParameter()
Adds parameter(s) to the internal list. Handles single values and arrays of values.
tsaddParameter(value: any): void;
Parameter Type Description valueanyReturns
- Type:
void- Description:
build()
Builds and returns the final SQL string.
tsbuild(): string;Returns
- Type:
string- Description:
column()
Adds a generic column definition.
tscolumn(name: string, type: DataType, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, isIdentity: boolean, isFuzzyIndexEnabled: boolean, args: any): CreateTableBuilder;
Parameter Type Description namestringtypeDataTypeisPrimaryKeybooleanisNullablebooleanisUniquebooleanisIdentitybooleanisFuzzyIndexEnabledbooleanargsanyAdditional dialect-specific arguments passed as an array to native. Returns
- Type:
CreateTableBuilder- Description:
columnVarchar()
Adds a VARCHAR column.
tscolumnVarchar(name: string, length: number, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, isIdentity: boolean, args: any): CreateTableBuilder;
Parameter Type Description namestringlengthnumberisPrimaryKeybooleanisNullablebooleanisUniquebooleanisIdentitybooleanargsanyAdditional dialect-specific arguments passed as an array to native. Returns
- Type:
CreateTableBuilder- Description:
columnNvarchar()
Adds an NVARCHAR column.
tscolumnNvarchar(name: string, length: number, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, isIdentity: boolean, args: any): CreateTableBuilder;
Parameter Type Description namestringlengthnumberisPrimaryKeybooleanisNullablebooleanisUniquebooleanisIdentitybooleanargsanyAdditional dialect-specific arguments passed as an array to native. Returns
- Type:
CreateTableBuilder- Description:
columnChar()
Adds a CHAR column.
tscolumnChar(name: string, length: number, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, isIdentity: boolean, args: any): CreateTableBuilder;
Parameter Type Description namestringlengthnumberisPrimaryKeybooleanisNullablebooleanisUniquebooleanisIdentitybooleanargsanyAdditional dialect-specific arguments passed as an array to native. Returns
- Type:
CreateTableBuilder- Description:
columnDate()
Adds a DATE column.
tscolumnDate(name: string, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, args: any): CreateTableBuilder;
Parameter Type Description namestringisPrimaryKeybooleanisNullablebooleanisUniquebooleanargsanyAdditional dialect-specific arguments passed as an array to native. Returns
- Type:
CreateTableBuilder- Description:
columnTime()
Adds a TIME column.
tscolumnTime(name: string, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, args: any): CreateTableBuilder;
Parameter Type Description namestringisPrimaryKeybooleanisNullablebooleanisUniquebooleanargsanyAdditional dialect-specific arguments passed as an array to native. Returns
- Type:
CreateTableBuilder- Description:
columnTimestamp()
Adds a TIMESTAMP column.
tscolumnTimestamp(name: string, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, args: any): CreateTableBuilder;
Parameter Type Description namestringisPrimaryKeybooleanisNullablebooleanisUniquebooleanargsanyAdditional dialect-specific arguments passed as an array to native. Returns
- Type:
CreateTableBuilder- Description:
columnInteger()
Adds an INTEGER column.
tscolumnInteger(name: string, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, isIdentity: boolean, args: any): CreateTableBuilder;
Parameter Type Description namestringisPrimaryKeybooleanisNullablebooleanisUniquebooleanisIdentitybooleanargsanyAdditional dialect-specific arguments passed as an array to native. Returns
- Type:
CreateTableBuilder- Description:
columnTinyint()
Adds a TINYINT column.
tscolumnTinyint(name: string, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, args: any): CreateTableBuilder;
Parameter Type Description namestringisPrimaryKeybooleanisNullablebooleanisUniquebooleanargsanyAdditional dialect-specific arguments passed as an array to native. Returns
- Type:
CreateTableBuilder- Description:
columnBigint()
Adds a BIGINT column.
tscolumnBigint(name: string, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, isIdentity: boolean, args: any): CreateTableBuilder;
Parameter Type Description namestringisPrimaryKeybooleanisNullablebooleanisUniquebooleanisIdentitybooleanargsanyAdditional dialect-specific arguments passed as an array to native. Returns
- Type:
CreateTableBuilder- Description:
columnSmallint()
Adds a SMALLINT column.
tscolumnSmallint(name: string, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, args: any): CreateTableBuilder;
Parameter Type Description namestringisPrimaryKeybooleanisNullablebooleanisUniquebooleanargsanyAdditional dialect-specific arguments passed as an array to native. Returns
- Type:
CreateTableBuilder- Description:
columnReal()
Adds a REAL column.
tscolumnReal(name: string, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, args: any): CreateTableBuilder;
Parameter Type Description namestringisPrimaryKeybooleanisNullablebooleanisUniquebooleanargsanyAdditional dialect-specific arguments passed as an array to native. Returns
- Type:
CreateTableBuilder- Description:
columnDouble()
Adds a DOUBLE column.
tscolumnDouble(name: string, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, args: any): CreateTableBuilder;
Parameter Type Description namestringisPrimaryKeybooleanisNullablebooleanisUniquebooleanargsanyAdditional dialect-specific arguments passed as an array to native. Returns
- Type:
CreateTableBuilder- Description:
columnBoolean()
Adds a BOOLEAN column.
tscolumnBoolean(name: string, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, args: any): CreateTableBuilder;
Parameter Type Description namestringisPrimaryKeybooleanisNullablebooleanisUniquebooleanargsanyAdditional dialect-specific arguments passed as an array to native. Returns
- Type:
CreateTableBuilder- Description:
columnBlob()
Adds a BLOB column.
tscolumnBlob(name: string, isNullable: boolean, args: any): CreateTableBuilder;
Parameter Type Description namestringisNullablebooleanargsanyAdditional dialect-specific arguments passed as an array to native. Returns
- Type:
CreateTableBuilder- Description:
columnDecimal()
Adds a DECIMAL column with precision and scale.
tscolumnDecimal(name: string, precision: number, scale: number, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, isIdentity: boolean, args: any): CreateTableBuilder;
Parameter Type Description namestringprecisionnumberscalenumberisPrimaryKeybooleanisNullablebooleanisUniquebooleanisIdentitybooleanargsanyAdditional dialect-specific arguments passed as an array to native. Returns
- Type:
CreateTableBuilder- Description:
primaryKey()
tsprimaryKey(columns: any, name: string): CreateTableBuilder;
Parameter Type Description columnsanynamestringReturns
- Type:
CreateTableBuilder- Description:
foreignKey()
tsforeignKey(name: string, columns: any, referencedTable: string, referencedColumns: any, referencedTableSchema: string): CreateTableBuilder;
Parameter Type Description namestringcolumnsanyreferencedTablestringreferencedColumnsanyreferencedTableSchemastringReturns
- Type:
CreateTableBuilder- Description:
unique()
tsunique(name: string, columns: any): CreateTableBuilder;
Parameter Type Description namestringcolumnsanyReturns
- Type:
CreateTableBuilder- Description:
check()
tscheck(name: string, expression: string): CreateTableBuilder;
Parameter Type Description namestringexpressionstringReturns
- Type:
CreateTableBuilder- Description:
CreateViewBuilder
prepareBuilder()
Hook for subclasses to set up the native builder object (e.g., calling .select()).
tsprepareBuilder(builder: any): any;
Parameter Type Description builderanyReturns
- Type:
any- Description:
parameters()
tsparameters(): void;Returns
- Type:
void- Description:
addParameter()
Adds parameter(s) to the internal list. Handles single values and arrays of values.
tsaddParameter(value: any): void;
Parameter Type Description valueanyReturns
- Type:
void- Description:
build()
Builds and returns the final SQL string.
tsbuild(): string;Returns
- Type:
string- Description:
column()
tscolumn(column: string): CreateViewBuilder;
Parameter Type Description columnstringReturns
- Type:
CreateViewBuilder- Description:
asSelect()
tsasSelect(select: string): CreateViewBuilder;
Parameter Type Description selectstringReturns
- Type:
CreateViewBuilder- Description:
CreateSequenceBuilder
prepareBuilder()
Hook for subclasses to set up the native builder object (e.g., calling .select()).
tsprepareBuilder(builder: any): any;
Parameter Type Description builderanyReturns
- Type:
any- Description:
parameters()
tsparameters(): void;Returns
- Type:
void- Description:
addParameter()
Adds parameter(s) to the internal list. Handles single values and arrays of values.
tsaddParameter(value: any): void;
Parameter Type Description valueanyReturns
- Type:
void- Description:
build()
Builds and returns the final SQL string.
tsbuild(): string;Returns
- Type:
string- Description:
DropBuilder
prepareBuilder()
Hook for subclasses to set up the native builder object (e.g., calling .select()).
tsprepareBuilder(builder: any): any;
Parameter Type Description builderanyReturns
- Type:
any- Description:
parameters()
tsparameters(): void;Returns
- Type:
void- Description:
addParameter()
Adds parameter(s) to the internal list. Handles single values and arrays of values.
tsaddParameter(value: any): void;
Parameter Type Description valueanyReturns
- Type:
void- Description:
build()
Builds and returns the final SQL string.
tsbuild(): string;Returns
- Type:
string- Description:
table()
tstable(table: string): DropTableBuilder;
Parameter Type Description tablestringReturns
- Type:
DropTableBuilder- Description:
view()
tsview(view: string): DropViewBuilder;
Parameter Type Description viewstringReturns
- Type:
DropViewBuilder- Description:
sequence()
tssequence(sequence: string): DropSequenceBuilder;
Parameter Type Description sequencestringReturns
- Type:
DropSequenceBuilder- Description:
DropTableBuilder
prepareBuilder()
Hook for subclasses to set up the native builder object (e.g., calling .select()).
tsprepareBuilder(builder: any): any;
Parameter Type Description builderanyReturns
- Type:
any- Description:
parameters()
tsparameters(): void;Returns
- Type:
void- Description:
addParameter()
Adds parameter(s) to the internal list. Handles single values and arrays of values.
tsaddParameter(value: any): void;
Parameter Type Description valueanyReturns
- Type:
void- Description:
build()
Builds and returns the final SQL string.
tsbuild(): string;Returns
- Type:
string- Description:
DropViewBuilder
prepareBuilder()
Hook for subclasses to set up the native builder object (e.g., calling .select()).
tsprepareBuilder(builder: any): any;
Parameter Type Description builderanyReturns
- Type:
any- Description:
parameters()
tsparameters(): void;Returns
- Type:
void- Description:
addParameter()
Adds parameter(s) to the internal list. Handles single values and arrays of values.
tsaddParameter(value: any): void;
Parameter Type Description valueanyReturns
- Type:
void- Description:
build()
Builds and returns the final SQL string.
tsbuild(): string;Returns
- Type:
string- Description:
DropSequenceBuilder
prepareBuilder()
Hook for subclasses to set up the native builder object (e.g., calling .select()).
tsprepareBuilder(builder: any): any;
Parameter Type Description builderanyReturns
- Type:
any- Description:
parameters()
tsparameters(): void;Returns
- Type:
void- Description:
addParameter()
Adds parameter(s) to the internal list. Handles single values and arrays of values.
tsaddParameter(value: any): void;
Parameter Type Description valueanyReturns
- Type:
void- Description:
build()
Builds and returns the final SQL string.
tsbuild(): string;Returns
- Type:
string- Description:
