https://github.com/repetere/lowkie
Lowkie is an ORM for LokiJS. LokiJS is a document oriented database written in javascript. LokiJS is used to store javascript objects as documents and follows familiar nosql paradigms to query and retrieve documents. Lowkie by default saves data to disk but for client-side usage, data persists in-memory or client side storage (e.g., a session store / localstorage)
https://github.com/repetere/lowkie
database javascript localstorage lokijs lokijs-collections lokijs-connector memcached
Last synced: about 1 year ago
JSON representation
Lowkie is an ORM for LokiJS. LokiJS is a document oriented database written in javascript. LokiJS is used to store javascript objects as documents and follows familiar nosql paradigms to query and retrieve documents. Lowkie by default saves data to disk but for client-side usage, data persists in-memory or client side storage (e.g., a session store / localstorage)
- Host: GitHub
- URL: https://github.com/repetere/lowkie
- Owner: repetere
- License: mit
- Created: 2017-03-11T01:51:40.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-12-02T21:28:48.000Z (over 6 years ago)
- Last Synced: 2025-04-22T14:07:22.322Z (about 1 year ago)
- Topics: database, javascript, localstorage, lokijs, lokijs-collections, lokijs-connector, memcached
- Language: JavaScript
- Homepage:
- Size: 4.24 MB
- Stars: 9
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Lowkie
[](https://travis-ci.org/typesettin/lowkie) [](http://badge.fury.io/js/lowkie) [](https://coveralls.io/github/typesettin/lowkie?branch=master) [](https://gitter.im/typesettin/lowkie?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
### Description
Lowkie is a lokijs object modeling tool designed to work in an asynchronous environment.

### Installation
```sh
$ npm i lowkie
```
### [Full Documentation](https://github.com/typesettin/lowkie/blob/master/doc/api.md)
### Usage (basic)
```javascript
//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
/*
{
"_id":"fbd8080a9272ecaa15d1bb6d0f4b3314",
"email":"test@domain.com",
"username":"testuser",
"age":30,
"meta":{
"revision":0,
"created":1490576236063,
"version":0
},
"$loki":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
});
```
### Development
*Make sure you have grunt installed*
```sh
$ npm i -g grunt-cli jsdoc-to-markdown
```
For generating documentation
```sh
$ grunt doc
$ jsdoc2md lib/**/*.js index.js > doc/api.md
```
### Notes
* Check out [https://github.com/typesettin/lowkie](https://github.com/typesettin/lowkie) for the full Lowkie Documentation
### Testing
```sh
$ npm i
$ grunt test
```
### Contributing
fork and create a pull request!

License
----
MIT