Skip to content

Commit

Permalink
added async methods for query
Browse files Browse the repository at this point in the history
  • Loading branch information
Bero committed Oct 8, 2024
1 parent 56c2153 commit 1f8412e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/query/query.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export default class Query extends Base {
return await callWithPromise(this.name, prepareForProcess(this.body, this.params));
}

async fetchAsync() {
return this.fetchSync();
}

/**
* Fetches one element in sync
* @return {*}
Expand All @@ -87,6 +91,10 @@ export default class Query extends Base {
return _.first(await this.fetchSync())
}

async fetchOneAsync() {
return this.fetchOneSync();
}

/**
* Retrieves the data.
* @param callbackOrOptions
Expand Down Expand Up @@ -133,6 +141,10 @@ export default class Query extends Base {
return await callWithPromise(this.name + '.count', prepareForProcess(this.body, this.params));
}

async getCountAsync() {
return this.getCountSync();
}

/**
* Gets the count of matching elements.
* @param callback
Expand Down
20 changes: 20 additions & 0 deletions lib/query/query.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ export default class Query extends Base {
return hypernova(node, context.userId, {params: this.params});
}

/**
* @param context
* @returns {*}
*/
async fetchAsync(context = {}) {
return await this.fetch(context);
}

/**
* @param context
* @returns {*}
Expand All @@ -28,11 +36,23 @@ export default class Query extends Base {
return _.first(this.fetch(context));
}

/**
* @param context
* @returns {*}
*/
async fetchOneAsync(context = {}) {
return await this.fetchOne(context);
}

/**
* Gets the count of matching elements.
* @returns {integer}
*/
getCount() {
return this.collection.find(this.body.$filters || {}, {}).count();
}

async getCountAsync() {
return this.getCount();
}
}

0 comments on commit 1f8412e

Please sign in to comment.