3.2.1 • Published 8 months ago

dynamoose-polytree v3.2.1

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

Install

To install this Lib we need to install dynamoose npm install --save dynamoose

then install the lib npm i dynamoose-polytree

Using this Lib

Preparing Model

Extend exisiting Model file. Model already have string id no need to add one and it is already extending dynamoose Item model so it can still be used with regular dynamoose API.

//building.entity.ts
import { Model } from 'dynamoose-polytree';

export class Building extends Model {
	name: string;
	logo: JSON;
	// ...
}

Prepare Schema

Create a regular dynamoose schema, please refer to this documentation from dynamoose please set id and type of string as your hash key as this property will be used for tree.

Type to Schema Dictionary

Since to create a dynamoose model we need the table name and the schema, our lib need a dictionary to map those table name and schema. An example of those schema is here.

import { Schema } from 'dynamoose/dist/Schema';
export const TypeScheme: Record<string, Schema> = {
  Building: BuildingSchema,
  Site: SiteSchema,
  Amenity: AmenitySchema,
};

Create the repository

Extend the repository class from this lib, please make sure that the Table name is present in the type to schema dictionary.

import { Repository } from 'dynamoose-polytree';
import { TypeScheme } from './path/to/dictionary';
@Injectable() // decorator for nest.js usage
export class BuildingRepository extends Repository {
  constructor() {
    super(dynamoose.model('Building', BuildingSchema), TypeScheme);
  }
}

Repository has property called instance that holds dynamoose model that you can interact directly with. Please note that this instance is the model instance that is passed in super() method. example is

let result = await this.instsance.batchGet(arrayOfIds)

other than that example please refer to dynamoose implementation.

Using the repository

Current version of the repository only support vor v4 uuid for the entity id (partition key) that the value is automatically added by the repository.

There are a few methods that are available in this repository. Please note that you have to use given create method if you want to add the entity to the tree.

let result = await this.repository.create(createBuildingDto as Building);

other methods that are avilable are as follows

  • getInstance() // returns dynamoose model
  • create()
  • update()
  • get()
  • findRoots()
  • findTree() // find children
  • findRoot()
  • findParent()
  • findSiblings()
3.2.1

8 months ago

3.2.0

8 months ago

3.1.0

9 months ago

3.0.0

9 months ago

2.0.15

1 year ago

2.0.16

1 year ago

2.0.13

1 year ago

2.0.5

1 year ago

2.0.14

1 year ago

2.0.4

1 year ago

2.0.11

1 year ago

2.0.7

1 year ago

2.0.12

1 year ago

2.0.6

1 year ago

2.0.9

1 year ago

2.0.10

1 year ago

2.0.8

1 year ago

2.0.19

1 year ago

2.0.17

1 year ago

2.0.18

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.2.4

1 year ago

1.0.6

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago