Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DatastoreOperations<T>

This class contains some lower-level abstractions for the LevelDB.

Usage

You should not instantiate this class, consider using Datastore instead. After that, you can access this class through datastore.methods.

Type parameters

Hierarchy

  • DatastoreOperations

Index

Constructors

constructor

  • new DatastoreOperations(db: function, store: LevelUp<EncodingDown<string, any>>, type: function): DatastoreOperations

Properties

Private _store

_store: function

The Datastore object that is parent of this object.

Type declaration

store

store: LevelUp<EncodingDown<string, any>>

LevelDB database object.

Private type

type: function

Type of an object stored.

Type declaration

    • (): any
    • Returns any

Methods

Private convertToClass

  • convertToClass(item: object): T
  • Converts a plain object to a class object. Uses class-transformer.

    Parameters

    • item: object

      Item to convert to a class object.

    Returns T

    Object with type T.

Private convertToClassWithId

  • convertToClassWithId(item: object): T
  • Converts a plain object to a class object, while also setting its general parameters. Uses class-transformer.

    Parameters

    • item: object

      Item to convert to a class object and set its parameters.

    Returns T

    Object with type T.

Private convertToPlain

  • convertToPlain(item: T): any

count

  • Gets the number of items that match the filter and are in range of your pagination data (skip, take). If none of those arguments are passed, returns the total number of objects in the database.

    Parameters

    • Optional filter: FilterOperator<T>

      Filter object. Must be FilterOperator<T>.

    • Optional pagination: PaginationData

      Pagination object. Must be PaginationData.

    Returns Promise<number>

    The number of objects that match the filter and the pagination data.

createReadStream

  • Created a read stream on LevelDB database. onData callback will be called on each object, and it contains plain-object form of the object.

    Usage

    await this.createReadStream<T>(data => values.push(data))

    Returns ValueStream<T>

createReadStreamFiltered

delete

  • delete(id: string): Promise<void>

get

  • Gets all items that match the filter. Gets all of the items if no filter is given.

    Parameters

    • Optional filter: FilterOperator<T>

      Filter object. Must be FilterOperator<T>.

    Returns Promise<T[]>

    An array of objects that match the filter.

getOne

  • getOne(id: string): Promise<T>

getWithJustFields

  • Gets all items that match the filter. Gets all of the items if no filter is given. Returned items are not converted to a class object - they are still in a plain object form. This method is faster than get().

    Parameters

    • Optional filter: FilterOperator<T>

      Filter object. Must be FilterOperator<T>.

    Returns Promise<IObjectFields<T>[]>

    An array of plain objects that match the filter.

paginate

push

  • push(item: T): Promise<T>

put

  • put(id: string, item: T): Promise<T>
  • Updates an item in the database.

    Parameters

    • id: string

      Identifier of an object. Same as item.meta.id.

    • item: T

      New data of the object.

    Returns Promise<T>

    The object with updated data.

setCreatedTime

  • setCreatedTime(item: T): void

Private setData

  • setData(item: T, id: string): void
  • Sets general parameters of an object, such as meta.id and store.

    Parameters

    • item: T

      Item to set parameters to.

    • id: string

      Identifier of an object.

    Returns void

setPushData

  • setPushData(id: string, item: T): void
  • Sets general parameters of an object when pushing, such as meta.id and store, also meta.created and meta.updated.

    Parameters

    • id: string

      Identifier of an object.

    • item: T

      Item to set parameters to.

    Returns void

setUpdatedTime

  • setUpdatedTime(item: T): void

sort

Generated using TypeDoc