formalize
Version:
Node.js NoSQL ActiveRecord ORM layer for FoundationDB
70 lines (54 loc) • 1.74 kB
text/coffeescript
_ = require('underscore')
async = require('async')
ActiveFactory = require('../active/factory')
{EventEmitter} = require('events')
path = require('path')
config = null
testDir = (dir) ->
fileName = path.join(dir, 'formalize')
try
require(fileName) || require(fileName + '.json')
catch e
getConfig = (dbType) ->
if (config is null)
for dir in [path.dirname(require.main.filename), process.cwd()]
config = testDir(dir)
return config[dbType] if (config)
### Abstract Provider class
{String} dbName Database name.
{String} dbType Database system type.
###
module.exports = class Provider extends EventEmitter
constructor: ( , ) ->
= 'disconnected'
= null
= ActiveFactory.createRecord
= ActiveFactory.createIndex
= ActiveFactory.createCounter
_configure: (callback) ->
= getConfig( )
activeRecordConfigs = _.pairs( [ ])
createActiveRecord = (pair, cb) =>
TypedActiveRecord =
TypedActiveRecord.init (Extension) ->
cb(null, Extension)
mapCallback = (err, results) ->
if (err)
console.error(err)
else
callback()
async.map(activeRecordConfigs, createActiveRecord, mapCallback)
connect: (options) ->
switch
when 'connected' then
when 'disconnected'
= 'connecting'
callback = (db) =>
= 'connected'
= db
=>
@
init: (options, callback) ->
throw new Error('not implemented')