1 Star 0 Fork 229

hello-tom/project_25500701

forked from mktime/python-learn 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
orm.py 683 Bytes
一键复制 编辑 原始数据 按行查看 历史
unknown 提交于 2015-04-05 15:40 . use sqlalchemy learning
from sqlalchemy import *
from sqlalchemy.orm import *
class user(object):
def __init__(self, name, age, passwd):
self.name = name
self.age = age
self.passwd = passwd
db = create_engine('sqlite:///test.db')
metadata = MetaData(db)
metadata.create_all(checkfirst=True)
users = Table('users', metadata,
Column('user_id', Integer, primary_key=True),
Column('name', String(40)),
Column('age', Integer),
Column('passwd', String)
)
users.create(checkfirst=True)
mapper(user, users)
Session = sessionmaker(bind=db)
session = Session()
item = user('Faker', 25, 'passwd')
session.add(item)
session.commit()
u = session.query(user).filter_by(age=25).first()
print u.age
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/hello-tom/python-learn.git
git@gitee.com:hello-tom/python-learn.git
hello-tom
python-learn
project_25500701
master

搜索帮助