import orm
import asyncio
from Models import User, Blog, Comment

loop = asyncio.get_event_loop()


# 使用 yield from 案例
@asyncio.coroutine
def test1():
    yield from orm.create_pool(user='root', password='qq5591916', db='awesome', loop=loop)

    u = User(name='Test', email='text1@example.com', passwd='1234567890', image='about:blank')

    yield from u.save()


# 使用 await 案例
async def test2():
    await orm.create_pool(user='root', password='qq5591916', db='awesome', loop=loop)

    u = User(name='Test', email='text2@example.com', passwd='1234567890', image='about:blank')

    await u.save()

# loop.run_until_complete(test2())
# 原始 案例
# u = User(name='Test', email='text4@example.com', passwd='1234567890', image='about:blank')
# loop.run_until_complete(orm.create_pool(user='root', password='qq5591916', db='awesome', loop=loop))
# loop.run_until_complete(u.save())


