mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-05-11 23:48:56 +08:00
[database] Correctly differentiate limitToLast and other similar clauses
This commit is contained in:
@@ -26,6 +26,7 @@ export default class Query {
|
||||
*/
|
||||
orderBy(name: string, key?: string) {
|
||||
this.modifiers.push({
|
||||
id: `orderBy-${name}:${key}`,
|
||||
type: 'orderBy',
|
||||
name,
|
||||
key,
|
||||
@@ -42,6 +43,7 @@ export default class Query {
|
||||
*/
|
||||
limit(name: string, limit: number) {
|
||||
this.modifiers.push({
|
||||
id: `limit-${name}:${limit}`,
|
||||
type: 'limit',
|
||||
name,
|
||||
limit,
|
||||
@@ -59,6 +61,7 @@ export default class Query {
|
||||
*/
|
||||
filter(name: string, value: any, key?: string) {
|
||||
this.modifiers.push({
|
||||
id: `filter-${name}:${objectToUniqueId(value)}:${key}`,
|
||||
type: 'filter',
|
||||
name,
|
||||
value,
|
||||
@@ -82,14 +85,21 @@ export default class Query {
|
||||
* @return {*}
|
||||
*/
|
||||
queryIdentifier() {
|
||||
// convert query modifiers array into an object for generating a unique key
|
||||
const object = {};
|
||||
// sort modifiers to enforce ordering
|
||||
const sortedModifiers = this.getModifiers().sort((a, b) => {
|
||||
if (a.id < b.id) return -1;
|
||||
if (a.id > b.id) return 1;
|
||||
return 0;
|
||||
});
|
||||
|
||||
for (let i = 0, len = this.modifiers.length; i < len; i++) {
|
||||
const { name, type, value } = this.modifiers[i];
|
||||
object[`${type}-${name}`] = value;
|
||||
// Convert modifiers to unique key
|
||||
let key = '{';
|
||||
for (let i = 0; i < sortedModifiers.length; i++) {
|
||||
if (i !== 0) key += ',';
|
||||
key += sortedModifiers[i].id;
|
||||
}
|
||||
key += '}';
|
||||
|
||||
return objectToUniqueId(object);
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user