Marguerite provides a declarative, consistent accessor to data layer.
Project description
Marguerite
Marguerite provides a declarative, consistent accessor to data layer.
Dependencies
Python 2.7 or later
Werkzeug 0.12.7 or later
Usage Flow.
define formater. ```python from marguerite import AbstractFormater, Order
class User(AbstractFormater): struct = { “id” : int(), “name” : str(), “email” : str(), }
orders = Order( user = “”” SELECT * FROM table WHERE id = :id “””,
users = """ SELECT * FROM __table__ WHERE id in (:ids) """
) ```
get data layer accessor object ```python from marguerite import Marguerite, AbstractAccessor from marguerite.accessors import bind
class Accessor(AbstractAccessor): def get(self, name, value={}): order = self.formater.get_order(name) return bind(order, value)
marguerite = Marguerite(None, Accessor) accessor = marguerite.get_accessor(“path.to.User”) ```
fetch data ```python # as dict result = accessor.get(“user”, { “id”: 1 }) print(result) # result “”” SELECT
FROM table WHERE id = 1 “””
as array
result = accessor.find(“users”, { “ids”: [1, 2] }) print(result) # result “”” SELECT * FROM table WHERE id in (1, 2) “”” ```
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.