API: dao
Source:
db/dao.ts
Prepare a JSON object for insert into DB
Usage
javascript
import { dao } from "sdk/db";
//create a DAO from configuration
const customers = 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 CUSTOMERS table
customers.createTable();
try {
//Create a new customer entity
let customerId = customers.insert({
orgName: "ACME",
employeesNumber: 1000
});
//List all customer entities
let customersList = customers.list();
//Get a particular customer entity by its id
let 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();
}