UNPKG

lowkie

Version:

My Custom lowkie / Express Applcation

172 lines (126 loc) 5.69 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Home</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Home</h1> <h3> </h3> <section> <article><h1>Lowkie</h1><p><a href="https://travis-ci.org/typesettin/lowkie"><img src="https://travis-ci.org/typesettin/lowkie.svg?branch=master" alt="Build Status"></a> <a href="http://badge.fury.io/js/lowkie"><img src="https://badge.fury.io/js/lowkie.svg" alt="NPM version"></a> <a href="https://coveralls.io/github/typesettin/lowkie?branch=master"><img src="https://coveralls.io/repos/github/typesettin/lowkie/badge.svg?branch=master" alt="Coverage Status"></a> <a href="https://gitter.im/typesettin/lowkie?utm_source=badge&amp;utm_medium=badge&amp;utm_campaign=pr-badge&amp;utm_content=badge"><img src="https://badges.gitter.im/typesettin/lowkie.svg" alt="Join the chat at https://gitter.im/typesettin/lowkie"></a></p> <h3>Description</h3><p>Lowkie is a lokijs object modeling tool designed to work in an asynchronous environment.</p> <p style="text-align:center;"><img src="https://raw.githubusercontent.com/typesettin/lowkie/master/doc/lowkie.png" alt="Promisie Logo" width="300px" height="auto" style="margin:auto; text-align:center;"></p> <h3>Installation</h3><pre class="prettyprint source lang-sh"><code>$ npm i lowkie</code></pre><h3><a href="https://github.com/typesettin/lowkie/blob/master/doc/api.md">Full Documentation</a></h3><h3>Usage (basic)</h3><pre class="prettyprint source lang-javascript"><code>//lowkie singleton const lowkie = require('lowkie'); //connect to lowkie (includes loki connection configuration), options can include other loki adapters besides structured file adapters lowkie.connect(path.join(__dirname, './sampledb.json'),options) .then((db) => { console.log('connected db'); }) .catch(e => { console.log('connection error', e); }); //listen for connection errors lowkie.connection.on('connectionError', (e)=>{ console.log('error connecting to the db',e); }); //listen for connecting status, dbname is the path to the db json file lowkie.connection.on('connecting', (dbname, options)=>{ console.log('now trying to connect to db'); }); //once connected, create models, query the db, etc lowkie.connection.once('connected', (db, options)=>{ console.log('now connected to db'); //create a new schema const UserSchema = lowkie.Schema({ email:String, username:String, age:Number, }); //register db models, each model is a proxied loki collection with additional helpers const User = lowkie.model('User',UserSchema); //write data to db User.insert({ email:'test@domain.com', username:'testuser', age:30, invalidProp:'whatever', //removes invalid schema props on creates }) .then(newuser => { //created db /* { &quot;_id&quot;:&quot;fbd8080a9272ecaa15d1bb6d0f4b3314&quot;, &quot;email&quot;:&quot;test@domain.com&quot;, &quot;username&quot;:&quot;testuser&quot;, &quot;age&quot;:30, &quot;meta&quot;:{ &quot;revision&quot;:0, &quot;created&quot;:1490576236063, &quot;version&quot;:0 }, &quot;$loki&quot;:201 } */ console.log({ newuser }); }) .catch(e => { console.log(e); }); //insert multiple documents User.insert([ { email:'john@domain.com', username:'jsmith', age:37, }, { email:'jane@domain.com', username:'jdoe', age:45, }, { email:'chris@domain.com', username:'clane', age:17, }, ]) .then((newusers)=>{ console.log(newusers); }) .catch(e =>{ console.log(e); }) //query loki for data let userQueryResults = User.find({ id: { '$gte': 1 } }); console.log({userQueryResults}) //result of user query });</code></pre><h3>Development</h3><p><em>Make sure you have grunt installed</em></p> <pre class="prettyprint source lang-sh"><code>$ npm i -g grunt-cli jsdoc-to-markdown</code></pre><p>For generating documentation</p> <pre class="prettyprint source lang-sh"><code>$ grunt doc $ jsdoc2md lib/**/*.js index.js > doc/api.md</code></pre><h3>Notes</h3><ul> <li>Check out <a href="https://github.com/typesettin/lowkie">https://github.com/typesettin/lowkie</a> for the full Lowkie Documentation</li> </ul> <h3>Testing</h3><pre class="prettyprint source lang-sh"><code>$ npm i $ grunt test</code></pre><h3>Contributing</h3><h2>License</h2><p>MIT</p></article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="lowkie.html">lowkie</a></li><li><a href="lowkie.lowkie.html">lowkie</a></li><li><a href="lowkieSchema.html">lowkieSchema</a></li><li><a href="ObjectId.html">ObjectId</a></li></ul><h3>Global</h3><ul><li><a href="global.html#connect">connect</a></li><li><a href="global.html#handler">handler</a></li><li><a href="global.html#model">model</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Mar 27 2017 21:39:17 GMT-0400 (EDT) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>