예제 #1
0
sqlite_db = os.path.join(
    os.path.dirname(os.path.realpath(__file__)), 'unrest-test.db'
)

db_url = f'sqlite:///{sqlite_db}'


engine = create_engine(db_url)
Session = sessionmaker()
Session.configure(bind=engine)
session = scoped_session(Session)

if not os.path.exists(sqlite_db):
    Base.metadata.create_all(bind=engine)
    fill_data(session)
    session.remove()


@app.route("/")
async def home(request):
    return response.text("A normal sanic route!")


@app.middleware('response')
async def after_request(request, response):
    session.remove()


rest = UnRest(app, session, framework=SanicFramework)
fruit = rest(
예제 #2
0
from unrest.idiom.json_server import JsonServerIdiom
from unrest.tests.model import Base, Fruit, Tree, fill_data

app = Flask(__name__)

sqlite_db = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                         'unrest-test.db')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{sqlite_db}'
app.debug = True

db = SQLAlchemy(app)

if not os.path.exists(sqlite_db):
    Base.metadata.create_all(bind=db.engine)
    fill_data(db.session)
    db.session.remove()


@app.route("/")
def home():
    return "A normal flask route!"


rest = UnRest(app, db.session, idiom=JsonServerIdiom)
fruit = rest(Fruit,
             methods=rest.all,
             properties=[rest.Property('square_size', Float())])
rest(
    Tree,
    methods=rest.all,