parentchilddemo-62ef docs

Database API setup

Include your JavaScript API library in a web page

<!-- First JQuery, Bootstrap, etc, ... -->
<script src="https://parentchilddemo-62ef.restdb.io/rest/_jsapi.js"></script>
...

Create a new database api connection

Note that this requires web enabled API-key or a valid JWT token (options.jwt must be set as true). Also note that access restrictions (method, path, events) could prevent this connection from receiving or sending data.

var db = new restdb("your-apikey-here | jwt token", options);

Options
  • url: override database url, e.g. if using a proxy
  • logging: bool (default false)
  • realtime: bool (default false)
  • jwt: bool (default false)

Collection classes

department

Description
- missing description -
Constructor
var obj = new db.department(properties);
Properties
Initial property values for a new instance of an object, e.g.
var instance = new db.department({"name": "value", ...});

Collection properties

name type description
obj['name'] text - missing description -
obj['manager'] people - missing description -

Instance methods

obj.save(callback)

obj.save(function(err, res){
  if (!err){
    // res is now the saved obj
  }
});

obj.delete(callback)

obj.delete(function(err, res){
  if (!err){
    // res is the ID of the deleted object
  }
});

obj.reload(callback)

obj.reload(function(err, res){
  if (!err){
    // res is now the reloaded object from the database
  }
});

obj.on(evt, callback)

obj.on("PUT", function(err, evt){
  if (!err){
    // PUT: evt.data contain the ID of the updated object, i.e. obj
    // DELETE: evt.data contain an array of IDs, of which one is this obj
  }
});

obj['employees'].addChild(childobj, callback)

var child = new db.people({... properties ...});
obj.addChild(child, function(err, res){
  if (!err){
    // res is the saved child
  }
});

obj['employees'].getChild(callback)

obj.getChild(function(err, res){
  if (!err){
    // res is an array of child people objects
  }
});

Collection methods

db.department.find(query, [hints], callback)

var query = {}; // get all records
var hints = {"$max": 10, "$orderby": {"_id": -1}}; // top ten, sort by creation id in descending order
db.department.find(query, hints, function(err, res){
  if (!err){
    // res is an array of department instances
  }
});

db.department.getById(ID, callback)

db.department.getById("570e4661edb62e6a00000000", function(err, res){
  if (!err){
    // res is a department instance
  }
});

Collection events

db.department.on(evt, callback)

db.department.on("POST", function(err, evt){
  if (!err){
    // evt contains data about event
    // PUT:    {event: "put", collection: "department", data: "ID"}
    // POST:   {event: "post", collection: "department", data: {_id: "ID", ...}}
    // DELETE: {event: "delete", collection: "department", data: ["ID1", "ID2", ...]}
  }
});
go to top

people

Description
- missing description -
Constructor
var obj = new db.people(properties);
Properties
Initial property values for a new instance of an object, e.g.
var instance = new db.people({"name": "value", ...});

Collection properties

name type description
obj['name'] text - missing description -
obj['email'] email - missing description -
obj['position'] option - missing description -

Instance methods

obj.save(callback)

obj.save(function(err, res){
  if (!err){
    // res is now the saved obj
  }
});

obj.delete(callback)

obj.delete(function(err, res){
  if (!err){
    // res is the ID of the deleted object
  }
});

obj.reload(callback)

obj.reload(function(err, res){
  if (!err){
    // res is now the reloaded object from the database
  }
});

obj.on(evt, callback)

obj.on("PUT", function(err, evt){
  if (!err){
    // PUT: evt.data contain the ID of the updated object, i.e. obj
    // DELETE: evt.data contain an array of IDs, of which one is this obj
  }
});

Collection methods

db.people.find(query, [hints], callback)

var query = {}; // get all records
var hints = {"$max": 10, "$orderby": {"_id": -1}}; // top ten, sort by creation id in descending order
db.people.find(query, hints, function(err, res){
  if (!err){
    // res is an array of people instances
  }
});

db.people.getById(ID, callback)

db.people.getById("570e4661edb62e6a00000000", function(err, res){
  if (!err){
    // res is a people instance
  }
});

Collection events

db.people.on(evt, callback)

db.people.on("POST", function(err, evt){
  if (!err){
    // evt contains data about event
    // PUT:    {event: "put", collection: "people", data: "ID"}
    // POST:   {event: "post", collection: "people", data: {_id: "ID", ...}}
    // DELETE: {event: "delete", collection: "people", data: ["ID1", "ID2", ...]}
  }
});
go to top

company

Description
- missing description -
Constructor
var obj = new db.company(properties);
Properties
Initial property values for a new instance of an object, e.g.
var instance = new db.company({"name": "value", ...});

Collection properties

name type description
obj['name'] text - missing description -
obj['description'] text - missing description -
obj['manager'] people - missing description -

Instance methods

obj.save(callback)

obj.save(function(err, res){
  if (!err){
    // res is now the saved obj
  }
});

obj.delete(callback)

obj.delete(function(err, res){
  if (!err){
    // res is the ID of the deleted object
  }
});

obj.reload(callback)

obj.reload(function(err, res){
  if (!err){
    // res is now the reloaded object from the database
  }
});

obj.on(evt, callback)

obj.on("PUT", function(err, evt){
  if (!err){
    // PUT: evt.data contain the ID of the updated object, i.e. obj
    // DELETE: evt.data contain an array of IDs, of which one is this obj
  }
});

obj['departments'].addChild(childobj, callback)

var child = new db.department({... properties ...});
obj.addChild(child, function(err, res){
  if (!err){
    // res is the saved child
  }
});

obj['departments'].getChild(callback)

obj.getChild(function(err, res){
  if (!err){
    // res is an array of child department objects
  }
});

Collection methods

db.company.find(query, [hints], callback)

var query = {}; // get all records
var hints = {"$max": 10, "$orderby": {"_id": -1}}; // top ten, sort by creation id in descending order
db.company.find(query, hints, function(err, res){
  if (!err){
    // res is an array of company instances
  }
});

db.company.getById(ID, callback)

db.company.getById("570e4661edb62e6a00000000", function(err, res){
  if (!err){
    // res is a company instance
  }
});

Collection events

db.company.on(evt, callback)

db.company.on("POST", function(err, evt){
  if (!err){
    // evt contains data about event
    // PUT:    {event: "put", collection: "company", data: "ID"}
    // POST:   {event: "post", collection: "company", data: {_id: "ID", ...}}
    // DELETE: {event: "delete", collection: "company", data: ["ID1", "ID2", ...]}
  }
});
go to top

systemjobs

Description
Background jobs for this database
Constructor
var obj = new db.systemjobs(properties);
Properties
Initial property values for a new instance of an object, e.g.
var instance = new db.systemjobs({"description": "value", ...});

Collection properties

name type description
obj['description'] text Job description
obj['crontab'] text Crontab expression
obj['script'] text JavaScript code for job
obj['active'] bool job is paused (created by system)

Instance methods

obj.save(callback)

obj.save(function(err, res){
  if (!err){
    // res is now the saved obj
  }
});

obj.delete(callback)

obj.delete(function(err, res){
  if (!err){
    // res is the ID of the deleted object
  }
});

obj.reload(callback)

obj.reload(function(err, res){
  if (!err){
    // res is now the reloaded object from the database
  }
});

obj.on(evt, callback)

obj.on("PUT", function(err, evt){
  if (!err){
    // PUT: evt.data contain the ID of the updated object, i.e. obj
    // DELETE: evt.data contain an array of IDs, of which one is this obj
  }
});

Collection methods

db.systemjobs.find(query, [hints], callback)

var query = {}; // get all records
var hints = {"$max": 10, "$orderby": {"_id": -1}}; // top ten, sort by creation id in descending order
db.systemjobs.find(query, hints, function(err, res){
  if (!err){
    // res is an array of systemjobs instances
  }
});

db.systemjobs.getById(ID, callback)

db.systemjobs.getById("570e4661edb62e6a00000000", function(err, res){
  if (!err){
    // res is a systemjobs instance
  }
});

Collection events

db.systemjobs.on(evt, callback)

db.systemjobs.on("POST", function(err, evt){
  if (!err){
    // evt contains data about event
    // PUT:    {event: "put", collection: "systemjobs", data: "ID"}
    // POST:   {event: "post", collection: "systemjobs", data: {_id: "ID", ...}}
    // DELETE: {event: "delete", collection: "systemjobs", data: ["ID1", "ID2", ...]}
  }
});
go to top

systemlog

Description
Background log for this database
Constructor
var obj = new db.systemlog(properties);
Properties
Initial property values for a new instance of an object, e.g.
var instance = new db.systemlog({"status": "value", ...});

Collection properties

name type description
obj['status'] text Log status
obj['logstring'] text Log output

Instance methods

obj.save(callback)

obj.save(function(err, res){
  if (!err){
    // res is now the saved obj
  }
});

obj.delete(callback)

obj.delete(function(err, res){
  if (!err){
    // res is the ID of the deleted object
  }
});

obj.reload(callback)

obj.reload(function(err, res){
  if (!err){
    // res is now the reloaded object from the database
  }
});

obj.on(evt, callback)

obj.on("PUT", function(err, evt){
  if (!err){
    // PUT: evt.data contain the ID of the updated object, i.e. obj
    // DELETE: evt.data contain an array of IDs, of which one is this obj
  }
});

Collection methods

db.systemlog.find(query, [hints], callback)

var query = {}; // get all records
var hints = {"$max": 10, "$orderby": {"_id": -1}}; // top ten, sort by creation id in descending order
db.systemlog.find(query, hints, function(err, res){
  if (!err){
    // res is an array of systemlog instances
  }
});

db.systemlog.getById(ID, callback)

db.systemlog.getById("570e4661edb62e6a00000000", function(err, res){
  if (!err){
    // res is a systemlog instance
  }
});

Collection events

db.systemlog.on(evt, callback)

db.systemlog.on("POST", function(err, evt){
  if (!err){
    // evt contains data about event
    // PUT:    {event: "put", collection: "systemlog", data: "ID"}
    // POST:   {event: "post", collection: "systemlog", data: {_id: "ID", ...}}
    // DELETE: {event: "delete", collection: "systemlog", data: ["ID1", "ID2", ...]}
  }
});
go to top

emailoutbound

Description
Outgoing email from this application
Constructor
var obj = new db.emailoutbound(properties);
Properties
Initial property values for a new instance of an object, e.g.
var instance = new db.emailoutbound({"to": "value", ...});

Collection properties

name type description
obj['to'] email email to address (created by system)
obj['subject'] text email subject (created by system)
obj['body'] richtext mail body (created by system)

Instance methods

obj.save(callback)

obj.save(function(err, res){
  if (!err){
    // res is now the saved obj
  }
});

obj.delete(callback)

obj.delete(function(err, res){
  if (!err){
    // res is the ID of the deleted object
  }
});

obj.reload(callback)

obj.reload(function(err, res){
  if (!err){
    // res is now the reloaded object from the database
  }
});

obj.on(evt, callback)

obj.on("PUT", function(err, evt){
  if (!err){
    // PUT: evt.data contain the ID of the updated object, i.e. obj
    // DELETE: evt.data contain an array of IDs, of which one is this obj
  }
});

Collection methods

db.emailoutbound.find(query, [hints], callback)

var query = {}; // get all records
var hints = {"$max": 10, "$orderby": {"_id": -1}}; // top ten, sort by creation id in descending order
db.emailoutbound.find(query, hints, function(err, res){
  if (!err){
    // res is an array of emailoutbound instances
  }
});

db.emailoutbound.getById(ID, callback)

db.emailoutbound.getById("570e4661edb62e6a00000000", function(err, res){
  if (!err){
    // res is a emailoutbound instance
  }
});

Collection events

db.emailoutbound.on(evt, callback)

db.emailoutbound.on("POST", function(err, evt){
  if (!err){
    // evt contains data about event
    // PUT:    {event: "put", collection: "emailoutbound", data: "ID"}
    // POST:   {event: "post", collection: "emailoutbound", data: {_id: "ID", ...}}
    // DELETE: {event: "delete", collection: "emailoutbound", data: ["ID1", "ID2", ...]}
  }
});
go to top

emailinbound

Description
Incoming email to this application
Constructor
var obj = new db.emailinbound(properties);
Properties
Initial property values for a new instance of an object, e.g.
var instance = new db.emailinbound({"from": "value", ...});

Collection properties

name type description
obj['from'] email email to address (created by system)
obj['sobject'] text email subject (created by system)
obj['body'] richtext mail body (created by system)

Instance methods

obj.save(callback)

obj.save(function(err, res){
  if (!err){
    // res is now the saved obj
  }
});

obj.delete(callback)

obj.delete(function(err, res){
  if (!err){
    // res is the ID of the deleted object
  }
});

obj.reload(callback)

obj.reload(function(err, res){
  if (!err){
    // res is now the reloaded object from the database
  }
});

obj.on(evt, callback)

obj.on("PUT", function(err, evt){
  if (!err){
    // PUT: evt.data contain the ID of the updated object, i.e. obj
    // DELETE: evt.data contain an array of IDs, of which one is this obj
  }
});

Collection methods

db.emailinbound.find(query, [hints], callback)

var query = {}; // get all records
var hints = {"$max": 10, "$orderby": {"_id": -1}}; // top ten, sort by creation id in descending order
db.emailinbound.find(query, hints, function(err, res){
  if (!err){
    // res is an array of emailinbound instances
  }
});

db.emailinbound.getById(ID, callback)

db.emailinbound.getById("570e4661edb62e6a00000000", function(err, res){
  if (!err){
    // res is a emailinbound instance
  }
});

Collection events

db.emailinbound.on(evt, callback)

db.emailinbound.on("POST", function(err, evt){
  if (!err){
    // evt contains data about event
    // PUT:    {event: "put", collection: "emailinbound", data: "ID"}
    // POST:   {event: "post", collection: "emailinbound", data: {_id: "ID", ...}}
    // DELETE: {event: "delete", collection: "emailinbound", data: ["ID1", "ID2", ...]}
  }
});
go to top

emailunsubscribed

Description
Unsubscribed email from this application
Constructor
var obj = new db.emailunsubscribed(properties);
Properties
Initial property values for a new instance of an object, e.g.
var instance = new db.emailunsubscribed({"to": "value", ...});

Collection properties

name type description
obj['to'] email unsubscribe email address (created by system)

Instance methods

obj.save(callback)

obj.save(function(err, res){
  if (!err){
    // res is now the saved obj
  }
});

obj.delete(callback)

obj.delete(function(err, res){
  if (!err){
    // res is the ID of the deleted object
  }
});

obj.reload(callback)

obj.reload(function(err, res){
  if (!err){
    // res is now the reloaded object from the database
  }
});

obj.on(evt, callback)

obj.on("PUT", function(err, evt){
  if (!err){
    // PUT: evt.data contain the ID of the updated object, i.e. obj
    // DELETE: evt.data contain an array of IDs, of which one is this obj
  }
});

Collection methods

db.emailunsubscribed.find(query, [hints], callback)

var query = {}; // get all records
var hints = {"$max": 10, "$orderby": {"_id": -1}}; // top ten, sort by creation id in descending order
db.emailunsubscribed.find(query, hints, function(err, res){
  if (!err){
    // res is an array of emailunsubscribed instances
  }
});

db.emailunsubscribed.getById(ID, callback)

db.emailunsubscribed.getById("570e4661edb62e6a00000000", function(err, res){
  if (!err){
    // res is a emailunsubscribed instance
  }
});

Collection events

db.emailunsubscribed.on(evt, callback)

db.emailunsubscribed.on("POST", function(err, evt){
  if (!err){
    // evt contains data about event
    // PUT:    {event: "put", collection: "emailunsubscribed", data: "ID"}
    // POST:   {event: "post", collection: "emailunsubscribed", data: {_id: "ID", ...}}
    // DELETE: {event: "delete", collection: "emailunsubscribed", data: ["ID1", "ID2", ...]}
  }
});
go to top

Subscribe to Database events in realtime

To use the realtime features set options parameter to {realtime: true}.

Listen for data events for REST operations
db.on(event, callback)
Predefined Events
  • "CONNECT"
  • "DISCONNECT"
  • "POST"
  • "PUT"
  • "DELETE"
Subscribe to "PUT" database operations
db.on("PUT", function(error, eventdata){
  // eventdata format: {event: "put", collection: "the-collection-name", data: "ID"}
}
Subscribe to "POST" database operations
db.on("POST", function(error, eventdata){
  // eventdata format: {event: "post", collection: "the-collection.name", data: {_id: ID, ...}}
}
Subscribe to "DELETE" database operations
db.on("DELETE", function(error, eventdata){
  // eventdata format: {event: "delete", collection: "the-collection-name", data: ["ID1", "ID2", ...]}
}

Publish / Subscribe to custom events

Subscribe to custom events from applications
db.on("<your_event>", function(error, eventdata){
  // eventdata format: {event: "<your_event>", data: {...}}
}
Publish custom events
db.publish("<your_event>", {"answer": 42}, function(error, result){
  // your handling code here
}