数据库包装程序库

notanorm的Python项目详细描述


简单的库,使得在python中使用数据库更加方便。在

notanorm可以返回对象而不是行,保护您不被注入,并且 有一个非常简单的驱动程序接口。在

显然不是ORM,因为ORM通常是具有 常常混淆语义。在

示例:

from notanorm import SqliteDb 
from notanorm import MysqlDb 

fname = ":memory:"

# default options are 
db = SqliteDb(fname)

# no special create support, just use a string
db.query("create table foo (bar text, iv integer primary key)")

# insert, select, update, and upsert are convenient and do the right thing
# preventing injection, normalizing across db types, etc.

db.insert(bar="hi", iv=1)
db.insert(bar="hi", iv=2)
db.insert(bar="ho", iv=3)

db.upsert(bar="ho", iv=4)                   # primary keys are required for upserts

db.select("foo", bar="hi")[0].bar           # hi
db.select("foo", {"bar": "hi"})[0].iv       # 1

db.count("foo", bar="hi")                   # 2

class Foo:
    def __init__(self, bar=None, iv=None):
        self.bar = bar
        self.iv = iv

# create a class during select
db.register_class("foo", Foo)
obj = db.select_one("foo", bar="hi")
print(obj.bar)                              # hi

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

推荐PyPI第三方库


热门话题
在数据库中存储密码的java加密方法   java正则表达式否定整个正则表达式   java为什么要得到这个Hashmap输出?   看不到玻璃鱼爪哇SE 6   类对象包装器中的Java基本数据字段   java从文本文件中读取整数并存储到单独的变量中?(扫描仪)   优化大型Java数据阵列的处理和管理   如何使用Java XML包装类创建对象   java为ExecutorService invokeAll()创建包装器   java如何在Android Studio 1.0.0中设置Facebook SDK?获取SDK位置未找到错误   java在尝试从线程启动动画时调用了FromErrorThreadException   java根据哈希确认文件内容   通过java在neo4j中获取索引值相同的所有节点?   java为什么我的Validare邮政编码(布尔)程序返回false?   java会话自动从servlet/jsp生成,尽管存在以下条件:<%@page session=“false”%>   创建新LANsocket时拒绝java连接   java如何多线程更新由sql代码更新的数据库?   安卓 Java使用类作为集合来添加项   安卓为什么我的清单文件不声明java包?