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

    0.3.63 • Public • Published

    logomakr_8lsyys

    npm Build Status Coverage Status PRs Welcome issues Welcome npm GitHub issues GitHub pull requests Downloads

    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

    Install

    npm i tarant-db-persist

    DownloadsWeekly Downloads

    2

    Version

    0.3.63

    License

    MIT

    Unpacked Size

    781 kB

    Total Files

    14

    Last publish

    Collaborators

    • kmruiz
    • kanekotic