tarant-db-persist
TypeScript icon, indicating that this package has built-in type declarations

0.3.109 • Public • Published

tarant-db

Downloads npm npm GitHub Workflow Status All Contributors Maintainability Test Coverage PRs Welcome issues Welcome GitHub issues GitHub pull requests

Motivation

Provide the capabilities to actors on the backend to be persisted using waterline adapters.

Installation

add it to your project using npm install tarant-db-persist --save or yarn add tarant-db-persist

Usage

Initialize the sync client with the waterline adapter from the persist storage you will be interested on

import { ActorSystem, ActorSystemConfigurationBuilder } from 'tarant';
import * as diskAdapter from 'sails-disk';
import { PersistResolverMaterializer } from 'tarant-db-persist';
import AppActor from '../AppActor';

const config = {
    adapter: {
        type: diskAdapter,
        settings: {
          inMemoryOnly: true
        },
      },
      actorTypes: { AppActor }
  };

const persister = await PersistMaterializer.create(config)

const system : any = ActorSystem.for(ActorSystemConfigurationBuilder.define()
    .withMaterializers([persister])
    .withResolvers([persister])
    .done())  

your actors will require to implement IUpdatable (UpdateFrom) and IExportable (toJson)

import { Actor } from "tarant";
import { IUpdatable, IExportable } from "tarant-db-persist"

export default class AppActor extends Actor implements IUpdatable, IExportable {

  constructor(name: string) {
      super(name)
  }

  addOne() {
      this.counter++
  }

  toJson(){
        return {
            id: this.id,
            type:"AppActor",
            counter: this.counter
        }
    }

    updateFrom({ counter }: any): void {
        this.counter = counter
    }

    private counter = 1; 
}
Created my free logo at LogoMakr.com

Dependents (0)

Package Sidebar

Install

npm i tarant-db-persist

Weekly Downloads

1

Version

0.3.109

License

MIT

Unpacked Size

14.5 kB

Total Files

8

Last publish

Collaborators

  • kmruiz
  • kanekotic