-
Notifications
You must be signed in to change notification settings - Fork 1
Home
When you face the need to persist your application model entities, you inevitably end up with persistence routines for the common Create, Read, Update and Delete (CRUD) type of operations. And before long you will realize that these are actually quite similar between different entities, i.e. they are very generic in nature if you start thinking in a little higher level abstractions such as types and identifiers, instead of concrete entities and properties. JavaScript happens to be very good at realizing this into application model. So, instead of copying the same routine for each entity, it's natural to abstract into a framework that can handle entities persistence into data records and back to entities in a generic way. That's what DAOism is about.
In a nutshell, DAOism knows how to handle the CRUD operations on an entity, plus some extras, based on a minimal configuration that you feed it to specify, which are the persistent entity properties and how they map to data records. You can also customize it on different levels to get your favorite style of DAOs.
DAOism is in fact a collection of modules that work together to provide you the maximum automation, but some (e.g. daoism/statements) are quite self contained and can be used standalone in different context too.
The daoism/dao module is the central module in DAOism. It uses the rest of the modules to expose a simplified interface for minimal input to you and provide you with a fully functional DAO.
Example: description
//create ORM var orm = { dbName: "TBL_A", properties: [ { name: "id", dbName: "A_ID", id: true, required: true, type: "Long" },{ name: "text", dbName: "A_TEXT", type: "String" } ] }; //Get a DAO for this ORM var dao = require('daoism/dao').get(orm); // CRUD an entity using the DAO var id = dao.insert({ shortText: "aaa" }); var entity = dao.find(id); var numberOfrecords = dao.count(); var entities = dao.list(); dao.update({ shortText: "bbb" }); dao.remove(id);
For full description of the capabilities of the module and reference how to use it refer to DAO wiki page
-
get()
Factory method for new DAO instances.
-
orm
Object(required) An object relation mapping configuration object.
-
logCtxName
String(optional) The name for the log/loggers/Logger instance that will be used by the DAO object produced by this factory method.
-
dataSource
DataSource object(optional) The DataSource object to use with this DAO instance. If none is supplied, the default DataSource is assumed.
Returns: a new DAO instance
Example:
var http = require("daoism/dao").get(orm);
-
-
DAO
The constructor function of the DAO class. The module exposes the class in case it is needed for extensions, for example for more specific handling of CRUD operations.
Example: New DAO instance (same as invoking
get
as described above)var DAO = require("daoism/dao").DAO; var dao = new DAO();
The daoism/orm module hosts the ORM class. Its role is to wrap a DAO configuration and inject utility functions such as getPrimaryKey()
or getProperty(name)
to enable easier use of the configuration and write maximum portable and refactoring-friendly code.
When a DAO class instance is created with an orm configuration as argument, its constructor will internally 'wrap' the configuration with the functionality from the ORM class, injecting its methods in the argument object. In this way, the ORM functions are indirectly available, via its DAO handler orm.
Example
//using the orm configuration form the example above var _orm = require('doaism/orm').get(orm); console.info('This ORM dbName is ' +_orm.dbName + ' and its entity id property name is '+_orm.getPrimaryKey().name);
For more extensive documentation and examples refer to the ORM wiki.
-
ORM
The constructor function of the ORM class.
-
get
Factory function for ORM instances.
-
orm
ObjectThe orm configuration that the produced ORM instance will wrap
-
The daoism/statements module purpose is to aid the construction and execution of sql statements. It hosts the StatementBuilder class that provides a fluent api to construct sql queries and the Statements class that can execute them.
Example
var statements = require('daoism/statements').get(); var stmnt = statements .builder() .select() .field(A_TEXT) .from('TBL_A') .where('A_TEXT LIKE ?', [{name:'text', dbName: 'A_TEXT', type: 'String'}]) .limit(10) .offset(0); var params = {}; params['text'] = "abc"; conn = ds.getConnection(); var rs; try{ rs = statements.execute(stmnt, conn, params); if(rs){ while(rs.next()){ console.info(rs.getString(1)); } } } finally{ if(rs) rs.close(); conn.close(); }
For more extensive documentation and examples refer to the Statements wiki.
-
Statements
The constructor function of the Statements class.
-
get
Factory function for Statements instances.
The module extedns daoism/statements with pre-build queries for the standard CRUD operations
Example How to test the example
For more extensive documentation and examples refer to the ORMStatements wiki.
-
ORMStatements
The constructor function of the ORMStatements class.
-
get
Factory function for ORMStatements instances.
Description.
Example How to test the example
For more extensive documentation and examples refer to the Dialects wiki.
-
Dialects
The constructor function of the Dialects class.
-
get
Factory function for Dialects instances.