Database DAO

Simplified database access objects utility.

Version 3.x

Basic Usage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var dao = require('db/dao');

//create a DAO from configuration
var customers = dao.create({
  "dbName": "CUSTOMERS",
  "properties": [{
      "name": "id",
      "dbName": "ID",
      "type": "BIGINT",
      "id": true
    }, {
      "name": "orgName",
      "dbName": "ORG_NAME",
      "type": "VARCHAR",
      "required": true
    },{
      "name": "employeesNumber",
      "dbName": "ORG_EMP_NUM",
      "type": "INTEGER",
      "required": true
   },{
      "name": "orgDescription",
      "dbName": "ORG_DESCR",
      "type": "VARCHAR",
      "required": false
   }]
});

//Create CUSTOMERS table
customers.createTable();

try{
	
  //Create a new customer entity
  var customerId = customers.insert({"orgName": "ACME", "employeesNumber": 1000});
		
  //List all customer entities
  var customersList = customers.list(); 
	
  //Get a particular customer entity by its id
  var customer = customers.find(customerId); 
	
  //Update a customer entity property
  customer.orgDescription = "ACME is a company";
  customers.update(customer);
	 
  //Delete a customer entity
  customers.remove(customerId);
	
} finally {  
  //Drop CUSTOMERS table
  customers.dropTable();
}

Definition

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). β€”
count() returns the number of persisted entities Number
createTable() Creates a table for persisting entities β€”
dropTable() Drops the entities table β€”

Compatibility

Rhino Nashorn V8
βœ… βœ… βœ…


Edit