Skip to content

db/sql

Documentation

Overview

Classes

SQLBuilder

prepareBuilder()

Hook for subclasses to set up the native builder object (e.g., calling .select()).

ts
prepareBuilder(builder: any): any;
ParameterTypeDescription
builderany

Returns

  • Type: any
  • Description:

parameters()

ts
parameters(): void;

Returns

  • Type: void
  • Description:

addParameter()

Adds parameter(s) to the internal list. Handles single values and arrays of values.

ts
addParameter(value: any): void;
ParameterTypeDescription
valueany

Returns

  • Type: void
  • Description:

build()

Builds and returns the final SQL string.

ts
build(): string;

Returns

  • Type: string
  • Description:

getDialect()

Factory method to get a dialect-specific SQLBuilder instance.

ts
static getDialect(connection: Connection): SQLBuilder;
ParameterTypeDescription
connectionConnection

Returns

  • Type: SQLBuilder
  • Description:

select()

ts
select(): SelectBuilder;

Returns

  • Type: SelectBuilder
  • Description:

insert()

ts
insert(): InsertBuilder;

Returns

  • Type: InsertBuilder
  • Description:

update()

ts
update(): UpdateBuilder;

Returns

  • Type: UpdateBuilder
  • Description:

delete()

ts
delete(): DeleteBuilder;

Returns

  • Type: DeleteBuilder
  • Description:

nextval()

ts
nextval(name: string): NextvalBuilder;
ParameterTypeDescription
namestring

Returns

  • Type: NextvalBuilder
  • Description:

create()

ts
create(): CreateBuilder;

Returns

  • Type: CreateBuilder
  • Description:

drop()

ts
drop(): DropBuilder;

Returns

  • Type: DropBuilder
  • Description:

SelectBuilder

parameters()

ts
parameters(): void;

Returns

  • Type: void
  • Description:

addParameter()

Adds parameter(s) to the internal list. Handles single values and arrays of values.

ts
addParameter(value: any): void;
ParameterTypeDescription
valueany

Returns

  • Type: void
  • Description:

build()

Builds and returns the final SQL string.

ts
build(): string;

Returns

  • Type: string
  • Description:

prepareBuilder()

Hook for subclasses to set up the native builder object (e.g., calling .select()).

ts
prepareBuilder(builder: any): any;
ParameterTypeDescription
builderany

Returns

  • Type: any
  • Description:

distinct()

ts
distinct(): SelectBuilder;

Returns

  • Type: SelectBuilder
  • Description:

forUpdate()

ts
forUpdate(): SelectBuilder;

Returns

  • Type: SelectBuilder
  • Description:

column()

ts
column(column: string): SelectBuilder;
ParameterTypeDescription
columnstring

Returns

  • Type: SelectBuilder
  • Description:

from()

ts
from(table: string, alias: string): SelectBuilder;
ParameterTypeDescription
tablestring
aliasstring

Returns

  • Type: SelectBuilder
  • Description:

join()

ts
join(table: string, on: string, alias: string, parameters: any): SelectBuilder;
ParameterTypeDescription
tablestring
onstring
aliasstring
parametersany

Returns

  • Type: SelectBuilder
  • Description:

innerJoin()

ts
innerJoin(table: string, on: string, alias: string, parameters: any): SelectBuilder;
ParameterTypeDescription
tablestring
onstring
aliasstring
parametersany

Returns

  • Type: SelectBuilder
  • Description:

outerJoin()

ts
outerJoin(table: string, on: string, alias: string, parameters: any): SelectBuilder;
ParameterTypeDescription
tablestring
onstring
aliasstring
parametersany

Returns

  • Type: SelectBuilder
  • Description:

leftJoin()

ts
leftJoin(table: string, on: string, alias: string, parameters: any): SelectBuilder;
ParameterTypeDescription
tablestring
onstring
aliasstring
parametersany

Returns

  • Type: SelectBuilder
  • Description:

rightJoin()

ts
rightJoin(table: string, on: string, alias: string, parameters: any): SelectBuilder;
ParameterTypeDescription
tablestring
onstring
aliasstring
parametersany

Returns

  • Type: SelectBuilder
  • Description:

fullJoin()

ts
fullJoin(table: string, on: string, alias: string, parameters: any): SelectBuilder;
ParameterTypeDescription
tablestring
onstring
aliasstring
parametersany

Returns

  • Type: SelectBuilder
  • Description:

where()

Sets the WHERE condition.

ts
where(condition: string, parameters: any): SelectBuilder;
ParameterTypeDescription
conditionstringThe SQL condition string (e.g., "column1 = ?").
parametersanyOptional parameters to replace '?' in the condition.

Returns

  • Type: SelectBuilder
  • Description:

order()

ts
order(column: string, asc: boolean): SelectBuilder;
ParameterTypeDescription
columnstring
ascboolean

Returns

  • Type: SelectBuilder
  • Description:

group()

ts
group(column: string): SelectBuilder;
ParameterTypeDescription
columnstring

Returns

  • Type: SelectBuilder
  • Description:

limit()

ts
limit(limit: number): SelectBuilder;
ParameterTypeDescription
limitnumber

Returns

  • Type: SelectBuilder
  • Description:

offset()

ts
offset(offset: number): SelectBuilder;
ParameterTypeDescription
offsetnumber

Returns

  • Type: SelectBuilder
  • Description:

having()

ts
having(having: string): SelectBuilder;
ParameterTypeDescription
havingstring

Returns

  • Type: SelectBuilder
  • Description:

union()

ts
union(select: string): SelectBuilder;
ParameterTypeDescription
selectstring

Returns

  • Type: SelectBuilder
  • Description:

InsertBuilder

parameters()

ts
parameters(): void;

Returns

  • Type: void
  • Description:

addParameter()

Adds parameter(s) to the internal list. Handles single values and arrays of values.

ts
addParameter(value: any): void;
ParameterTypeDescription
valueany

Returns

  • Type: void
  • Description:

build()

Builds and returns the final SQL string.

ts
build(): string;

Returns

  • Type: string
  • Description:

prepareBuilder()

Hook for subclasses to set up the native builder object (e.g., calling .select()).

ts
prepareBuilder(builder: any): any;
ParameterTypeDescription
builderany

Returns

  • Type: any
  • Description:

into()

ts
into(table: string): InsertBuilder;
ParameterTypeDescription
tablestring

Returns

  • Type: InsertBuilder
  • Description:

column()

ts
column(column: string): InsertBuilder;
ParameterTypeDescription
columnstring

Returns

  • Type: InsertBuilder
  • Description:

value()

Sets the value for the last column specified.

ts
value(value: string, parameters: any): InsertBuilder;
ParameterTypeDescription
valuestringThe value placeholder (e.g., "?") or literal.
parametersanyOptional parameters if a placeholder was used.

Returns

  • Type: InsertBuilder
  • Description:

select()

ts
select(select: string): InsertBuilder;
ParameterTypeDescription
selectstring

Returns

  • Type: InsertBuilder
  • Description:

UpdateBuilder

parameters()

ts
parameters(): void;

Returns

  • Type: void
  • Description:

addParameter()

Adds parameter(s) to the internal list. Handles single values and arrays of values.

ts
addParameter(value: any): void;
ParameterTypeDescription
valueany

Returns

  • Type: void
  • Description:

build()

Builds and returns the final SQL string.

ts
build(): string;

Returns

  • Type: string
  • Description:

prepareBuilder()

Hook for subclasses to set up the native builder object (e.g., calling .select()).

ts
prepareBuilder(builder: any): any;
ParameterTypeDescription
builderany

Returns

  • Type: any
  • Description:

table()

ts
table(table: string): UpdateBuilder;
ParameterTypeDescription
tablestring

Returns

  • Type: UpdateBuilder
  • Description:

set()

Sets a column to a value.

ts
set(column: string, value: string, parameters: any): UpdateBuilder;
ParameterTypeDescription
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.

ts
where(condition: string, parameters: any): UpdateBuilder;
ParameterTypeDescription
conditionstringThe SQL condition string (e.g., "column1 = ?").
parametersanyOptional parameters to replace '?' in the condition.

Returns

  • Type: UpdateBuilder
  • Description:

DeleteBuilder

parameters()

ts
parameters(): void;

Returns

  • Type: void
  • Description:

addParameter()

Adds parameter(s) to the internal list. Handles single values and arrays of values.

ts
addParameter(value: any): void;
ParameterTypeDescription
valueany

Returns

  • Type: void
  • Description:

build()

Builds and returns the final SQL string.

ts
build(): string;

Returns

  • Type: string
  • Description:

prepareBuilder()

Hook for subclasses to set up the native builder object (e.g., calling .select()).

ts
prepareBuilder(builder: any): any;
ParameterTypeDescription
builderany

Returns

  • Type: any
  • Description:

from()

ts
from(table: string): DeleteBuilder;
ParameterTypeDescription
tablestring

Returns

  • Type: DeleteBuilder
  • Description:

where()

Sets the WHERE condition for the deletion.

ts
where(condition: string, parameters: any): DeleteBuilder;
ParameterTypeDescription
conditionstringThe SQL condition string (e.g., "column1 = ?").
parametersanyOptional parameters to replace '?' in the condition.

Returns

  • Type: DeleteBuilder
  • Description:

NextvalBuilder

parameters()

ts
parameters(): void;

Returns

  • Type: void
  • Description:

addParameter()

Adds parameter(s) to the internal list. Handles single values and arrays of values.

ts
addParameter(value: any): void;
ParameterTypeDescription
valueany

Returns

  • Type: void
  • Description:

build()

Builds and returns the final SQL string.

ts
build(): string;

Returns

  • Type: string
  • Description:

prepareBuilder()

Hook for subclasses to set up the native builder object (e.g., calling .select()).

ts
prepareBuilder(builder: any): any;
ParameterTypeDescription
builderany

Returns

  • Type: any
  • Description:

CreateBuilder

prepareBuilder()

Hook for subclasses to set up the native builder object (e.g., calling .select()).

ts
prepareBuilder(builder: any): any;
ParameterTypeDescription
builderany

Returns

  • Type: any
  • Description:

parameters()

ts
parameters(): void;

Returns

  • Type: void
  • Description:

addParameter()

Adds parameter(s) to the internal list. Handles single values and arrays of values.

ts
addParameter(value: any): void;
ParameterTypeDescription
valueany

Returns

  • Type: void
  • Description:

build()

Builds and returns the final SQL string.

ts
build(): string;

Returns

  • Type: string
  • Description:

table()

ts
table(table: string): CreateTableBuilder;
ParameterTypeDescription
tablestring

Returns

  • Type: CreateTableBuilder
  • Description:

view()

ts
view(view: string): CreateViewBuilder;
ParameterTypeDescription
viewstring

Returns

  • Type: CreateViewBuilder
  • Description:

sequence()

ts
sequence(sequence: string): CreateSequenceBuilder;
ParameterTypeDescription
sequencestring

Returns

  • Type: CreateSequenceBuilder
  • Description:

CreateTableBuilder

prepareBuilder()

Hook for subclasses to set up the native builder object (e.g., calling .select()).

ts
prepareBuilder(builder: any): any;
ParameterTypeDescription
builderany

Returns

  • Type: any
  • Description:

parameters()

ts
parameters(): void;

Returns

  • Type: void
  • Description:

addParameter()

Adds parameter(s) to the internal list. Handles single values and arrays of values.

ts
addParameter(value: any): void;
ParameterTypeDescription
valueany

Returns

  • Type: void
  • Description:

build()

Builds and returns the final SQL string.

ts
build(): string;

Returns

  • Type: string
  • Description:

column()

Adds a generic column definition.

ts
column(name: string, type: DataType, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, isIdentity: boolean, isFuzzyIndexEnabled: boolean, args: any): CreateTableBuilder;
ParameterTypeDescription
namestring
typeDataType
isPrimaryKeyboolean
isNullableboolean
isUniqueboolean
isIdentityboolean
isFuzzyIndexEnabledboolean
argsanyAdditional dialect-specific arguments passed as an array to native.

Returns

  • Type: CreateTableBuilder
  • Description:

columnVarchar()

Adds a VARCHAR column.

ts
columnVarchar(name: string, length: number, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, isIdentity: boolean, args: any): CreateTableBuilder;
ParameterTypeDescription
namestring
lengthnumber
isPrimaryKeyboolean
isNullableboolean
isUniqueboolean
isIdentityboolean
argsanyAdditional dialect-specific arguments passed as an array to native.

Returns

  • Type: CreateTableBuilder
  • Description:

columnNvarchar()

Adds an NVARCHAR column.

ts
columnNvarchar(name: string, length: number, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, isIdentity: boolean, args: any): CreateTableBuilder;
ParameterTypeDescription
namestring
lengthnumber
isPrimaryKeyboolean
isNullableboolean
isUniqueboolean
isIdentityboolean
argsanyAdditional dialect-specific arguments passed as an array to native.

Returns

  • Type: CreateTableBuilder
  • Description:

columnChar()

Adds a CHAR column.

ts
columnChar(name: string, length: number, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, isIdentity: boolean, args: any): CreateTableBuilder;
ParameterTypeDescription
namestring
lengthnumber
isPrimaryKeyboolean
isNullableboolean
isUniqueboolean
isIdentityboolean
argsanyAdditional dialect-specific arguments passed as an array to native.

Returns

  • Type: CreateTableBuilder
  • Description:

columnDate()

Adds a DATE column.

ts
columnDate(name: string, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, args: any): CreateTableBuilder;
ParameterTypeDescription
namestring
isPrimaryKeyboolean
isNullableboolean
isUniqueboolean
argsanyAdditional dialect-specific arguments passed as an array to native.

Returns

  • Type: CreateTableBuilder
  • Description:

columnTime()

Adds a TIME column.

ts
columnTime(name: string, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, args: any): CreateTableBuilder;
ParameterTypeDescription
namestring
isPrimaryKeyboolean
isNullableboolean
isUniqueboolean
argsanyAdditional dialect-specific arguments passed as an array to native.

Returns

  • Type: CreateTableBuilder
  • Description:

columnTimestamp()

Adds a TIMESTAMP column.

ts
columnTimestamp(name: string, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, args: any): CreateTableBuilder;
ParameterTypeDescription
namestring
isPrimaryKeyboolean
isNullableboolean
isUniqueboolean
argsanyAdditional dialect-specific arguments passed as an array to native.

Returns

  • Type: CreateTableBuilder
  • Description:

columnInteger()

Adds an INTEGER column.

ts
columnInteger(name: string, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, isIdentity: boolean, args: any): CreateTableBuilder;
ParameterTypeDescription
namestring
isPrimaryKeyboolean
isNullableboolean
isUniqueboolean
isIdentityboolean
argsanyAdditional dialect-specific arguments passed as an array to native.

Returns

  • Type: CreateTableBuilder
  • Description:

columnTinyint()

Adds a TINYINT column.

ts
columnTinyint(name: string, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, args: any): CreateTableBuilder;
ParameterTypeDescription
namestring
isPrimaryKeyboolean
isNullableboolean
isUniqueboolean
argsanyAdditional dialect-specific arguments passed as an array to native.

Returns

  • Type: CreateTableBuilder
  • Description:

columnBigint()

Adds a BIGINT column.

ts
columnBigint(name: string, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, isIdentity: boolean, args: any): CreateTableBuilder;
ParameterTypeDescription
namestring
isPrimaryKeyboolean
isNullableboolean
isUniqueboolean
isIdentityboolean
argsanyAdditional dialect-specific arguments passed as an array to native.

Returns

  • Type: CreateTableBuilder
  • Description:

columnSmallint()

Adds a SMALLINT column.

ts
columnSmallint(name: string, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, args: any): CreateTableBuilder;
ParameterTypeDescription
namestring
isPrimaryKeyboolean
isNullableboolean
isUniqueboolean
argsanyAdditional dialect-specific arguments passed as an array to native.

Returns

  • Type: CreateTableBuilder
  • Description:

columnReal()

Adds a REAL column.

ts
columnReal(name: string, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, args: any): CreateTableBuilder;
ParameterTypeDescription
namestring
isPrimaryKeyboolean
isNullableboolean
isUniqueboolean
argsanyAdditional dialect-specific arguments passed as an array to native.

Returns

  • Type: CreateTableBuilder
  • Description:

columnDouble()

Adds a DOUBLE column.

ts
columnDouble(name: string, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, args: any): CreateTableBuilder;
ParameterTypeDescription
namestring
isPrimaryKeyboolean
isNullableboolean
isUniqueboolean
argsanyAdditional dialect-specific arguments passed as an array to native.

Returns

  • Type: CreateTableBuilder
  • Description:

columnBoolean()

Adds a BOOLEAN column.

ts
columnBoolean(name: string, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, args: any): CreateTableBuilder;
ParameterTypeDescription
namestring
isPrimaryKeyboolean
isNullableboolean
isUniqueboolean
argsanyAdditional dialect-specific arguments passed as an array to native.

Returns

  • Type: CreateTableBuilder
  • Description:

columnBlob()

Adds a BLOB column.

ts
columnBlob(name: string, isNullable: boolean, args: any): CreateTableBuilder;
ParameterTypeDescription
namestring
isNullableboolean
argsanyAdditional dialect-specific arguments passed as an array to native.

Returns

  • Type: CreateTableBuilder
  • Description:

columnDecimal()

Adds a DECIMAL column with precision and scale.

ts
columnDecimal(name: string, precision: number, scale: number, isPrimaryKey: boolean, isNullable: boolean, isUnique: boolean, isIdentity: boolean, args: any): CreateTableBuilder;
ParameterTypeDescription
namestring
precisionnumber
scalenumber
isPrimaryKeyboolean
isNullableboolean
isUniqueboolean
isIdentityboolean
argsanyAdditional dialect-specific arguments passed as an array to native.

Returns

  • Type: CreateTableBuilder
  • Description:

primaryKey()

ts
primaryKey(columns: any, name: string): CreateTableBuilder;
ParameterTypeDescription
columnsany
namestring

Returns

  • Type: CreateTableBuilder
  • Description:

foreignKey()

ts
foreignKey(name: string, columns: any, referencedTable: string, referencedColumns: any, referencedTableSchema: string): CreateTableBuilder;
ParameterTypeDescription
namestring
columnsany
referencedTablestring
referencedColumnsany
referencedTableSchemastring

Returns

  • Type: CreateTableBuilder
  • Description:

unique()

ts
unique(name: string, columns: any): CreateTableBuilder;
ParameterTypeDescription
namestring
columnsany

Returns

  • Type: CreateTableBuilder
  • Description:

check()

ts
check(name: string, expression: string): CreateTableBuilder;
ParameterTypeDescription
namestring
expressionstring

Returns

  • Type: CreateTableBuilder
  • Description:

CreateViewBuilder

prepareBuilder()

Hook for subclasses to set up the native builder object (e.g., calling .select()).

ts
prepareBuilder(builder: any): any;
ParameterTypeDescription
builderany

Returns

  • Type: any
  • Description:

parameters()

ts
parameters(): void;

Returns

  • Type: void
  • Description:

addParameter()

Adds parameter(s) to the internal list. Handles single values and arrays of values.

ts
addParameter(value: any): void;
ParameterTypeDescription
valueany

Returns

  • Type: void
  • Description:

build()

Builds and returns the final SQL string.

ts
build(): string;

Returns

  • Type: string
  • Description:

column()

ts
column(column: string): CreateViewBuilder;
ParameterTypeDescription
columnstring

Returns

  • Type: CreateViewBuilder
  • Description:

asSelect()

ts
asSelect(select: string): CreateViewBuilder;
ParameterTypeDescription
selectstring

Returns

  • Type: CreateViewBuilder
  • Description:

CreateSequenceBuilder

prepareBuilder()

Hook for subclasses to set up the native builder object (e.g., calling .select()).

ts
prepareBuilder(builder: any): any;
ParameterTypeDescription
builderany

Returns

  • Type: any
  • Description:

parameters()

ts
parameters(): void;

Returns

  • Type: void
  • Description:

addParameter()

Adds parameter(s) to the internal list. Handles single values and arrays of values.

ts
addParameter(value: any): void;
ParameterTypeDescription
valueany

Returns

  • Type: void
  • Description:

build()

Builds and returns the final SQL string.

ts
build(): string;

Returns

  • Type: string
  • Description:

DropBuilder

prepareBuilder()

Hook for subclasses to set up the native builder object (e.g., calling .select()).

ts
prepareBuilder(builder: any): any;
ParameterTypeDescription
builderany

Returns

  • Type: any
  • Description:

parameters()

ts
parameters(): void;

Returns

  • Type: void
  • Description:

addParameter()

Adds parameter(s) to the internal list. Handles single values and arrays of values.

ts
addParameter(value: any): void;
ParameterTypeDescription
valueany

Returns

  • Type: void
  • Description:

build()

Builds and returns the final SQL string.

ts
build(): string;

Returns

  • Type: string
  • Description:

table()

ts
table(table: string): DropTableBuilder;
ParameterTypeDescription
tablestring

Returns

  • Type: DropTableBuilder
  • Description:

view()

ts
view(view: string): DropViewBuilder;
ParameterTypeDescription
viewstring

Returns

  • Type: DropViewBuilder
  • Description:

sequence()

ts
sequence(sequence: string): DropSequenceBuilder;
ParameterTypeDescription
sequencestring

Returns

  • Type: DropSequenceBuilder
  • Description:

DropTableBuilder

prepareBuilder()

Hook for subclasses to set up the native builder object (e.g., calling .select()).

ts
prepareBuilder(builder: any): any;
ParameterTypeDescription
builderany

Returns

  • Type: any
  • Description:

parameters()

ts
parameters(): void;

Returns

  • Type: void
  • Description:

addParameter()

Adds parameter(s) to the internal list. Handles single values and arrays of values.

ts
addParameter(value: any): void;
ParameterTypeDescription
valueany

Returns

  • Type: void
  • Description:

build()

Builds and returns the final SQL string.

ts
build(): string;

Returns

  • Type: string
  • Description:

DropViewBuilder

prepareBuilder()

Hook for subclasses to set up the native builder object (e.g., calling .select()).

ts
prepareBuilder(builder: any): any;
ParameterTypeDescription
builderany

Returns

  • Type: any
  • Description:

parameters()

ts
parameters(): void;

Returns

  • Type: void
  • Description:

addParameter()

Adds parameter(s) to the internal list. Handles single values and arrays of values.

ts
addParameter(value: any): void;
ParameterTypeDescription
valueany

Returns

  • Type: void
  • Description:

build()

Builds and returns the final SQL string.

ts
build(): string;

Returns

  • Type: string
  • Description:

DropSequenceBuilder

prepareBuilder()

Hook for subclasses to set up the native builder object (e.g., calling .select()).

ts
prepareBuilder(builder: any): any;
ParameterTypeDescription
builderany

Returns

  • Type: any
  • Description:

parameters()

ts
parameters(): void;

Returns

  • Type: void
  • Description:

addParameter()

Adds parameter(s) to the internal list. Handles single values and arrays of values.

ts
addParameter(value: any): void;
ParameterTypeDescription
valueany

Returns

  • Type: void
  • Description:

build()

Builds and returns the final SQL string.

ts
build(): string;

Returns

  • Type: string
  • Description: