Answer the question
In order to leave comments, you need to log in
How to get data in json?
There is a standard example from the tutorial ( eve-sqlalchemy ):
from eve import Eve
from eve_sqlalchemy import SQL
from eve_sqlalchemy.config import DomainConfig, ResourceConfig
from eve_sqlalchemy.validation import ValidatorSQL
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import column_property
Base = declarative_base()
class People(Base):
__tablename__ = 'people'
id = Column(Integer, primary_key=True, autoincrement=True)
firstname = Column(String(80))
lastname = Column(String(120))
fullname = column_property(firstname + " " + lastname)
SETTINGS = {
'DEBUG': True,
'SQLALCHEMY_DATABASE_URI': 'sqlite://',
'SQLALCHEMY_TRACK_MODIFICATIONS': False,
'DOMAIN': DomainConfig({
'people': ResourceConfig(People)
}).render()
}
app = Eve(auth=None, settings=SETTINGS, validator=ValidatorSQL, data=SQL)
# bind SQLAlchemy
db = app.data.driver
Base.metadata.bind = db.engine
db.Model = Base
db.create_all()
# Insert some example data in the db
if not db.session.query(People).count():
db.session.add_all([
People(firstname=u'George', lastname=u'Washington'),
People(firstname=u'John', lastname=u'Adams'),
People(firstname=u'Thomas', lastname=u'Jefferson')])
db.session.commit()
# using reloader will destroy in-memory sqlite db
app.run(debug=True, use_reloader=False)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question