Last active
August 29, 2015 14:21
-
-
Save samtux/e7f85eb6bad8e3ea5b7d to your computer and use it in GitHub Desktop.
Eve REST API with Oracle Database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment