Python数据库操作Orator-orm
【摘要】 It is inspired by the database part of the Laravel framework, but largely modified to be more pythonic.
参考 PHP排名第一的web框架 Laravel framework
https://orator-orm.com/
pip install orator
...
It is inspired by the database part of the Laravel framework, but largely modified to be more pythonic.
参考 PHP排名第一的web框架 Laravel framework
pip install orator
- 1
3种查询方式 代码实现
# -*- coding: utf-8 -*-
from orator import DatabaseManager
import logging
# 开启查询日志,打印sql
logging.basicConfig(level=logging.DEBUG)
config = { 'mysql': { 'driver': 'mysql', 'host': 'localhost', 'database': 'data', 'user': 'root', 'password': '123456', 'prefix': '', 'log_queries': True }
}
db = DatabaseManager(config)
# query
results = db.select('select * from student where id = %s', [11])
print(results)
# query builder
user = db.table('student').first()
print(user)
# orm
from orator import Model
Model.set_connection_resolver(db)
class Student(Model): __table__ = 'student'
user = Student.find(11)
print(user.name)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
文章来源: pengshiyu.blog.csdn.net,作者:彭世瑜,版权归原作者所有,如需转载,请联系作者。
原文链接:pengshiyu.blog.csdn.net/article/details/103430271
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)