Options
All
  • Public
  • Public/Protected
  • All
Menu

This represent a Database

Type parameters

  • S: object

    the database schema

  • E: BaseEntity<S>

    the Entity

  • V: string

    the (optional) view type that defines a list of possible view IDs

Hierarchy

  • SlothDatabase

Index

Constructors

constructor

Properties

Private _model

_model: EntityConstructor<S, E>
type

{T}

memberof

SlothDatabase

Private _name

_name: string
type

{string}

memberof

SlothDatabase

_root

_root: string

Private Optional _setupPromise

_setupPromise: Promise<any>

Private _subscribers

_subscribers: object[] = []

Methods

cancel

  • Unsubscribe a subscriber, so it will not be called anymore Possibly cancel PouchDB changes

    Parameters

    • factory: PouchFactory<S>

      The pouchDB factory to unsubscribe from

    • sub: Subscriber<S>

      the subscriber to unsubscribe

    Returns void

create

  • Create a new model instance

    Parameters

    • factory: PouchFactory<S>

      The database factory to attach to the model

    • props: Partial<S>

      the entity properties

    Returns E

    an entity instance

Protected dispatch

findAllDocs

  • findAllDocs(factory: PouchFactory<S>, startKey?: string, endKey?: string): Promise<E[]>
  • Fetches all documents for this database and map them with the model

    see

    PouchDB#allDocs

    memberof

    SlothDatabase

    Parameters

    • factory: PouchFactory<S>

      the PouchDB factory to use

    • Default value startKey: string = this._root || ''
    • Default value endKey: string = join(startKey, '\uffff')

    Returns Promise<E[]>

    a promise that resolves into an array of entity instances

findAllIDs

  • findAllIDs(factory: PouchFactory<S>, startKey?: string, endKey?: string): Promise<string[]>
  • Fetches all documents IDs for this database and return them

    see

    PouchDB#allDocs

    memberof

    SlothDatabase

    Parameters

    • factory: PouchFactory<S>

      the PouchDB factory to use

    • Default value startKey: string = this._root || ''
    • Default value endKey: string = join(startKey, '\uffff')

    Returns Promise<string[]>

    a promise that resolves into an array of string IDs

findById

  • findById(factory: PouchFactory<S>, id: string): Promise<E>
  • Fetch a docuemt from the database

    Parameters

    • factory: PouchFactory<S>

      the PouchDB factory to use

    • id: string

      the document identifier to fetch

    Returns Promise<E>

    a promise resolving with the entity instance

Protected getSubscriberFor

  • getSubscriberFor(factory: PouchFactory<S>): undefined | object

initSetup

put

  • put(factory: PouchFactory<S>, props: Partial<S>): Promise<E>
  • Create a new model instance and save it to database

    Parameters

    • factory: PouchFactory<S>

      The database factory to attach to the model

    • props: Partial<S>

      the entity properties

    Returns Promise<E>

    an entity instance

query

  • query(factory: PouchFactory<S>, view: V, startKey?: string, endKey?: string, includeDocs?: boolean): Promise<Response<S>>
  • Run a query

    Parameters

    • factory: PouchFactory<S>

      the pouch factory

    • view: V

      the view identifier

    • Default value startKey: string = ""

      the optional startkey

    • Default value endKey: string = join(startKey, '\uffff')

      the optional endkey

    • Default value includeDocs: boolean = false

      include_docs

    Returns Promise<Response<S>>

queryDocs

  • queryDocs(factory: PouchFactory<S>, view: V, startKey?: string, endKey?: string): Promise<E[]>
  • Queries and maps docs to Entity objects

    Parameters

    • factory: PouchFactory<S>

      the pouch factory

    • view: V

      the view identifier

    • Default value startKey: string = ""

      the optional startkey

    • Default value endKey: string = join(startKey, '\uffff')

      the optional endkey

    Returns Promise<E[]>

queryKeys

  • queryKeys(factory: PouchFactory<S>, view: V, startKey?: string, endKey?: string): Promise<string[]>
  • Queries keys. Returns an array of emitted keys

    Parameters

    • factory: PouchFactory<S>

      the pouch factory

    • view: V

      the view identifier

    • Default value startKey: string = ""

      the optional startkey

    • Default value endKey: string = join(startKey, '\uffff')

      the optional endkey

    Returns Promise<string[]>

queryKeysIDs

  • queryKeysIDs(factory: PouchFactory<S>, view: V, startKey?: string, endKey?: string): Promise<Dict<string>>
  • Queries keys/_id map. Returns a map of emitted keys/ID

    Parameters

    • factory: PouchFactory<S>

      the pouch factory

    • view: V

      the view identifier

    • Default value startKey: string = ""

      the optional startkey

    • Default value endKey: string = join(startKey, '\uffff')

      the optional endkey

    Returns Promise<Dict<string>>

Private setupViews

subscribe

withRoot

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc