UNPKG

nodulator

Version:

Complete NodeJS Framework for Restfull APIs

310 lines (199 loc) 10.4 kB
<!DOCTYPE html> <html> <head> <title>Mongo.ls</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <ul id="jump_to"> <li> <a class="large" href="javascript:void(0);">Jump To &hellip;</a> <a class="small" href="javascript:void(0);">+</a> <div id="jump_wrapper"> <div id="jump_page_wrapper"> <div id="jump_page"> <a class="source" href="Nodulator.html"> Nodulator.ls </a> <a class="source" href="ClientDB.html"> ClientDB.ls </a> <a class="source" href="index.html"> index.ls </a> <a class="source" href="Resource.html"> Resource.ls </a> <a class="source" href="Bus.html"> Bus.ls </a> <a class="source" href="Cache.html"> Cache.ls </a> <a class="source" href="ChangeWatcher.html"> ChangeWatcher.ls </a> <a class="source" href="Debug.html"> Debug.ls </a> <a class="source" href="Wrappers.html"> Wrappers.ls </a> <a class="source" href="Nodulator.html"> Nodulator.ls </a> <a class="source" href="Resource.html"> Resource.ls </a> <a class="source" href="Schema.html"> Schema.ls </a> <a class="source" href="NModule.html"> NModule.ls </a> <a class="source" href="AccountResource.html"> AccountResource.ls </a> <a class="source" href="User.html"> User.ls </a> <a class="source" href="index.html"> index.ls </a> <a class="source" href="Nodulator-Angular.html"> Nodulator-Angular.ls </a> <a class="source" href="TaskDirective.html"> TaskDirective.ls </a> <a class="source" href="index.html"> index.ls </a> <a class="source" href="TaskService.html"> TaskService.ls </a> <a class="source" href="main.html"> main.ls </a> <a class="source" href="index.html"> index.ls </a> <a class="source" href="index.html"> index.ls </a> <a class="source" href="Task.html"> Task.ls </a> <a class="source" href="index.html"> index.ls </a> <a class="source" href="index.html"> index.ls </a> <a class="source" href="index.html"> index.ls </a> <a class="source" href="index.html"> index.ls </a> <a class="source" href="index.html"> index.ls </a> <a class="source" href="DOM.html"> DOM.ls </a> <a class="source" href="View.html"> View.ls </a> <a class="source" href="index.html"> index.ls </a> <a class="source" href="Nodulator.html"> Nodulator.ls </a> <a class="source" href="Mongo.html"> Mongo.ls </a> <a class="source" href="Mysql.html"> Mysql.ls </a> <a class="source" href="SqlMem.html"> SqlMem.ls </a> <a class="source" href="index.html"> index.ls </a> <a class="source" href="Resource.html"> Resource.ls </a> <a class="source" href="Request.html"> Request.ls </a> <a class="source" href="Route.html"> Route.ls </a> <a class="source" href="index.html"> index.ls </a> </div> </div> </li> </ul> <ul class="sections"> <li id="title"> <div class="annotation"> <h1>Mongo.ls</h1> </div> </li> <li id="section-1"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-1">&#182;</a> </div> </div> <div class="content"><div class='highlight'><pre>_ = <span class="hljs-built_in">require</span> <span class="hljs-string">'underscore'</span> db = <span class="hljs-built_in">require</span>(<span class="hljs-string">'mongous'</span>).Mongous ids = {} <span class="hljs-built_in">module</span>.exports = <span class="hljs-function"><span class="hljs-params">(config)</span> -&gt;</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Mongo</span></span> -&gt; db().open config.host || <span class="hljs-string">'localhost'</span>, config.port || <span class="hljs-number">27017</span> <span class="hljs-keyword">if</span> config.user db(config.database + <span class="hljs-string">'.$cmd'</span>).auth config.user, config.pass, <span class="hljs-function"><span class="hljs-params">(res)</span> -&gt;</span> Select: <span class="hljs-function"><span class="hljs-params">(table, fields, where, options, done)</span> -&gt;</span> opts = {} <span class="hljs-keyword">if</span> options.limit? opts.lim = options.limit <span class="hljs-keyword">if</span> options.sortBy? rev = <span class="hljs-number">1</span> <span class="hljs-keyword">if</span> options.sortBy<span class="hljs-number">.0</span> <span class="hljs-keyword">is</span> \- options.sortBy = options.sortBy[<span class="hljs-number">1</span> to]*<span class="hljs-string">''</span> rev = <span class="hljs-number">-1</span> opts.sort = (options.sortBy): rev db(config.database + <span class="hljs-string">'.'</span> + table).find where, {}, opts, <span class="hljs-function"><span class="hljs-params">(rows)</span> -&gt;</span> done <span class="hljs-literal">null</span>, rows.documents Insert: <span class="hljs-function"><span class="hljs-params">(table, fields, done)</span> -&gt;</span> db(config.database + <span class="hljs-string">'.'</span> + table).insert fields done <span class="hljs-literal">null</span>, fields Update: <span class="hljs-function"><span class="hljs-params">(table, fields, where, done)</span> -&gt;</span> db(config.database + <span class="hljs-string">'.'</span> + table).update {id: fields.id}, fields done() Delete: <span class="hljs-function"><span class="hljs-params">(table, where, done)</span> -&gt;</span> db(config.database + <span class="hljs-string">'.'</span> + table).remove {id: where.id} done <span class="hljs-literal">null</span>, <span class="hljs-number">1</span> Drop: <span class="hljs-function"><span class="hljs-params">(table)</span> -&gt;</span> db(config.database + <span class="hljs-string">'.$cmd'</span>).find({drop: table},<span class="hljs-number">1</span>) _NextId: <span class="hljs-function"><span class="hljs-params">(name, done)</span> -&gt;</span> db(config.database + <span class="hljs-string">'.'</span> + name).find {}, {}, {sort: {id: <span class="hljs-number">-1</span>}, lim: <span class="hljs-number">1</span>}, <span class="hljs-function">-&gt;</span> done <span class="hljs-literal">null</span>, +it.documents[<span class="hljs-number">0</span>]?.id + <span class="hljs-number">1</span> || <span class="hljs-number">1</span> <span class="hljs-keyword">new</span> Mongo() <span class="hljs-built_in">module</span>.exports.AddTable = <span class="hljs-function"><span class="hljs-params">(name, config, done)</span> -&gt;</span></pre></div></div> </li> </ul> </div> </body> </html>