Python数据库操作Orator-orm
发布日期:2021-07-01 06:08:27
浏览次数:3
分类:技术文章
本文共 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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
初次前来,多多关照!
[***.217.46.12]2024年04月29日 10时05分32秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
TestNG 学习总结 - 忽略测试(八)
2021-07-06
TestNG 学习总结 - 测试结果报告(十四)
2021-07-06
Java对象深复制、浅复制
2019-05-03
细分自动化测试
2019-05-03
使用WebDriver完成web页面切换操作(附源码)
2019-05-03
山东科技大学2015-2016学年第一学期程序设计基础期末考试第一场 题解
2019-05-03
蓝桥杯题解(三)
2019-05-03
Scala学习第十二天 Scala中的继承:超类的构造、重写字段、重写方法代码实战
2019-05-03
剑指offer:字符串的组合(java)
2019-05-03
实时开发框架Meteor API解读系列<二>Core
2019-05-03
实时开发框架Meteor 实际应用系列<一>---文件的上传和下载[补充]
2019-05-03
启用fcitx-qimpanel面板程序
2019-05-03
浅谈Q的基本实现
2019-05-03
阿里云短信服务(JAVA)
2019-05-03
GCD使用 串行并行队列 与 同步异步执行的各种组合 及要点分析
2019-05-03
深入研究 Runloop 与线程保活
2019-05-03
iOS 版本更新(强制更新)检测问题
2019-05-03
Struts2(1)简介
2019-05-03
XSS漏洞解析(一)
2019-05-03