A Parse Platform REST API utility and query builder for the Parse Platform SDK for Node. Simplify and enhance your queries with ease using this powerful query builder, leveraging the Parse Platform REST API.
npm install parse-query-node
const ParseQuery = require('parse-query-node');
// Example initialization
const query = new ParseQuery(
'<Your-Application-Id>',
'<Your-Master-Key>',
'<Your-REST-API-Key>',
'<Your-Parse-Server-URL>',
'<Your-Parse-Server-Version>'
);
// Example usage
query.table('YourTableName')
.where('fieldName', '>', 10)
.with('relatedField')
.getAll()
.then(results => {
console.log(results);
})
.catch(error => {
console.error(error);
});
The ParseQuery provides a convenient way to construct queries for Parse Server.
Initializes a new ParseQuery object with the specified Parse Server configuration parameters.
const ParseQuery = require('parse-query-node');
// Initialize ParseQuery with required parameters
const query = new ParseQuery(
'<Your-Application-Id>',
'<Your-Master-Key>',
'<Your-REST-API-Key>',
'<Your-Parse-Server-URL>',
'<Your-Parse-Server-Version>'
);
- applicationId: Your Parse application ID.
- masterKey: Your Parse master key (optional).
- restApiKey: Your Parse REST API key.
- parseServerUrl: URL of your Parse Server.
- parseServerVersion:Version of your Parse Server.
Specifies the Table Name to query.
query.table('<YourTableName>');
Adds basic equality and comparison conditions to the query.
query.where('fieldName', '=', 'value')
.where('otherField', 10)
.where({name:"test"})
.where([['field1', '>', 10], ['field2', '=', 'value']]);
Includes related fields in the query result.
query.with('relatedField1', 'relatedField2');
Adds a condition to join with a Pointer field.
query.whereJoinKey('foreignkeyname', 'foreignkeyValue', 'ForeignTableName');
Adds a condition to check if a field matches any value in a subquery.
query.whereJoinInQuery('foreignkeyname', [
['score', '>', 90],
['level', '=', 'advanced'],
], 'ForeignTableName');
Adds a condition to check if a field does not match any value in a subquery.
query.whereJoinNotInQuery('foreignkeyname', [
['score', '>', 90],
['level', '=', 'advanced'],
], 'ForeignTableName');
Adds a condition to retrieve objects related to a specific parent object.
Imagine you have a Post class and User class, where each Post can be liked by many users. If the Users that liked a Post were stored in a Relation on the post under the key “likes”, you can find the users that liked a particular post by:
//query.whereRelatedTo('Post', '1', 'likes');
query.whereRelatedTo('ForeignTableName', 'ForeignTableObjectId', 'foreignkeyname');
Adds a condition to check if a field matches any value in a given array.
query.whereIn('field', [1,3,5,7,9]);
Adds a condition to check if a field does not match any value in a given array.
query.whereNotIn('field', [1,3,5,7,9]);
Adds a condition to check if a field exists.
query.whereExists('field');
Adds a condition to check if a field does not exist.
query.whereNotExists('field');
Adds a condition to check if a field contains all specified values.
query.whereContainsAll('field', [2,3,4]);
Adds a condition to check if a field contains a specific value.
query.whereContains('field', 2);
Adds a condition for full-text search on a field.
query.whereFullText('fieldName', 'searchTerm');
Inserts data into the specified Table.
query.insert({name: 'Alice', age: 30 });
query.insert([
{ name: 'Alice', age: 30, city: 'San Francisco' },
{ name: 'Bob', age: 28, city: 'Los Angeles' },
]);
Updates data in the specified Table for a specific object.
query.update('objectId', { key: 'updatedValue' });
Deletes data from the specified Table for a specific object.
query.delete('objectId');
Deletes a specific field from an object in the specified Table.
query.deleteField('objectId', 'fieldName');
Adds values to an array field in an object.
query.addToArray('objectId', 'fieldName', ['value1', 'value2']);
Adds unique values to an array field in an object.
query.addUniqueToArray('objectId', 'fieldName', ['value1', 'value2']);
Removes values from an array field in an object.
query.removeFromArray('objectId', 'fieldName', ['value1', 'value2']);
Retrieves distinct values for specified fields.
query.distinct('field1', 'field2');
Performs aggregation using a specified pipeline.
const exmaplePipeline = [
{
$match: {
field1: { $exists: true },
field2: { $gte: 0 },
},
},
{
$group: {
_id: '$groupField',
count: { $sum: 1 },
},
},
];
query.aggregate(exmaplePipeline);
Counts the number of records that match the query.
query.count();
Retrieves the first record that matches the query.
query.first();
Retrieves all records that match the query.
query.getAll();
Retrieves a specific record by its object ID.
query.find('objectId');
Orders the query result by a specified field in ascending order.
query.orderBy('fieldName', 'asc');
query.orderBy('fieldName', 'desc');
Orders the query result by specified fields in descending order.
query.orderByDesc('field1', 'field2');
Orders the query result by specified fields in ascending order.
query.orderByAsc('field1', 'field2');
Limits the number of results returned by the query.
query.limit(10);
Skips a specified number of results in the query result set.
query.skip(5);
Selects specific fields to be included in the query result.
query.select('field1', 'field2');
Excludes specific fields from the query result.
query.except('field1', 'field2');
This package is open-source and available under the MIT License.
If you encounter any issues or have suggestions for improvements, please feel free to open an issue on the GitHub repository: Link to GitHub Repository
Contributions and pull requests are welcome!