2017-03-02 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { ReferenceBase } from './../base';
|
|
|
|
import Reference from './reference.js';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class Query
|
|
|
|
*/
|
|
|
|
export default class Query extends ReferenceBase {
|
2017-04-26 11:21:53 +00:00
|
|
|
modifiers: Array<DatabaseModifier>;
|
2017-03-02 11:40:08 +00:00
|
|
|
|
2017-04-26 11:21:53 +00:00
|
|
|
constructor(ref: Reference, path: string, existingModifiers?: Array<DatabaseModifier>) {
|
2017-03-24 22:53:56 +00:00
|
|
|
super(ref.database, path);
|
2017-03-02 11:40:08 +00:00
|
|
|
this.log.debug('creating Query ', path, existingModifiers);
|
|
|
|
this.modifiers = existingModifiers ? [...existingModifiers] : [];
|
|
|
|
}
|
|
|
|
|
2017-04-26 11:21:53 +00:00
|
|
|
orderBy(name: string, key?: string) {
|
|
|
|
this.modifiers.push({
|
|
|
|
type: 'orderBy',
|
|
|
|
name,
|
|
|
|
key,
|
|
|
|
});
|
2017-03-02 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
2017-04-26 11:21:53 +00:00
|
|
|
limit(name: string, limit: number) {
|
|
|
|
this.modifiers.push({
|
|
|
|
type: 'limit',
|
|
|
|
name,
|
|
|
|
limit,
|
|
|
|
});
|
2017-03-02 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
2017-04-26 11:21:53 +00:00
|
|
|
filter(name: string, value: any, key?:string) {
|
|
|
|
this.modifiers.push({
|
|
|
|
type: 'filter',
|
|
|
|
name,
|
|
|
|
value,
|
|
|
|
valueType: typeof value,
|
|
|
|
key,
|
|
|
|
});
|
2017-03-02 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
2017-04-26 11:21:53 +00:00
|
|
|
getModifiers(): Array<DatabaseModifier> {
|
2017-03-02 11:40:08 +00:00
|
|
|
return [...this.modifiers];
|
|
|
|
}
|
|
|
|
}
|