Still in developpement

fysql is a small python ORM inpired by peewee.

Have fun

Definition of your tables.

from fysql import *

database = MySQLDatabase('db', host='localhost', user='x', passwd='x')

class User(Table):
    firstname = CharColumn(max_length=50)
    lastname  = CharColumn(max_length=50)
    role      = CharColumn(index=True, unique=True)


Creating your first User.

>>> user = User.create(firstname='Fy', lastname='SQL', role='Admin')
>>> print user
{"id": 1, "lastname": "SQL", "role": "Admin", "firstname": "Fy"}

Updating your User.

>>> user.role = 'Member'
>>> user.save()
>>> print user
{"id": 1, "lastname": "SQL", "role": "Member", "firstname": "Fy"}

Selecting one User.

>>> user = User.get(User.id==1)
>>> print user
{"id": 1, "lastname": "SQL", "role": "Admin", "firstname": "Fy"}

Adding new users and selecting members.

>>> User.create(firstname='Jean', lastname='Bon', role='Member')
>>> User.create(firstname='Jean', lastname='Rhume', role='Admin')
>>> users = User.filter(User.role=='Member').all()
>>> print users
[{"id": 1, "lastname": "SQL", "role": "Member", "firstname": "Fy"}, {"id": 2, "lastname": "Bon", "role": "Member", "firstname": "Jean"}]

Counting users.

>>> count_users = User.count_filter(User.role <<< ['Member', 'Admin'])
>>> print count_users