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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Python多层装饰器执行顺序
下一篇:Lua快速入门

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年04月28日 21时01分29秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章