Implement scopes on models and support interacting with them via ModelBuilder
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
11
src/orm/model/scope/ActiveScope.ts
Normal file
11
src/orm/model/scope/ActiveScope.ts
Normal 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)
|
||||
}
|
||||
}
|
||||
18
src/orm/model/scope/Scope.ts
Normal file
18
src/orm/model/scope/Scope.ts
Normal 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>
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user