jardin.Model¶
-
class
jardin.
Model
(**kwargs)¶ Base class from which your models should inherit.
-
collection_class
¶ alias of
Collection
-
destroy
(force=False)¶ Deletes the record. If the model has
soft_delete
activated, the record will not actually be deleted.Parameters: force (boolean) – forces the record to be actually deleted if soft_delete
is activated.
-
classmethod
find
(id, **kwargs)¶ Finds a record by its id in the model’s table in the replica database. :returns: an instance of the model.
-
classmethod
find_by
(values={}, **kwargs)¶ Returns a single record matching the criteria in
values
found in the model’s table in the replica database.Parameters: values (dict) – Criteria to find the record. Returns: an instance of the model.
-
classmethod
insert
(**kwargs)¶ Performs an INSERT statement on the model’s table in the master database.
Parameters: values (dict) – A dictionary containing the values to be inserted. datetime
,dict
andbool
objects can be passed as is and will be correctly serialized by psycopg2.
-
classmethod
last
(limit=1, **kwargs)¶ Returns the last limit records inserted in the model’s table in the replica database. Rows are sorted by
created_at
.
-
classmethod
query
(sql=None, filename=None, **kwargs)¶ run raw sql from sql or file against.
Parameters: - sql (string) – Raw SQL query to pass directly to the connection.
- filename (string) – Path to a file containing a SQL query. The path should be relative to CWD.
- db (string) – optional Database name from your
jardin_conf.py
, overrides the default database set in the model declaration. - role (string) – optional One of
('master', 'replica')
to override the default.
Returns: jardin.Collection
collection, which is apandas.DataFrame
.
-
classmethod
replica_lag
(**kwargs)¶ Returns the current replication lag in seconds between the master and replica databases.
Returns: float
-
classmethod
table_schema
()¶ Returns the table schema.
Returns: dict
-