Python数据库操作Orator-orm
发布日期:2021-07-01 06:08:27
浏览次数:2
分类:技术文章
本文共 834 字,大约阅读时间需要 2 分钟。
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
3种查询方式 代码实现
# -*- coding: utf-8 -*-from orator import DatabaseManagerimport logging# 开启查询日志,打印sqllogging.basicConfig(level=logging.DEBUG)config = { 'mysql': { 'driver': 'mysql', 'host': 'localhost', 'database': 'data', 'user': 'root', 'password': '123456', 'prefix': '', 'log_queries': True }}db = DatabaseManager(config)# queryresults = db.select('select * from student where id = %s', [11])print(results)# query builderuser = db.table('student').first()print(user)# ormfrom orator import ModelModel.set_connection_resolver(db)class Student(Model): __table__ = 'student'user = Student.find(11)print(user.name)
转载地址:https://pengshiyu.blog.csdn.net/article/details/103430271 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
感谢大佬
[***.8.128.20]2024年04月28日 21时01分29秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
HttpClient高并发下性能优化-http连接池
2019-05-06
2019工作安排
2019-05-06
kalibr-ros安装
2019-05-06
分区域分析数据趋势并拟合曲面
2019-05-06
2020年规划
2019-05-06
hpe项目编译问题解决
2019-05-06
机器人开发计划
2019-05-06
两坐标系转换T,其中一系世界位姿,求另一系世界位姿
2019-05-06
opencv标定生成rt的解释
2019-05-06
相机内参单位描述
2019-05-06
【原创】保险_Detective_ALong_新浪博客
2019-05-06