pydent.interfaces.QueryInterface¶
-
class
pydent.interfaces.
QueryInterface
(model_name, aqhttp, session)[source]¶ Bases:
pydent.interfaces.SessionInterface
,pydent.interfaces.QueryInterfaceABC
Makes requests using AqHTTP that are model specific.
Establishes a connection between a session object and an Aquarium model.
Instantiates a new model interface. Uses aqhttp to make requests, and deserializes response to models.
- Parameters
model_name (basestring) – Model name (e.g. ‘Sample’ or ‘FieldValue’)
aqhttp (AqHTTP) – the AqHTTP instance
session –
-
__init__
(model_name, aqhttp, session)[source]¶ Instantiates a new model interface. Uses aqhttp to make requests, and deserializes response to models.
- Parameters
model_name (basestring) – Model name (e.g. ‘Sample’ or ‘FieldValue’)
aqhttp (AqHTTP) – the AqHTTP instance
session –
Methods
__init__
(model_name, aqhttp, session)Instantiates a new model interface.
all
([methods, include, opts])Finds all models.
array_query
(method, args[, rest, include, opts])Finds models based on a query.
find
(model_id[, include, opts])Finds model by id.
find_by_name
(name[, include, opts])Finds model by name.
first
([num, query, include, opts])Find the first added models.
get
(path)Makes a generic get request.
last
([num, query, include, opts])Find the last added models.
load
(post_response)Loads model instance(s) from data.
new
(*args, **kwargs)Creates a new model instance.
one
([query, first, include, opts])Return one model.
where
(criteria[, methods, include, …])Performs a query for models.
Attributes
DEFAULT_LIMIT
DEFAULT_OFFSET
DEFAULT_REVERSE
MERGE
aqhttp
model
Alias for self.model.__name__
session
-
_post_json
(data)[source]¶ Posts a json request to session for this interface.
Attaches raw json and this session instance to the models it retrieves.
-
all
(methods=None, include=None, opts=None)[source]¶ Finds all models.
- Parameters
methods (
Optional
[List
[str
]]) –include –
opts (dict) – additional options (“offset”, “limit”, “reverse”, etc.)
- Returns
- Return type
-
array_query
(method, args, rest=None, include=None, opts=None)[source]¶ Finds models based on a query.
-
first
(num=None, query=None, include=None, opts=None)[source]¶ Find the first added models.
- Parameters
num (int) – number of models to return. If not provided, assumes 1
query (dict) – additional query to find models
include –
opts (dict) – additional options (“offset”, “limit”, “reverse”, etc.)
- Returns
list of models
- Return type
list
-
last
(num=None, query=None, include=None, opts=None)[source]¶ Find the last added models.
- Parameters
num (int) – number of models to return. If not provided, assumes 1
query (dict) – additional query to find models
opts (dict) – additional options (“offset”, “limit”, “reverse”, etc.)
- Returns
list of models
- Return type
list
-
load
(post_response)[source]¶ Loads model instance(s) from data.
Model instances will be of class defined by self.model. If data is a list, will return a list of model instances.
-
property
model_name
¶ Alias for self.model.__name__
-
new
(*args, **kwargs)[source]¶ Creates a new model instance.
Attach a session by calling __new__ with session kwargs.
-
one
(query=None, first=False, include=None, opts=None)[source]¶ Return one model. Returns the last model by default. Returns None if no model is found.
- Parameters
first (bool) – whether to return the first model (default: False
- Returns
model
- Return type
-
pagination
(query, page_size, methods=None, include=None, opts=None)[source]¶ Return pagination query (as a generator).
- Parameters
interface – SessionInterface
query (
dict
) – querypage_size (
int
) – number of models to return per pagelimit – total number of models to return
opts (
Optional
[dict
]) – additional options
- Return type
Generator
[list
,None
,None
]- Returns
generator of list of models
-
where
(criteria, methods=None, include=None, page_size=None, opts=None)[source]¶ Performs a query for models.
- Parameters
criteria (dict) – query to find models
methods (list) – server side methods to implement
opts (dict) – additional options (“offset”, “limit”, “reverse”, etc.)
include (
Optional
[List
[str
]]) –
- Returns
list of models
- Return type
list