react-native-firebase/lib/modules/database/query.js

50 lines
972 B
JavaScript
Raw Normal View History

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 {
modifiers: Array<DatabaseModifier>;
2017-03-02 11:40:08 +00:00
constructor(ref: Reference, path: string, existingModifiers?: Array<DatabaseModifier>) {
2017-05-30 11:28:53 +00:00
super(path);
2017-03-02 11:40:08 +00:00
this.log.debug('creating Query ', path, existingModifiers);
this.modifiers = existingModifiers ? [...existingModifiers] : [];
}
orderBy(name: string, key?: string) {
this.modifiers.push({
type: 'orderBy',
name,
key,
});
2017-03-02 11:40:08 +00:00
}
limit(name: string, limit: number) {
this.modifiers.push({
type: 'limit',
name,
limit,
});
2017-03-02 11:40:08 +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
}
getModifiers(): Array<DatabaseModifier> {
2017-03-02 11:40:08 +00:00
return [...this.modifiers];
}
}