ormvana module¶
-
class
ormvana.
Model
(**kwargs)[source]¶ Base class for making models inherited from it.
Base class for making models inherited from it. Provides some basic functions for database object retrieval and manipulation. Also provides decorators which can be used for making custom object getters.
-
cnx
¶ SQL connection object – SQL connection object compliant with PEP-249.
-
close
()[source]¶ Close connection to the database. Call it only when you’re sure you’re not going to call save() or delete() on this object again.
-
classmethod
fetch_multiple
(func)[source]¶ Decorator to be used for making custom functions that retrieve multiple objects.
Parameters: func (function) – Function which returns a valid SQL query, for selecting records of the corresponding model. Returns: Decorated function which returns a list of objects according to the query made by the input func. Return type: function
-
classmethod
fetch_single
(func)[source]¶ Decorator to be used for making custom functions that retrieve single object.
Parameters: func (function) – Function which returns a valid SQL query, for selecting a record of the corresponding model. Returns: Decorated function which returns a single object according to the query made by the input func. Return type: function
-
classmethod
get
(id)[source]¶ Retrieve the object from the database having the given ID.
Parameters: id (int) – ID of the object to be retrieved. Returns: The object retrieved having the given ID. Return type: Model object
-
classmethod
get_all
()[source]¶ Retrieve all the objects of the given model.
Returns: List of objects of the given model. Return type: list of Model object
-
classmethod
get_by
(field, value)[source]¶ Retrieve records having the given value for the given field.
Parameters: - field (str) – The field name.
- value (int or str) – The value of the given field.
Returns: An object having the given value for the given field.
Return type: Model object
-
name
= ''¶ str – Name of the database table this Model corresponds to.
-
-
ormvana.
connection
()[source]¶ Function that provide the SQL connection to be uses by the ORM.
Returns: The first element of the tuple indicates whether the connection is to be closed after every query. The second element should provide an SQL connection object compliant with PEP-249. Return type: (bool, SQL connection object)
-
ormvana.
debug
= True¶ bool – Setting debug to True will make ormvana print each SQL query it’s about to execute.