new QuerySet()
Base class responsible for all ORM (please
) actions.
- Source:
Properties:
Name | Type | Argument | Default | Description |
---|---|---|---|---|
model |
Object | |||
endpoint |
String |
<optional> |
'list' | |
method |
String |
<optional> |
'GET' | |
headers |
Object |
<optional> |
{} | |
properties |
Object |
<optional> |
{} | |
query |
Object |
<optional> |
{} | |
payload |
Object |
<optional> |
{} | |
attachments |
Object |
<optional> |
{} | |
_serialize |
Boolean |
<optional> |
true |
Classes
Members
-
<constant> All
-
Allows fetching of all objects of a type (DataObjects, Classes etc.) recursively.
- Source:
Examples
var all = DataObject.please().all({ instanceName: 'test-instace', className: 'test-class' }); all.on('start', function() { console.log('all::start'); }); all.on('stop', function() { console.log('all::stop'); }); all.on('page', function(page) { console.log('all::page', page); }); all.on('error', function(error) { console.log('all::error', error); });
Methods
-
add(properties, field)
-
Adds an array to an array field.
Parameters:
Name Type Description properties
Object lookup properties used for path resolving
field
Object to add to.
- Source:
Returns:
- Type
- QuerySet
Example
DataObject.please().add({instanceName: 'my-instance', className: 'my-class', id: 1}, {array_field: [1,2]})
-
add(field, array)
-
Adds an array to an array field.
Parameters:
Name Type Description field
String name.
array
Array to add to the field.
- Source:
Returns:
- Type
- QuerySet
Example
Object.add('authors', [1,2,3]);
-
addUnique(field, array)
-
Adds an array to an array field without duplicate values.
Parameters:
Name Type Description field
String name.
array
Array to add to the field.
- Source:
Returns:
- Type
- QuerySet
Example
Object.add('authors', [1,2,3]);
-
addUnique(properties, field)
-
Adds an array to an array field without duplicate values.
Parameters:
Name Type Description properties
Object lookup properties used for path resolving
field
Object to add to.
- Source:
Returns:
- Type
- QuerySet
Example
DataObject.please().add({instanceName: 'my-instance', className: 'my-class', id: 1}, {array_field: [1,2]})
-
bulkCreate(objects)
-
Creates many objects based on provied Array of objects.
Parameters:
Name Type Description objects
Array - Source:
Returns:
- Type
- Promise
Example
const objects = [Instance({name: 'test1'}), Instance({name: 'tes21'})]; Instance.please().bulkCreate(objects).then(function(instances) { console.log('instances', instances); });
-
cacheKey(cache_key)
-
Sets the provided cache key in the request query.
Parameters:
Name Type Description cache_key
String the cache key for the result
- Source:
Returns:
- Type
- QuerySet
Example
DataEndpoint.please().DataEndpoint.please().fetchData({name: 'dataViewName', instanceName: 'test-one'}).cacheKey('123').then(function(data) {});
-
contains(field, array)
-
Filters DataObjects using _contains.
Parameters:
Name Type Description field
String name
array
Array of ids
- Source:
Returns:
- Type
- QuerySet
Example
DataObject.please().list({instanceName: 'my-instance', className: 'books'}).contains('authors', [1, 2, 3])
-
count()
-
Returns DataObject count.
- Source:
Returns:
- Type
- QuerySet
Example
DataObject.please().list({ instanceName: 'test-instace', className: 'test-class' }).count().then(function(response) {});
-
create(object)
-
A convenience method for creating an object and saving it all in one step.
Parameters:
Name Type Description object
Object - Source:
Returns:
- Type
- Promise
Example
// Thus: Instance .please() .create({name: 'test-one', description: 'description'}) .then(function(instance) {}); // and: var instance = Instance({name: 'test-one', description: 'description'}); instance.save().then(function(instance) {}); // are equivalent.
-
currentMonth()
-
Sets the range of Usage query to current month.
- Source:
Returns:
- Type
- QuerySet
Example
DailyUsage.please().list().currentMonth().then(function(usage) {});
-
delete(properties)
-
Removes single object based on provided properties.
Parameters:
Name Type Description properties
Object lookup properties used for path resolving
- Source:
Returns:
- Type
- QuerySet
Example
Instance.please().delete({name: 'test-instance'}).then(function() {}); Class.please().delete({name: 'test', instanceName: 'test-one'}).then(function() {});
-
endDate(date)
-
Sets end date for Usage.
Parameters:
Name Type Description date
Date - Source:
Returns:
- Type
- QuerySet
Example
DailyUsage.please().list().endDate(new Date()).then(function(usage) {});
-
excludedFields(fields)
-
Removes specified fields from object response.
Parameters:
Name Type Description fields
Object - Source:
Returns:
- Type
- QuerySet
Example
DataObject.please().list({ instanceName: 'test-instace', className: 'test-class' }).excludedFields(['title', 'author']).then(function(dataobjects) {});
-
fields(fields)
-
Selects specified fields from object.
Parameters:
Name Type Description fields
Object - Source:
Returns:
- Type
- QuerySet
Example
DataObject.please().list({ instanceName: 'test-instace', className: 'test-class' }).fields(['title', 'author']).then(function(dataobjects) {});
-
filter(filters)
-
Allows to filter the request.
Parameters:
Name Type Description filters
Object object containing the filters.
- Source:
Returns:
- Type
- QuerySet
Example
DataObject.please().list({instanceName: 'INSTANCE_NAME', className: 'CLASS_NAME'}).filter({ title: { _eq: "Star Wars"} }).then(function(dataobjects) {});
-
first( [properties] [, query])
-
Returns the first object matched by the lookup properties or undefined, if there is no matching object.
Parameters:
Name Type Argument Default Description properties
Object <optional>
{} query
Object <optional>
{} - Source:
Returns:
- Type
- Promise
Example
Instance.please().first().then(function(instance) {}); Class.please().first({instanceName: 'test-one'}).then(function(cls) {});
-
get(properties)
-
Returns the object matching the given lookup properties.
Parameters:
Name Type Description properties
Object lookup properties used for path resolving
- Source:
Returns:
- Type
- QuerySet
Example
Instance.please().get({name: 'test-one'}).then(function(instance) {});
-
getOrCreate(properties, defaults)
-
A convenience method for looking up an object with the given lookup properties, creating one if necessary.
Successful callback will receive object, created arguments.Parameters:
Name Type Description properties
Object attributes which will be used for object retrieving
defaults
Object attributes which will be used for object creation
- Source:
Returns:
- Type
- Promise
Example
Instance .please() .getOrCreate({name: 'test-one'}, {description: 'test'}) .then(function(instance, created) {}); // above is equivalent to: Instance .please() .get({name: 'test-one'}) .then(function(instance) { // Get }) .catch(function() { // Create return Instance.please().create({name: 'test-one', description: 'test'}); });
-
getRelatedObjects(field)
-
Gets related objects via relation field name.
Parameters:
Name Type Description field
String name.
- Source:
Returns:
- Type
- QuerySet
Example
Object.getRelatedObjects('authors');
-
increment(field, value)
-
Increments single object field based on provided arguments.
Parameters:
Name Type Description field
String name.
value
Number to increment the field by,
- Source:
Returns:
- Type
- QuerySet
Example
Object.increment('views', 1);
-
increment(properties, field)
-
Increments single object based on provided arguments
Parameters:
Name Type Description properties
Object lookup properties used for path resolving
field
Object to increment.
- Source:
Returns:
- Type
- QuerySet
Example
DataObject.please().increment({instanceName: 'my-instance', className: 'my-class', id: 1}, {views: 1})
-
is(field, filters)
-
Filters DataObjects using _is.
Parameters:
Name Type Description field
String name
filters
Object - Source:
Returns:
- Type
- QuerySet
Example
DataObject.please().list({instanceName: 'my-instance', className: 'books'}).is('authors', { name: { _eq: 'Stephen King'}})
-
list( [properties] [, query])
-
Returns list of objects that match the given lookup properties.
Parameters:
Name Type Argument Default Description properties
Object <optional>
{} lookup properties used for path resolving
query
Object <optional>
{} - Source:
Returns:
- Type
- QuerySet
Example
Instance.please().list().then(function(instances) {}); Class.please().list({instanceName: 'test-one'}).then(function(classes) {});
-
near(coordinates)
-
Filters dataobjects by a geopoint field.
Parameters:
Name Type Description coordinates
Object - Source:
Returns:
- Type
- QuerySet
Examples
DataObject.please().list({ instanceName: 'test-instace', className: 'test-class' }).near({ geopoint_field_name: { latitude: POINT_LATITUDE, longitude: POINT_LONGITUDE }}).then(function(dataobjects) {});
DataObject.please().list({ instanceName: 'test-instace', className: 'test-class' }).near({ geopoint_field_name: { latitude: POINT_LATITUDE, longitude: POINT_LONGITUDE, distance_in_kilometers: DISTANCE_IN_KILOMETERS }}).then(function(dataobjects) {});
DataObject.please().list({ instanceName: 'test-instace', className: 'test-class' }).near({ geopoint_field_name: { latitude: POINT_LATITUDE, longitude: POINT_LONGITUDE, distance_in_miles: DISTANCE_IN_MILES }}).then(function(dataobjects) {});
-
orderBy(field)
-
Orders DataObject by field.
Parameters:
Name Type Description field
String - Source:
Returns:
- Type
- QuerySet
Example
DataObject.please().list({ instanceName: 'test-instace', className: 'test-class' }).orderBy('author').then(function(dataobjects) {}); DataObject.please().list({ instanceName: 'test-instace', className: 'test-class' }).orderBy('-author').then(function(dataobjects) {});
-
ordering( [value])
-
Sets order of returned objects.
Parameters:
Name Type Argument Default Description value
String <optional>
'asc' allowed choices are "asc" and "desc"
- Source:
Returns:
- Type
- QuerySet
Example
Instance.please().ordering('desc').then(function(instances) {}); Class.please({instanceName: 'test-one'}).ordering('desc').then(function(classes) {});
-
pageSize(value)
-
Sets page size.
Parameters:
Name Type Description value
Number - Source:
Returns:
- Type
- QuerySet
Example
Instance.please().pageSize(2).then(function(instances) {}); Class.please({instanceName: 'test-one'}).pageSize(2).then(function(classes) {});
-
poll(options [, start])
-
Allows polling of a channel.
Parameters:
Name Type Argument Default Description options
Object start
Boolean <optional>
true - Source:
Returns:
- Type
- ChannelPoll
Example
var poll = Channel.please().poll({ instanceName: 'test-instace', name: 'test-class' }); poll.on('start', function() { console.log('poll::start'); }); poll.on('stop', function() { console.log('poll::stop'); }); poll.on('message', function(message) { console.log('poll::message', message); }); poll.on('custom', function(message) { console.log('poll::custom', message); }); poll.on('create', function(data) { console.log('poll::create', data); }); poll.on('delete', function(data) { console.log('poll::delete', data); }); poll.on('update', function(data) { console.log('poll::update', data); }); poll.on('error', function(error) { console.log('poll::error', error); }); poll.start();
-
publish(channel, message [, room])
-
Publishes to a channel.
Parameters:
Name Type Argument Default Description channel
Object message
Object room
String <optional>
null - Source:
Returns:
- Type
- QuerySet
Example
Channel.please().publish({ instanceName: 'test-instace', name: 'test-class' }, { content: 'my message'});
-
raw()
-
Disables serialization. Callback will will recive raw JavaScript objects.
- Source:
Returns:
- Type
- QuerySet
Example
Instance.please().raw().then(function(response) {}); Class.please({instanceName: 'test-one'}).raw().then(function(response) {});
-
remove(properties, field)
-
Subtracts an array from an array field.
Parameters:
Name Type Description properties
Object lookup properties used for path resolving
field
Object to subtract from.
- Source:
Returns:
- Type
- QuerySet
Example
DataObject.please().remove({instanceName: 'my-instance', className: 'my-class', id: 1}, {array_field: [1,2]})
-
remove(field, array)
-
Subtracts an array from an array field.
Parameters:
Name Type Description field
String name.
array
Array to subtract from the field.
- Source:
Returns:
- Type
- QuerySet
Example
Object.remove('authors', [1]);
-
rename(properties, payload)
-
A convenience method for renaming an object that support the action.
Parameters:
Name Type Description properties
Object lookup properties used for path resolving
payload
Object object containing the payload to be sent
- Source:
Returns:
- Type
- QuerySet
Example
Model.please().fetchData({name: 'model_name', instanceName: 'test-one'}, { new_name: 'new_name'}).then(function(model) {});
-
request( [requestPath] [, requestOptions])
-
Executes current state of QuerySet
Parameters:
Name Type Argument Default Description requestPath
String <optional>
null requestOptions
Object <optional>
{} - Source:
Returns:
- Type
- Promise
Example
Instance.please().list().request().then(function(instance) {});
-
startDate(date)
-
Sets start date for Usage.
Parameters:
Name Type Description date
Date - Source:
Returns:
- Type
- QuerySet
Example
DailyUsage.please().list().startDate(new Date()).then(function(usage) {});
-
templateResponse(name)
-
Renders the api response as a template.
Parameters:
Name Type Description name
template_name of template to be rendered
- Source:
Returns:
- Type
- QuerySet
Example
DataObject .please() .list({instanceName: 'my-instance', className: 'my-class'}) .templateResponse('objects_html_table') .then(function(objects) {});
-
then(callback)
-
Wrapper around Queryset.request method
Parameters:
Name Type Description callback
function - Source:
Returns:
- Type
- Promise
-
total()
-
Sets grouping for Usage.
- Source:
Returns:
- Type
- QuerySet
Example
DailyUsage.please().list().total().then(function(usage) {});
-
update(properties, object)
-
Updates single object based on provided arguments
Parameters:
Name Type Description properties
Object lookup properties used for path resolving
object
Object attributes to update
- Source:
Returns:
- Type
- QuerySet
Example
Instance .please() .update({name: 'test-instance'}, {description: 'new one'}) .then(function(instance) {}); Class .please() .update({name: 'test', instanceName: 'test-one'}, {description: 'new one'}) .then(function(cls) {});
-
updateOrCreate(properties [, object] [, defaults])
-
A convenience method for updating an object with the given properties, creating a new one if necessary.
Successful callback will receive object, updated arguments.Parameters:
Name Type Argument Default Description properties
Object lookup properties used for path resolving
object
Object <optional>
{} object with (field, value) pairs used in case of update
defaults
Object <optional>
{} object with (field, value) pairs used in case of create
- Source:
Returns:
- Type
- Promise
Example
Instance .please() .updateOrCreate({name: 'test-one'}, {description: 'new-test'}, {description: 'create-test'}) .then(function(instance, updated) {}); // above is equivalent to: Instance .please() .update({name: 'test-one'}, {description: 'new-test'}) .then(function(instance) { // Update }) .catch(function() { // Create return Instance.please().create({name: 'test-one', description: 'create-test'}); });