Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
4aec47f207 | |||
c2e3a1ae6e | |||
3d8f8646b1 | |||
aca9817c56 |
25
README.md
25
README.md
@ -47,7 +47,7 @@ How RethinkDB's terms map to the ones of smartdata:
|
|||||||
|
|
||||||
represents a Database. Naturally it has .connect() etc. methods on it.
|
represents a Database. Naturally it has .connect() etc. methods on it.
|
||||||
|
|
||||||
```javascript
|
```typescript
|
||||||
import * as smartdata from "smartdata";
|
import * as smartdata from "smartdata";
|
||||||
|
|
||||||
let myRethinkDb1 = new smartdata.Db({
|
let myRethinkDb1 = new smartdata.Db({
|
||||||
@ -64,19 +64,18 @@ A collection is defined by the object class (that is extending smartdata.dbdoc)
|
|||||||
|
|
||||||
So to get to get access to a specific collection you document
|
So to get to get access to a specific collection you document
|
||||||
|
|
||||||
```javascript
|
```typescript
|
||||||
// continues from the block before...
|
// continues from the block before...
|
||||||
|
|
||||||
@Collection(myRethinkDb1)
|
@smartdata.Table(myRethinkDb1)
|
||||||
class MyObject extends smartdata.DbDoc<myObject> {
|
class MyObject extends smartdata.DbDoc<myObject> {
|
||||||
// read the next block about DbDoc
|
// read the next block about DbDoc
|
||||||
@smartdata.svDb() property1: string; // @smartdata.svDb() marks the property for db save
|
@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()
|
property2: number; // this one is not marked, so it won't be save upon calling this.save()
|
||||||
constructor(optionsArg: { property1: string, property2: number }) {
|
constructor(optionsArg: { property1: string; property2: number }) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let myCollection = myRethinkDb1.getCollectionByName < myObject > myObject;
|
|
||||||
|
|
||||||
// start to instantiate instances of classes from scratch or database
|
// start to instantiate instances of classes from scratch or database
|
||||||
|
|
||||||
@ -85,16 +84,20 @@ let localObject = new MyObject({
|
|||||||
property2: 2
|
property2: 2
|
||||||
});
|
});
|
||||||
localObject.save(); // saves the object to the database
|
localObject.save(); // saves the object to the database
|
||||||
```
|
|
||||||
|
|
||||||
> Alert: You NEVER instantiate a collection.
|
// start retrieving instances
|
||||||
> This is done for you!!!
|
|
||||||
|
MyObject.getInstance<MyObject>({
|
||||||
|
property: "hi"
|
||||||
|
}); // outputs a new instance of MyObject with the values from db assigned
|
||||||
|
```
|
||||||
|
|
||||||
### class DbDoc
|
### class DbDoc
|
||||||
|
|
||||||
represents a individual document in a collection
|
represents a individual document in a collection
|
||||||
and thereby is ideally suited to extend the class you want to actually store.
|
and thereby is ideally suited to extend the class you want to actually store.
|
||||||
|
|
||||||
|
**sStore** instances of classes to Db:
|
||||||
DbDoc extends your class with the following methods:
|
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.
|
* `.save()` will save (or update) the object you call it on only. Any referenced non-savable objects will not get stored.
|
||||||
@ -103,8 +106,10 @@ DbDoc extends your class with the following methods:
|
|||||||
that extends DbDoc as well and call .saveDeep() on them as well.
|
that extends DbDoc as well and call .saveDeep() on them as well.
|
||||||
Loops are prevented
|
Loops are prevented
|
||||||
|
|
||||||
So now we can **store** instances of classes to Db...
|
**Get** a new class instance from a Doc in the DB:
|
||||||
How do we **get** a new class instance from a Doc in the DB?
|
DbDoc exposes a static method that allows you specify a filter to retrieve a cloned class of the one you used to that doc at some point later in time. Yes, let that sink in a minute :)
|
||||||
|
|
||||||
|
So you can just call `.getInstance({ /* filter props here */ })`.
|
||||||
|
|
||||||
## TypeScript
|
## TypeScript
|
||||||
|
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "smartdata",
|
"name": "smartdata",
|
||||||
"version": "2.0.3",
|
"version": "2.0.5",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "smartdata",
|
"name": "smartdata",
|
||||||
"version": "2.0.3",
|
"version": "2.0.5",
|
||||||
"description": "do more with data",
|
"description": "do more with data",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
|
Reference in New Issue
Block a user