ndx-mongo v0.3.19
ndx-mongo
mongo database connector for ndx-framework apps
Usage
npm install --save ndx-mongosrc/server/app.coffee
require 'ndx-server
dbEngine: require 'ndx-mongo'
mongoUrl: 'mongodb://192.168.99.100:27017/test'
tables: ['users', 'table1', 'table2']
.start()Environment variables
mongoUrl can be set with the environment variable MONGO_URL
Methods
db.select(string table, object whereObj, function callback)
Select data
db.insert(string table, object insertObj, function callback)
Insert data
db.update(string table, object updateObj, object whereObj, function callback)
Update data
db.upsert(string table, object upsertObj, object whereObj, function callback)
Upsert data
db.delete(string table, object whereObj, function callback)
Delete data
db.exec(string sql, array props, bool notCritical) -> data
Callbacks
ndx.database.on 'callbackName', (args, cb) ->
#do something with args
cb true #or false if you want to cancel the operationready
The database is ready to use
preInsert
args.tableThe database table being operated onargs.objThe object being inserted into the databaseargs.userThe user carrying out the operation
cb(false) to cancel the insert
insert
args.idThe inserted object's idargs.tableThe database table being operated onargs.objThe object that was inserted into the databaseargs.userThe user carrying out the operation
preUpdate
args.idThe id of the object being updatedargs.tableThe database table being operated onargs.whereThe database queryargs.objThe data to updateargs.oldObjThe value of the object preUpdateargs.changesThe changes to be appliedargs.userThe user carrying out the operation
cb(false) to cancel the update
update
args.idThe id of the object that was updatedargs.tableThe database table that was operated onargs.objThe data that was updatedargs.oldObjThe value of the object pre updateargs.newObjThe value of the object post updateargs.changesThe changes that were appliedargs.userThe user carrying out the operation
preSelect
args.tableThe database table being operated onargs.argsThe arguments that were passed to the select functionargs.userThe user carrying out the operation
cb(false) to cancel the select
select
args.tableThe database table being operated onargs.objsThe objects that were selected from the databaseargs.userThe user carrying out the operation
preDelete
args.tableThe database table being operated onargs.whereThe database queryargs.userThe user carrying out the operation
cb(false) to cancel the delete
delete
args.tableThe database table being operated onargs.userThe user carrying out the operation
callbacks can be used to modify data flowing to and from the database.
see ndx-permissions and ndx-profiler for examles
db.off(string callbackName, function callback) -> db
Unregister a callback
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago