• Jump To … +
    Nodulator.ls ClientDB.ls index.ls Resource.ls Bus.ls Cache.ls ChangeWatcher.ls Debug.ls Wrappers.ls Nodulator.ls Resource.ls Schema.ls NModule.ls AccountResource.ls User.ls index.ls Nodulator-Angular.ls TaskDirective.ls index.ls TaskService.ls main.ls index.ls index.ls Task.ls index.ls index.ls index.ls index.ls index.ls DOM.ls View.ls index.ls Nodulator.ls Mongo.ls Mysql.ls SqlMem.ls index.ls Resource.ls Request.ls Route.ls index.ls
  • Mongo.ls

  • ¶
    _ = require 'underscore'
    db = require('mongous').Mongous
    
    ids = {}
    
    module.exports = (config) ->
    
      class Mongo
    
        ->
          db().open config.host || 'localhost', config.port || 27017
    
          if config.user
            db(config.database + '.$cmd').auth config.user, config.pass, (res) ->
    
        Select: (table, fields, where, options, done) ->
    
          opts = {}
          if options.limit?
            opts.lim = options.limit
          if options.sortBy?
            rev = 1
            if options.sortBy.0 is \-
              options.sortBy = options.sortBy[1 to]*''
              rev = -1
            opts.sort = (options.sortBy): rev
    
          db(config.database + '.' + table).find where, {}, opts, (rows) ->
            done null, rows.documents
    
        Insert: (table, fields, done) ->
          db(config.database + '.' + table).insert fields
          done null, fields
    
        Update: (table, fields, where, done) ->
          db(config.database + '.' + table).update {id: fields.id}, fields
          done()
    
        Delete: (table, where, done) ->
          db(config.database + '.' + table).remove {id: where.id}
          done null, 1
    
        Drop: (table) ->
          db(config.database + '.$cmd').find({drop: table},1)
    
        _NextId: (name, done) ->
          db(config.database + '.' + name).find {}, {}, {sort: {id: -1}, lim: 1}, ->
            done null, +it.documents[0]?.id + 1 || 1
    
      new Mongo()
    
    module.exports.AddTable = (name, config, done) ->