Parse Model Factory
Intro
Parse Model Factory is an addon to parse-server. It provides a lot of basic queries so you can centralize all of your queries in one place.
This addon is amazing when you don't want query.find()
all over your project.
You can have clean models with just a few lines of code:
const ModelFactory = ;const MyModel = ModelFactory;MyModel { const query = this; // all of your logic return this;}moduleexports = MyModel;
As you can see, we get the query from the model factory and we call _find
with our complex query, an array of includes and the limit.
No more query.include().include().include()
❤️
Getting Started
Running model factory
Locally
$ npm install parse-model-factory
Creating your first model
The only thing you should do is requiring the module and call the generate
function
const ModelFactory = ; const modelProperties = defaultIncludes: 'prop1' 'prop2'; const objectProperties = { const prop = this; return `Your prop is `; }; const MyModel = ModelFactory;
Now you should be able to do:
const query = MyModel;query; MyModel ;
Object Methods index
object.customFetch()
-> Will fetch the object with the master keyobject.saveMasterKey()
-> Will save the object with the master keyobject.destroyMasterKey()
-> Will destroy the object with the master keyobject.setAcl(force = false, func, ...args)
- force : if false will set the acl only when the object is new
- func : method you want to set
public | private | read | write | user
const object = ;object;// == setPublicReadAccess(true) && setPublicWriteAccess(false) object;// == setReadAccess(user) && setWriteAccess(user) object;// == setReadAccess(user1) && setReadAccess(user2) && setPublicWriteAccess(false) object;// == setWriteAccess(user1) && setWriteAccess(user2) && setPublicReadAccess(true) object;// == setReadAccess(user) && setWriteAccess(user)
Queries Methods index
Model._query()
Methods with master key
Model._find(query, includes = [], limit = 5000, skip = 0)
Model._get(query, objectId, includes = [])
Model._each(query, includes = [], callback)
Model._count(query)
Model._first(query, includes = [])
Model.save(object, params = null)
Model.saveAll(objects)
Model.destroy(object)
Model.destroyAll(objects)
Methods without master key
Model._findRegular(query, includes = [], limit = 5000, skip = 0, option = {})
Model._getRegular(query, objectId, includes = [], option = {})
Model._countRegular(query, option = {})
Model._firstRegular(query, includes = [], option = {})
const query = MyModel;query; const session = sessionToken: requser ; const result = await MyModel;