Python数据库操作Orator-orm
It is inspired by the database part of the Laravel framework, but largely modified to be more pythonic.参考 PHP排名第一的web框架 Laravel frameworkhttps://orator-orm.com/pip install orator3种查询方式 代码实现# -*...
·
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 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)
更多推荐
已为社区贡献8条内容
所有评论(0)