You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.5 KiB
51 lines
1.5 KiB
import {escape, EscapedValue, FieldSet, QuerySource} from './types.ts'
|
|
import { Select } from './type/Select.ts'
|
|
import RawValue from './RawValue.ts'
|
|
import {Statement} from './Statement.ts'
|
|
import {Update} from "./type/Update.ts";
|
|
import {Insert} from "./type/Insert.ts";
|
|
|
|
export function raw(value: string) {
|
|
return new RawValue(value)
|
|
}
|
|
|
|
export class IncorrectInterpolationError extends Error {
|
|
constructor(expected: number, received: number) {
|
|
super(`Unable to interpolate arguments into query. Expected ${expected} argument${expected === 1 ? '' : 's'}, but received ${received}.`)
|
|
}
|
|
}
|
|
|
|
export class Builder {
|
|
// create table, insert, delete, alter table, drop table, select
|
|
|
|
public select(...fields: FieldSet[]) {
|
|
fields = fields.flat()
|
|
const select = new Select()
|
|
return select.fields(...fields)
|
|
}
|
|
|
|
public update(target?: QuerySource, alias?: string) {
|
|
const update = new Update()
|
|
if ( target ) update.to(target, alias)
|
|
return update
|
|
}
|
|
|
|
public insert(target?: QuerySource, alias?: string) {
|
|
const insert = new Insert()
|
|
if ( target ) insert.into(target, alias)
|
|
return insert
|
|
}
|
|
|
|
public statement(statement: string, ...interpolations: EscapedValue[]) {
|
|
return new Statement(statement, interpolations)
|
|
}
|
|
|
|
public static raw(value: string) {
|
|
return new RawValue(value)
|
|
}
|
|
|
|
public static default() {
|
|
return this.raw('DEFAULT')
|
|
}
|
|
}
|