Most Web Framework ORM Module
npm install most-data!MOST Web Framework Codename Blushift
_Note: If you want to use MOST Web Framework v.1x, continue reading._
The most-data module is the main ORM module of MOST Web Framework applications and enables developers
to write scalable data-driven applications and services.
{
"name": "User", "id": 90, "title": "Users", "inherits": "Account", "hidden": false, "sealed": false, "abstract": false, "version": "1.4",
"fields": [
{
"name": "id", "title": "Id", "description": "The identifier of the item.",
"type": "Integer",
"nullable": false,
"primary": true
},
{
"name": "accountType", "title": "Account Type", "description": "Contains a set of flags that define the type and scope of an account object.",
"type": "Integer",
"readonly":true,
"value":"javascript:return 0;"
},
{
"name": "lockoutTime", "title": "Lockout Time", "description": "The date and time that this account was locked out.",
"type": "DateTime",
"readonly": true
},
{
"name": "logonCount", "title": "Logon Count", "description": "The number of times the account has successfully logged on.",
"type": "Integer",
"value": "javascript:return 0;",
"readonly": true
},
{
"name": "enabled", "title": "Enabled", "description": "Indicates whether a user is enabled or not.",
"type": "Boolean",
"nullable": false,
"value": "javascript:return true;"
},
{
"name": "lastLogon", "title": "Last Logon", "description": "The last time and date the user logged on.",
"type": "DateTime",
"readonly": true
},
{
"name": "groups", "title": "User Groups", "description": "A collection of groups where user belongs.",
"type": "Group",
"expandable": true,
"mapping": {
"associationAdapter": "GroupMembers", "parentModel": "Group",
"parentField": "id", "childModel": "User", "childField": "id",
"associationType": "junction", "cascade": "delete",
"select": [
"id",
"name",
"alternateName"
]
}
},
{
"name": "additionalType",
"value":"javascript:return this.model.name;",
"readonly":true
},
{
"name": "accountType",
"value": "javascript:return 0;"
}
], "privileges":[
{ "mask":1, "type":"self", "filter":"id eq me()" },
{ "mask":15, "type":"global", "account":"*" }
],
"constraints":[
{
"description": "User name must be unique across different records.",
"type":"unique",
"fields": [ "name" ]
}
],
"views": [
{
"name":"list", "title":"Users List", "fields":[
{ "name":"id", "hidden":true },
{ "name":"description" },
{ "name":"name" },
{ "name":"enabled" },
{ "name":"dateCreated" },
{ "name":"dateModified" }
], "order":"dateModified desc"
}
],
"eventListeners": [
{ "name":"New User Credentials Provider", "type":"/app/controllers/user-credentials-listener" }
],
"seed":[
{
"name":"anonymous",
"description":"Anonymous User",
"groups":[
{ "name":"Guests" }
]
},
{
"name":"admin@example.com",
"description":"Site Administrator",
"groups":[
{ "name":"Administrators" }
]
}
]
}
{
"name": "User", "id": 90, "title": "Users", "inherits": "Account", "hidden": false,
"sealed": false, "abstract": false, "version": "1.4",
"fields": [ .. ]
...
}
//User model inherits Account model
{
"name": "User", "id": 90, "title": "Users", "inherits": "Account", "hidden": false,
"sealed": false, "abstract": false, "version": "1.4",
"fields": [ .. ]
...
}
//User model has a unique constraint based on user name.
...
"constraints":[
{
"description": "User name must be unique across different records.",
"type":"unique",
"fields": [ "name" ]
}
]
...
...
{
"name": "enabled", "title": "Enabled", "description": "Indicates whether a user is enabled or not.",
"type": "Boolean",
"nullable": false,
"value": "javascript:return true;"
},
{
"name": "dateCreated",
"title": "Date Created",
"description": "The date on which this item was created.",
"type": "Date",
"value":"javascript:return (new Date());",
"readonly":true
}
...
...
{
"name": "dateModified",
"title": "Date Modified",
"description": "The date on which this item was most recently modified.",
"type": "Date",
"readonly":true,
"value":"javascript:return (new Date());",
"calculation":"javascript:return (new Date());"
}
...
{
"name": "Order", "id": 449, "title": "Order", "hidden": false, ...
"fields": [
...
{
"name": "customer",
"title": "Customer",
"description": "Party placing the order.",
"type": "Party",
"expandable":true
}
...
]
}
...
{
"name": "groups", "title": "User Groups", "description": "A collection of groups where user belongs.",
"type": "Group",
"expandable": true,
"mapping": {
"associationAdapter": "GroupMembers", "parentModel": "Group",
"parentField": "id", "childModel": "User", "childField": "id",
"associationType": "junction", "cascade": "delete"
}
}
...
//get customers orders with status delivered
context.model('Order').where('orderStatus/alternateName').equal('OrderedDelivered')
.and("customer").equal(257)
.list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
DataQueryable class offers a wide set of methods for
filtering, paging, ordering and grouping data objects.
//get orders order by order date
context.model('Order').where('orderStatus/alternateName').equal('OrderProcessing')
.orderBy('orderDate').thenBy('paymentMethod/name')
.list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
//skip 15 orders and take next 15
context.model('Order').where('orderStatus/alternateName').equal('OrderProcessing')
.take(15).skip(15)
.list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
The result of a paged query is an instance of DataResultSet class.
context.model('Order').where('orderStatus/alternateName').equal('OrderProcessing')
.select('id','orderDate','orderedItem/name as productName', 'customer/description as customerName')
.take(15)
.list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
//count orders by order status
context.model('Order')
.select('count(id) as orderCount','orderStatus/name as orderStatusName')
.groupBy('orderStatus/name')
.where('orderDate').getMonth().equal(10).and('orderDate').getFullYear().equal(2015)
.all().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
//Order.json schema
...
"eventListeners": [
{ "name":"New Order Notification", "type":"/app/controllers/new-order-listener" }
]
...
//new-order-listener.js listener
...
exports.afterSave = function(event, callback) {
if (event.state!=1) { return callback(); }
//use most web mailer module
var mm = require("most-web-mailer");
mm.mailer(context).subject("New Order Notification")
.subject("New Order")
.template("new-order-notification")
.to("employee1@example.com")
.test()
.send(event.target, function(err, res) {
if (err) { return done(err); }
return done();
});
}
...
"privileges":[
{ "mask":1, "type":"self", "filter":"id eq me()" },
{ "mask":15, "type":"global", "account":"*" }
]
...
{
"name": "OrderStatus", "id": 9507079, "title": "Order Status", "hidden": false, "sealed": false,
"abstract": false, "version": "1.1", "caching":"always"
}
{
"name": "OrderStatus", "id": 9507079, "title": "Order Status", "hidden": false,
"sealed": false, "abstract": false, "version": "1.1",
...
"fields": [
...
],
..
"seed": [
{ "id":1, "name":"Delivered", "alternateName":"OrderDelivered", "description":"Representing the successful delivery of an order."
}, {
"id":2, "name":"Cancelled", "alternateName":"OrderCancelled", "description":"Representing the cancellation of an order."
}, {
"id":3, "name":"In Transit", "alternateName":"OrderInTransit", "description":"Representing that an order is in transit."
}, {
"id":4, "name":"Payment Due", "alternateName":"OrderPaymentDue", "description":"Representing that payment is due on an order."
}, {
"id":5, "name":"Pickup", "alternateName":"OrderPickup", "description":"Representing availability of an order for pickup."
}, {
"id":6, "name":"Processing", "alternateName":"OrderProcessing", "description":"Representing that an order is being processed."
}, {
"id":7, "name":"Problem", "alternateName":"OrderProblem", "description":"Representing that there is a problem with the order."
}, {
"id":8, "name":"Returned", "alternateName":"OrderReturned", "description":"Representing that an order has been returned."
}
]
}
Install the data adapter:
npm install most-data-mysql
Append the adapter type in application configuration (app.json#adapterTypes):
...
"adapterTypes": [
...
{ "name":"MySQL Data Adapter", "invariantName": "mysql", "type":"most-data-mysql" }
...
]
Register an adapter in application configuration (app.json#adapters):
adapters: [
...
{ "name":"development", "invariantName":"mysql", "default":true,
"options": {
"host":"localhost",
"port":3306,
"user":"user",
"password":"password",
"database":"test"
}
}
...
]
#### MOST Web Framework MSSQL Adapter for connecting with Microsoft SQL Database Server
Install the data adapter:
npm install most-data-mssql
Append the adapter type in application configuration (app.json#adapterTypes):
...
"adapterTypes": [
...
{ "name":"MSSQL Data Adapter", "invariantName": "mssql", "type":"most-data-mssql" }
...
]
Register an adapter in application configuration (app.json#adapters):
adapters: [
...
{ "name":"development", "invariantName":"mssql", "default":true,
"options": {
"server":"localhost",
"user":"user",
"password":"password",
"database":"test"
}
}
...
]
#### MOST Web Framework PostgreSQL Adapter for connecting with PostgreSQL Database Server
Install the data adapter:
npm install most-data-pg
Append the adapter type in application configuration (app.json#adapterTypes):
...
"adapterTypes": [
...
{ "name":"PostgreSQL Data Adapter", "invariantName": "postgres", "type":"most-data-pg" }
...
]
Register an adapter in application configuration (app.json#adapters):
adapters: [
...
{ "name":"development", "invariantName":"postgres", "default":true,
"options": {
"host":"localhost",
"post":5432,
"user":"user",
"password":"password",
"database":"db"
}
}
...
]
#### MOST Web Framework Oracle Adapter for connecting with Oracle Database Server
Install the data adapter:
npm install most-data-oracle
Append the adapter type in application configuration (app.json#adapterTypes):
...
"adapterTypes": [
...
{ "name":"Oracle Data Adapter", "invariantName": "oracle", "type":"most-data-oracle" }
...
]
Register an adapter in application configuration (app.json#adapters):
adapters: [
...
{ "name":"development", "invariantName":"oracle", "default":true,
"options": {
"host":"localhost",
"port":1521,
"user":"user",
"password":"password",
"service":"orcl",
"schema":"PUBLIC"
}
}
...
]
#### MOST Web Framework SQLite Adapter for connecting with Sqlite Databases
Install the data adapter:
npm install most-data-sqlite
Append the adapter type in application configuration (app.json#adapterTypes):
...
"adapterTypes": [
...
{ "name":"SQLite Data Adapter", "invariantName": "sqlite", "type":"most-data-sqlite" }
...
]
Register an adapter in application configuration (app.json#adapters):
adapters: [
...
{ "name":"development", "invariantName":"sqlite", "default":true,
"options": {
database:"db/local.db"
}
}
...
]