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.

26 lines
890 B

import {JoinOperator, TableRef, WhereStatement} from '../../types.ts'
import {TableRefBuilder} from '../TableRefBuilder.ts'
import {applyMixins} from '../../../../../lib/src/support/mixins.ts'
import {WhereBuilder} from '../WhereBuilder.ts'
export class Join {
public readonly operator: JoinOperator = 'JOIN'
protected _wheres: WhereStatement[] = []
constructor(
public readonly table_ref: TableRef
) {}
sql(level = 0): string {
const indent = Array(level * 2).fill(' ').join('')
return [
`${this.operator} ${this.serialize_table_ref(this.table_ref)}`,
...[this._wheres.length > 0 ? ['ON'] : []],
this.wheres_to_sql(this._wheres, level),
].filter(Boolean).join(`\n${indent}`)
}
}
export interface Join extends TableRefBuilder, WhereBuilder {}
applyMixins(Join, [TableRefBuilder, WhereBuilder])