An advanced library for NoSQL data organization and manipulation using TypeScript with support for MongoDB, data validation, collections, and custom data types.
Go to file
2018-01-12 01:36:12 +01:00
dist feat(add RethinkDB as main driver and revert to docs in README): 2018-01-12 01:22:58 +01:00
docs update deps and docs 2018-01-07 17:43:02 +01:00
test feat(add RethinkDB as main driver and revert to docs in README): 2018-01-12 01:22:58 +01:00
ts feat(add RethinkDB as main driver and revert to docs in README): 2018-01-12 01:22:58 +01:00
.gitignore remove NeDB and update to use MongoDB Atlas for testing 2017-06-23 11:40:20 +02:00
.gitlab-ci.yml update ci 2018-01-12 01:33:54 +01:00
npmextra.json fix(CI): npmts now installing correctly during CI 2018-01-12 01:36:08 +01:00
package-lock.json 2.0.2 2018-01-12 01:36:12 +01:00
package.json 2.0.2 2018-01-12 01:36:12 +01:00
qenv.yml feat(add RethinkDB as main driver and revert to docs in README): 2018-01-12 01:22:58 +01:00
README.md feat(add RethinkDB as main driver and revert to docs in README): 2018-01-12 01:22:58 +01:00
tsconfig.json update ci 2017-06-18 19:52:54 +02:00
tslint.json add tests and gitlab ci 2016-09-11 16:22:53 +02:00
yarn.lock feat(add RethinkDB as main driver and revert to docs in README): 2018-01-12 01:22:58 +01:00

smartdata

do more with data and RethinkDB

Availabililty

npm git git docs

Status for master

build status coverage report npm downloads per month Dependency Status bitHound Dependencies bitHound Code Known Vulnerabilities TypeScript node JavaScript Style Guide

Usage

Use TypeScript for best in class instellisense.

smartdata is an ODM that adheres to TypeScript practices and uses classes to organize data. It uses RethinkDB as persistent storage.

Intention

There are many ODMs out there, however when we searched for an ODM that uses TypeScript, acts smart while still embracing the NoSQL idea we didn't find a matching solution. This is why we started smartdata.

How RethinkDB's terms map to the ones of smartdata:

RethinkDB term smartdata class
Database smartdata.Db
Table smartdata.DbTable
Document smartdata.DbDoc

class Db

represents a Database. Naturally it has .connect() etc. methods on it.

import * as smartdata from 'smartdata'

let myRethinkDb1 = new smartdata.Db({
  // rethinkDb connection options here
})

myDb1.connect()

class DbCollection

represents a collection of objects. A collection is defined by the object class (that is extending smartdata.dbdoc) it respresents

So to get to get access to a specific collection you document

// continues from the block before...

@Collection(myRethinkDb1)
class MyObject extends smartdata.DbDoc<myObject> { // read the next block about DbDoc
    @smartdata.svDb() property1: string // @smartdata.svDb() marks the property for db save
    property2: number // this one is not marked, so it won't be save upon calling this.save() 
    constructor(optionsArg:{
        property1: string,
        property2: number
    }) {
        super()
    }
}
let myCollection = myRethinkDb1.getCollectionByName<myObject>(myObject)

// start to instantiate instances of classes from scratch or database

let localObject = new MyObject({
    property1: 'hi',
    property2: 2
})
localObject.save() // saves the object to the database

Alert: You NEVER instantiate a collection. This is done for you!!!

class DbDoc

represents a individual document in a collection and thereby is ideally suited to extend the class you want to actually store.

DbDoc extends your class with the following methods:

  • .save() will save (or update) the object you call it on only. Any referenced non-savable objects will not get stored.
  • .saveDeep() does the same like .save(). In addition it will look for properties that reference an object that extends DbDoc as well and call .saveDeep() on them as well. Loops are prevented

So now we can store instances of classes to Db... How do we get a new class instance from a Doc in the DB?

TypeScript

How does TypeScript play into this? Since you define your classes in TypeScript and types flow through smartdata in a generic way you should get all the Intellisense and type checking you love when using smartdata. smartdata itself also bundles typings. So you don't need to install any additional types when importing smartdata.

For further information read the linked docs at the top of this README.

MIT licensed | © Lossless GmbH | By using this npm module you agree to our privacy policy

repo-footer