import{dao}from"sdk/mongodb";import{response}from"sdk/http";//create a DAO from configurationletcustomers=dao.create({table:"CUSTOMERS",properties:[{name:"id",column:"ID",type:"BIGINT",id:true},{name:"orgName",column:"ORG_NAME",type:"VARCHAR",required:true},{name:"employeesNumber",column:"ORG_EMP_NUM",type:"INTEGER",required:true},{name:"orgDescription",column:"ORG_DESCR",type:"VARCHAR",required:false}]});//Create a new customer entityletcustomerId=customers.insert({orgName:"ACME",employeesNumber:1000});response.println("Id: "+customerId);//List all customer entitiesletcustomersList=customers.list();//Get a particular customer entity by its idletcustomer=customers.find(customerId);//Update a customer entity propertycustomer.orgDescription="ACME is a company";customers.update(customer);//Delete a customer entitycustomers.remove(customerId);
Functions
Function
Description
Returns
create(oConfiguration, loggerName?)
Creates new DAO instances from oConfiguraiton JS object, which can be either standard ORM definition or a standard dirigible table definition
DAO
Objects
DAO
Function
Description
Returns
insert(entity)
inserts array or entity and returns id (or ids of array of entities was supplied as input)
any
list(oQuerySettings?)
lists entities optionally constrained with the supplied query settings
Array
find(id, expand?, select?)
returns an entity by its id(if any), optionally expanding inline the associations defined in expand and optionally constraining the entitiy properties to those specified in select
Object
update(entity)
updates a persistent entity and returns for its dao chaining
DAO
remove(?id)
delete entity by id, or array of ids, or delete all (if not argument is provided).