/** * SqlB - Simple query builder * Copyright 2020 jhaemin */ declare type Order = 'ASC' | 'asc' | 'DESC' | 'desc'; declare type SqlBValue = number | string | undefined; export declare class SqlBInstance { private q; /** * Add a space at the end */ private space; /** * Append query with a space before */ private append; /** * Concatenate string without a space */ private concat; private wrap; private singleQuotify; /** * Convert `undefined` to '?' and escape others */ private convert; build(terminate?: boolean): string; /** * Format the output. Use this before `build()`. */ format(): SqlBInstance; raw(str: string): SqlBInstance; /** * `(...) alias` * * Wrap the whole query currently built with braces. */ bind(alias?: string): SqlBInstance; /** * `SELECT` * * Select columns from table. If you specify a generic schema type, * it only allows the keys of the given type. * Use `alsoSelectAny` for more flexible selection. * @param what Array of strings or SqlB instances. Empty will select all. */ select(...what: Array): SqlBInstance; /** * Don't use this method alone. * Run `select()` or `selectAny()` first. */ alsoSelect(...what: Array): SqlBInstance; selectAny(...what: string[]): SqlBInstance; /** * Don't know why this method is created. * Can't find any use cases. * * Don't use this method alone. * Run `select()` or `selectAny()` first. */ alsoSelectAny(...what: string[]): SqlBInstance; distinctSelect(...what: (keyof T | '*' | SqlBInstance)[]): SqlBInstance; /** * Wrap whole query in SqlBInstance and append alias. * * `(query_until_now) AS alias` */ as(alias: string): SqlBInstance; /** * `FROM target` * * Pass nothing only appends `FROM` statement */ from(): SqlBInstance; from(target: string): SqlBInstance; from(target: string): SqlBInstance; from(target: SqlBInstance): SqlBInstance; /** * `WHERE conditions` * * Pass nothing only appends `WHERE` statement */ where(): SqlBInstance; where(conditions: string): SqlBInstance; where(conditions: SqlBInstance): SqlBInstance; /** * `schema1 JOIN schema2` */ join(schema1: string, schema2: string, outer?: 'left' | 'right'): SqlBInstance; /** * `ON condition` */ on(condition?: string): SqlBInstance; in(attr: keyof T, values: SqlBValue[]): SqlBInstance; isNull(attr: keyof T): SqlBInstance; andIsNull(attr: keyof T): SqlBInstance; orIsNull(attr: keyof T): SqlBInstance; isNotNull(attr: keyof T): SqlBInstance; andIsNotNull(attr: keyof T): SqlBInstance; orIsNotNull(attr: keyof T): SqlBInstance; /** * > NOTE: To check `NULL`, use `isNull()` */ equal(attr: string, value: SqlBValue): SqlBInstance; andEqual(attr: string, value: SqlBValue): SqlBInstance; /** * > NOTE: To check `NULL`, use `isNotNull()` */ notEqual(attr: string, value: SqlBValue): SqlBInstance; andNotEqual(attr: string, value: SqlBValue): SqlBInstance; /** attr >= value */ equalOrMore(attr: string, value: SqlBValue): SqlBInstance; /** AND attr >= value */ andEqualOrMore(attr: string, value: SqlBValue): SqlBInstance; /** attr <= value */ equalOrLess(attr: string, value: SqlBValue): SqlBInstance; /** AND attr <= value */ andEqualOrLess(attr: string, value: SqlBValue): SqlBInstance; /** attr > value */ more(attr: string, value: SqlBValue): SqlBInstance; /** AND attr > value */ andMore(attr: string, value: SqlBValue): SqlBInstance; /** attr < value */ less(attr: string, value: SqlBValue): SqlBInstance; /** AND attr < value */ andLess(attr: string, value: SqlBValue): SqlBInstance; group(by: keyof T): SqlBInstance; order(attr: keyof T, direction?: Order): SqlBInstance; multiOrder(options: [keyof T, Order][]): SqlBInstance; limit(amount: number, offset?: number): SqlBInstance; like(column: keyof T, keyword: string): SqlBInstance; private onDuplicateKeyUpdate; insert(schema: string, items: { [K in keyof T]?: T[K]; }, dupStrategy?: 'ignore' | 'update' | { strategy: 'update'; attributes: (keyof T)[]; }): SqlBInstance; bulkInsert(schema: string, items: { [K in keyof T]?: T[K]; }[], dupStrategy?: 'ignore' | 'update' | { strategy: 'update'; attributes: (keyof T)[]; }): SqlBInstance; /** * `UPDATE schema SET attribute = 'value', ...` */ update(schema: string, items: { [K in keyof T]?: T[K]; }): SqlBInstance; delete(): SqlBInstance; when(): SqlBInstance; notExists(sqlB: SqlBInstance): SqlBInstance; and(sql?: string | SqlBInstance): SqlBInstance; or(sql?: string | SqlBInstance): SqlBInstance; } declare function SqlB(): SqlBInstance; declare namespace SqlB { var escape: (value: any) => string; } export default SqlB; /** * SqlB function alias */ export declare const Q: typeof SqlB;