Skip to content

CLI | cli_api

ewolio edited this page Feb 21, 2020 · 5 revisions

The cli_api library allows managing of the database by adding, updating, deleting entries, by displaying its content and by providing higher-level functionalities (automatic tasks creation, ...).

To every table in the database correspond an EntityTable in the cli_api. Those different tables are stored in the cli_api.cli object. Even though their classes are different (UserTable, ImageTable...), all of them inherit the same class EntityTable. This class defines common functionalities, mainly requesting data to the server and parsing them into Entity or EntityList.

Entity Table

Overview

Members Documentation

EntityTable Attributes

  • __entity__: The class inheriting Entity managed by this table.

EntityTable Methods

  • getById(id)

    Retrieve one or some entities from the database's table. Note that table.getById(id) is similar to table[id].

    Parameters:
    • id [int|list|tuple|set]: One primary key or a list of primaries keys corresponding to the entities to retrieve.
    Return:

    If id is a primary key then returns the corresponding entity parsed as an object of type __entity__. Else, if id was a list, returns an EntityList of the parsed entities.

  • save(entity)

    Save an entity to the database. Alternatively, you can use entity.save().

    Parameters:
    • entity [Entity]: The entity to save.
  • delete(entity)

    Delete an entity . Alternatively you can use del table[id] where id is the index in the database of the entity to delete.

    Parameters:
    • entity [Entity|int|list|tuple|set]: An entity to delete or its a primary key. A list of those is also accepted, in this case they will be deleted one after the other.

Inheriting EntityTable

Methods to override:

  • _getById(indexes)

  • _update(entity)

  • _update_multiples(entities)

  • _delete(id)

Useful decorators:

  • @cli_method

  • @format_entity(entity=None)

Entity

Overview

Entity automatically parses prototype from models of the server (e.g. ProtoImage or ProtoUser).

Members Documentation

Entity Attributes

Entity Methods

  • save()

    Save this entity to the database.

  • revert()

    Revert this entity to its state in the database.

  • delete()

    Delete this entity from the database.

  • to_json(str=False)

    Inherited from json_template.JSONClass.

    Export the entity to JSON format (compatible with Proto format of entities in the database).

Extending Entity functionnalities

The json_template module

Inheriting Entity

Methods to override:

  • table()

    A class method returning the table singleton corresponding to this entity.

Entity List

Overview

Members Documentation

EntityList Attributes

EntityList Methods

Clone this wiki locally