python 使用Oracle数据库的Eve REST API
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 使用Oracle数据库的Eve REST API相关的知识,希望对你有一定的参考价值。
from eve_sqlalchemy.decorators import registerSchema
from sqlalchemy.ext.hybrid import hybrid_property
from eve_sqlalchemy import SQL
from eve_sqlalchemy.validation import ValidatorSQL
from eve import Eve
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import column_property
from sqlalchemy import ( ForeignKey, Column, String, Integer, Unicode, Float, Date )
from sqlalchemy.orm import relationship, backref
from sqlalchemy.dialects import oracle
Base = declarative_base()
class Tercero(Base):
__tablename__ = "forest_terceros"
__table_args__ = {"quote": False, "schema":"gis"}
numter = Column(Unicode, primary_key=True)
nomter = Column(Unicode)
@hybrid_property
def _id(self):
return self.numter
class Pregunta(Base):
__tablename__ = "ontrack_pregunta_valor_date"
__table_args__ = {"quote": False, "schema":"gis"}
idpregunta = Column(Integer, primary_key=True)
idformulario = Column(Integer)
idrespuesta = Column(Integer)
@hybrid_property
def _id(self):
return self.idpregunta
registerSchema('tercero')(Tercero)
registerSchema('pregunta')(Pregunta)
settings = {
'DEBUG': True,
'SQLALCHEMY_DATABASE_URI': 'oracle://xxxxx:xxxxxx@localhost/GIS',
'DOMAIN': {
'tercero': Tercero._eve_schema['tercero'],
'pregunta': Pregunta._eve_schema['pregunta']
}
#'ID_FIELD': 'id'
}
settings['DOMAIN']['pregunta'].update({
'item_title': 'pregunta',
'item_lookup_field': 'id',
'cache_control': 'max-age=10,must-revalidate',
'cache_expires': 10,
'resource_methods': ['GET']
})
settings['DOMAIN']['tercero'].update({
'item_url': 'regex("[\w]+")',
'item_title': 'tercero',
'item_lookup_field': 'numter',
'cache_control': 'max-age=10,must-revalidate',
'cache_expires': 10,
'additional_lookup': {
'url': 'regex("[\w]+")',
'field': 'numter'
},
'resource_methods': ['GET']
})
app = Eve(auth=None, settings=settings, validator=ValidatorSQL, data=SQL)
db = app.data.driver
Base.metadata.bind = db.engine
db.Model = Base
app.run(debug=True, use_reloader=True)
以上是关于python 使用Oracle数据库的Eve REST API的主要内容,如果未能解决你的问题,请参考以下文章
如何在 python eve 中存储到数据库之前处理数据
python RESTful API框架:Eve 高速入门
python网络自动化运维之环境搭建(EVE-NG+pycharm)
eve界面可以编辑吗
python---BFS
python软件开发的案例都有哪些,可用于哪些开发