一个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。这不难,但需要有某种连锁。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何设置apache camel groovy脚本组件的属性   java理解如何在if语句条件内创建对象   java使用访问者和复合模式构建过滤流   游戏框架上的java生成管理区(CRUD)   是java中的toString()方法。util。日期与地区无关?   java是否可以扩展AppIUMFieldCorator类以使其接受自定义注释?   内存管理java jvm最大和最小堆选项   JavaSpringMVC:正确的异常处理   java保存拖放图像按钮的位置   java如何使用replaceAll()替换算术(即0+1)   java获取方法调用方的方法名   java在JOptionPane输出上打印一行中的10组素数   java Spring/Hibernate如何访问私有成员?   java单例EJB在EJB容器外部的行为应该相同,但不相同   多线程处理一个“不可能”的null返回使用Java IO读取文件   java如何从axis web服务返回复杂对象   java ImageView在安卓中不起作用   java如何在安卓中使用带正则表达式的SpannableString?