Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DBObject

References an object stored in a specific model of your application. It provides the methods to get, update, delete an existing object identified by its id or create, set or append a new object.

If id is provided when creatign an instance, you can use get, update, delete and updateFields methods. If no id specified in constructor, you can use create, set, and append methods to create a new object in the database.

create method is used to creat a top-level object, which does not have any parent. set method is used to set the value of an object field of a parent object and finally append is used to add a child object to an object-list field of a parent object.

Since both set and append operate on a sub-model or sub-model list object respectively, you need to pass a parentId as an input parameter.

export

Hierarchy

Index

Constructors

  • Creates an instance of DBObject

    Parameters

    • modelName: string

      The name of the model that this query builder will be operating on

    • fetcher: Fetcher

      The http client to make RESTful API calls to the application's execution engine

    • Optional id: string

      The unique identifier of the dbobject

    Returns DBObject

Properties

#id: undefined | string

The unique identifier of the db object

#modelName: string

The name of the model that the db object will be operating on

fetcher: Fetcher

The http client to make RESTful API calls to the application's execution engine

Methods

  • append(values: object, parentId: string, options?: AppendOptions): Promise<{ data: null | object; errors: null | APIError }>
  • Appends the input object to the object list field of a parent object identified by parentId. This method is valid only for sub-model object-lists, object-lists with a parent. If this method is called for a top-level model object or sub-model object, an error will be returned.

    If the id is provided as input to this DBObject, its value will be ignored by this method since Altogic will automatically assign an id for new objects created in the database.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Parameters

    • values: object

      An object that contains the fields and their values to create in the database

    • parentId: string

      the id of the parent object.

    • Optional options: AppendOptions

      Create operation options. By default no caching of the newly created object in Redis store and no top level object return

    Returns Promise<{ data: null | object; errors: null | APIError }>

    Returns the newly create object in the database.

  • create(values: object, options?: CreateOptions): Promise<{ data: null | object; errors: null | APIError }>
  • Creates a top level model object in the database. This method is valid only for top-level models, models without a parent. If this method is called for a sub-model object or object-list, an error will be returned.

    If the id is provided as input to this DBObject, its value will be ignored by this method since Altogic will automatically assign an id for new objects created in the database.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Parameters

    • values: object

      An object that contains the fields and their values to create in the database

    • Optional options: CreateOptions

      Create operation options. By default no caching of the newly created object in Redis store.

    Returns Promise<{ data: null | object; errors: null | APIError }>

    Returns the newly create object in the database.

  • Deletes the document referred to by this DBObject and identified by the id. For a top level model object this method deletes the object from the database and for sub-model objects either unsets its value or removes it from its parent's object list. If the id of the db object is not defined, it returns an error.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Parameters

    • Optional options: DeleteOptions

      Delete operation options. By default removes deleted object from Redis cache (if cached already) and no top level object return.

    Returns Promise<{ data: null | object; errors: null | APIError }>

    Returns null if the deleted object is a top-level object. If the deleted object is a sub-model object and if returnTop is set to true in DeleteOptions, it returns the updated top-level object.

  • Gets the object referred to by this db object and identified by the id from the database. If the id of the db object is not specified, it returns an error.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Parameters

    • Optional options: GetOptions

      Get operation options. By default no caching of the retrieved object in Redis store.

    Returns Promise<{ data: null | object; errors: null | APIError }>

    Returns the object identified by the id or null if no such object exists in the database

  • Gets the object referred to by this db object and identified by the id from the database. While getting the object it also performs the specified lookups. If the id of the db object is not specified, it returns an error.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Parameters

    • lookups: [SimpleLookup | ComplexLookup]

      The list of lookups to make (left outer join) while getting the object from the database

    • Optional options: GetOptions

      Get operation options. By default no caching of the retrieved object in Redis store.

    Returns Promise<{ data: null | object; errors: null | APIError }>

    Returns the object identified by the id or null if no such object exists in the database

  • set(values: object, parentId: string, options?: SetOptions): Promise<{ data: null | object; errors: null | APIError }>
  • Sets the object field value of a parent object identified by parentId. This method is valid only for sub-model objects, objects with a parent. If this method is called for a top-level model object or sub-model object-list, an error will be returned.

    If the id is provided as input to this DBObject, its value will be ignored by this method since Altogic will automatically assign an id for new objects created in the database.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Parameters

    • values: object

      An object that contains the fields and their values to create in the database

    • parentId: string

      the id of the parent object.

    • Optional options: SetOptions

      Create operation options. By default no caching of the newly created object in Redis store and no top level object return

    Returns Promise<{ data: null | object; errors: null | APIError }>

    Returns the newly create object in the database.

  • update(values: object, options?: UpdateOptions): Promise<{ data: null | object; errors: null | APIError }>
  • Updates the object referred to by this db object and identified by the id using the input values. This method directly sets the field values of the object in the database with the values provided in the input.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Parameters

    • values: object

      An object that contains the fields and their values to update in the database

    • Optional options: UpdateOptions

      Update operation options. By default no caching of the updated object in Redis store and no top level object return

    Returns Promise<{ data: null | object; errors: null | APIError }>

    Returns the updated object in the database. If returnTop is set to true in UpdateOptions and if the updated object is a sub-model or sub-model-list object, it returns the updated top-level object.

  • Updates the fields of object referred to by this db object and identified by the id using the input FieldUpdate instruction(s).

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Parameters

    • fieldUpdates: FieldUpdate | [FieldUpdate]

      Field update instruction(s)

    • Optional options: UpdateOptions

      Update operation options. By default no caching of the updated object in Redis store and no top level object return

    Returns Promise<{ data: null | object; errors: null | APIError }>

    Returns the updated object in the database. If returnTop is set to true in UpdateOptions and if the updated object is a sub-model or sub-model-list object, it returns the updated top-level object.

Generated using TypeDoc