Implement scopes on models and support interacting with them via ModelBuilder
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-11-11 16:42:37 -06:00
parent d92c8b5409
commit 0a9dd30909
9 changed files with 229 additions and 13 deletions

View File

@@ -0,0 +1,11 @@
import {Scope} from './Scope'
import {AbstractBuilder} from '../../builder/AbstractBuilder'
/**
* A basic scope to limit results where `active` = true.
*/
export class ActiveScope extends Scope {
apply(query: AbstractBuilder<any>): void {
query.where('active', '=', true)
}
}

View File

@@ -0,0 +1,18 @@
import {Injectable, InjectionAware} from '../../../di'
import {Awaitable} from '../../../util'
import {AbstractBuilder} from '../../builder/AbstractBuilder'
/**
* A closure that takes a query and applies some scope to it.
*/
export type ScopeClosure = (query: AbstractBuilder<any>) => Awaitable<void>
/**
* Base class for scopes that can be applied to queries.
*/
@Injectable()
export abstract class Scope extends InjectionAware {
abstract apply(query: AbstractBuilder<any>): Awaitable<void>
}