一个ORM接口,它将自己塑造成你的数据。
plastic的Python项目详细描述
塑性变形
一种将自身塑造为数据的ORM
目前正在进行beta验证。SQLite是初始测试。
请参阅dev/
目录以了解用法示例。在
快速启动
以下是从SQLite数据库文件中获取一些数据的快速方法:
from plastic.connectors.sqlite import PlasticSqlite
PlasticSqlite._dbInfo = './dev/sqlite-test.db'
class Task(PlasticSqlite): pass
print(Task.find(Task.id[3:]))
# [task(id=4,active=0,title='Uninteresting',description='Not much to say here.'),
# task(id=5,active=1,title='Very important',description=None)]
要更改记录,可以这样设置:
^{pr2}$Note: To avoid the need to call
_commit()
, set_autocommit=True
. This can be done at the object or class level. Also note that for SQLite a commit means the database file is updated!
表的任何列都可以作为属性引用,也可以用作筛选器。 例如,要查找仍处于活动状态的任务:
print({task.title: task.description
for task
in Task.find(Task.active[0])})
# {'Skipped': None, 'A bit more interesting': 'Not much to say here.'}
通过实例化而不使用绑定键添加项:
newTask = Task()
newTask.title = "A new task to do"
newTask.active = True
newTask._commit()
print(Task.find(Task.id[5:])) # get tasks after the last added
# [task(id=6,active=1,title='A new task to do',description=None)]
尚不支持删除not。这不难,但需要有某种连锁。在
- 项目
标签: