Created
April 21, 2013 17:15
-
-
Save Tefnet/5430309 to your computer and use it in GitHub Desktop.
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 import Eve | |
from eve.io.sqlalchemy import SQLAlchemy, Validator | |
import models | |
app = Eve(validator=Validator, data=SQLAlchemy) | |
db = app.data.driver | |
db.create_all() | |
if not db.session.query(models.People).count(): | |
for item in models.test_data: | |
db.session.add(models.People.from_tuple(item)) | |
db.session.commit() | |
app.run(debug=True) |
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.io.sqlalchemy import db | |
from eve.io.sqlalchemy.decorators import registerSchema | |
test_data = [ | |
(u'George', u'Washington'), | |
(u'John', u'Adams'), | |
(u'Thomas', u'Jefferson'), | |
(u'George', u'Clinton'), | |
(u'James', u'Madison'), | |
(u'Elbridge', u'Gerry'), | |
(u'James', u'Monroe'), | |
(u'John', u'Adams'), | |
(u'Andrew', u'Jackson'), | |
(u'Martin', u'Van Buren'), | |
(u'William', u'Harrison'), | |
(u'John', u'Tyler'), | |
(u'James', u'Polk'), | |
(u'Zachary', u'Taylor'), | |
(u'Millard', u'Fillmore'), | |
(u'Franklin', u'Pierce'), | |
(u'James', u'Buchanan'), | |
(u'Abraham', u'Lincoln'), | |
(u'Andrew', u'Johnson'), | |
(u'Ulysses', u'Grant'), | |
(u'Henry', u'Wilson'), | |
(u'Rutherford', u'Hayes'), | |
(u'James', u'Garfield'), | |
(u'Chester', u'Arthur'), | |
(u'Grover', u'Cleveland'), | |
(u'Benjamin', u'Harrison'), | |
(u'Grover', u'Cleveland'), | |
(u'William', u'McKinley'), | |
(u'Theodore', u'Roosevelt'), | |
(u'Charles', u'Fairbanks'), | |
(u'William', u'Taft'), | |
(u'Woodrow', u'Wilson'), | |
(u'Warren', u'Harding'), | |
(u'Calvin', u'Coolidge'), | |
(u'Charles', u'Dawes'), | |
(u'Herbert', u'Hoover'), | |
(u'Franklin', u'Roosevelt'), | |
(u'Henry', u'Wallace'), | |
(u'Harry', u'Truman'), | |
(u'Alben', u'Barkley'), | |
(u'Dwight', u'Eisenhower'), | |
(u'John', u'Kennedy'), | |
(u'Lyndon', u'Johnson'), | |
(u'Hubert', u'Humphrey'), | |
(u'Richard', u'Nixon'), | |
(u'Gerald', u'Ford'), | |
(u'Nelson', u'Rockefeller'), | |
(u'Jimmy', u'Carter'), | |
(u'Ronald', u'Reagan'), | |
(u'George', u'Bush'), | |
(u'Bill', u'Clinton'), | |
(u'George', u'Bush'), | |
(u'Barack', u'Obama') | |
] | |
@registerSchema('people') | |
class People(db.Model): | |
id = db.Column(db.Integer, primary_key=True) | |
firstname = db.Column(db.String(80)) | |
lastname = db.Column(db.String(120)) | |
fullname = db.column_property(firstname + " " + lastname) | |
year = db.Column(db.Integer, unique=True, nullable=True) | |
_eve_resource = { | |
'pagination': False, | |
} | |
def __repr__(self): | |
return '<People %s>' % (self.fullname,) | |
@classmethod | |
def from_tuple(cls, data): | |
return cls(firstname=data[0], lastname=data[1]) |
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
SERVER_NAME = 'localhost:5000' | |
SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/test.db' | |
SQLALCHEMY_ECHO = True | |
SQLALCHEMY_RECORD_QUERIES = True | |
DEBUG = True | |
DOMAIN = { | |
'people': { | |
'item_title': 'person', | |
'additional_lookup': { | |
'url': '[0-9]+', | |
'field': 'id' | |
}, | |
'cache_control': 'max-age=10,must-revalidate', | |
'cache_expires': 10, | |
'resource_methods': ['GET', 'POST', 'DELETE'], | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment