-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
296 additions
and
147 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ dist | |
*.egg-info | ||
|
||
# Checkers | ||
.coverage | ||
.mypy_cache | ||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
[mypy] | ||
files = aiohttp_sqlalchemy, tests | ||
|
||
[mypy-sqlalchemy.*] | ||
ignore_missing_imports = True | ||
plugins = sqlalchemy.ext.mypy.plugin |
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
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
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from aiohttp import web | ||
import aiohttp_sqlalchemy | ||
from aiohttp_sqlalchemy import sa_decorator, sa_bind, SAView | ||
from datetime import datetime | ||
import sqlalchemy as sa | ||
from sqlalchemy import orm | ||
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine | ||
|
||
|
||
metadata = sa.MetaData() | ||
Base = orm.declarative_base(metadata=metadata) | ||
|
||
|
||
class Request(Base): | ||
__tablename__ = 'requests' | ||
id = sa.Column(sa.Integer, primary_key=True) | ||
timestamp = sa.Column(sa.DateTime(), default=datetime.now) | ||
|
||
|
||
class Main: | ||
@sa_decorator() | ||
async def get(self, request): | ||
async with request['sa_main'].bind.begin() as conn: | ||
await conn.run_sync(Base.metadata.create_all) | ||
|
||
async with request['sa_main'].begin(): | ||
request['sa_main'].add_all([Request()]) | ||
result = await request['sa_main'].execute(sa.select(Request)) | ||
data = {r.id: r.timestamp.isoformat() for r in result.scalars()} | ||
return web.json_response(data) | ||
|
||
|
||
app = web.Application() | ||
|
||
engine = create_async_engine('sqlite+aiosqlite:///') | ||
Session = orm.sessionmaker(engine, AsyncSession) | ||
aiohttp_sqlalchemy.setup(app, [sa_bind(Session, middleware=False)]) | ||
|
||
main = Main() | ||
app.add_routes([web.get('/', main.get)]) | ||
|
||
if __name__ == '__main__': | ||
web.run_app(app) |
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
Oops, something went wrong.