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.

41 lines
1.4 KiB

import {Builder} from '../../builder/Builder.ts'
import {Select} from '../../builder/type/Select.ts'
import {Relation} from './Relation.ts'
import {Update} from '../../builder/type/Update.ts'
import {FieldSet, QuerySource} from '../../builder/types.ts'
import {Delete} from '../../builder/type/Delete.ts'
import {Model} from '../Model.ts'
export class RelationBuilder<T extends Model<T>> extends Builder<T> {
constructor(
protected relation: Relation<any, T>
) {
super()
}
public select(...fields: FieldSet[]): Select<T> {
const select = this.relation.related.select(...fields)
.from(this.relation.related_query_source)
select.target_operator(this.relation.get_operator())
this.relation.scope_query(select)
return select
}
public update(target?: QuerySource, alias?: string): Update<T> {
const update = this.relation.related.update(this.relation.related_query_source)
update.target_operator(this.relation.get_operator())
this.relation.scope_query(update)
return update
}
public delete(target?: QuerySource, alias?: string): Delete<T> {
const delete_query = this.relation.related.delete(this.relation.related_query_source)
delete_query.target_operator(this.relation.get_operator())
this.relation.scope_query(delete_query)
return delete_query
}
}