orm icon indicating copy to clipboard operation
orm copied to clipboard

Is this project stopped for maintenance?

Open yi250 opened this issue 3 years ago • 2 comments

Seems to be unavailable now,'await' outside function,I even called the code in text to run no one except to create a database

yi250 avatar Sep 11 '22 16:09 yi250

Hey, What is the issue exactly? Can you provide more info?

aminalaee avatar Sep 11 '22 17:09 aminalaee

现在好像不可用了,我甚至在文本中调用了代码来运行除了创建数据库之外没有人'await' outside function,

Did you copy the sample code directly?

Functions that contain await need to be used in async functions

Like this

import asyncio

import databases
import orm

database = databases.Database("sqlite:///db.sqlite")
models = orm.ModelRegistry(database=database)


class Note(orm.Model):
    tablename = "notes"
    registry = models
    fields = {
        "id": orm.Integer(primary_key=True),
        "text": orm.String(max_length=100),
        "completed": orm.Boolean(default=False),
    }


async def main():
    # Create the tables
    await models.create_all()

    await Note.objects.create(text="Buy the groceries.", completed=False)

    note = await Note.objects.get(id=1)
    print(note)
    # Note(id=1)


if __name__ == '__main__':
    asyncio.run(main())

iasukas avatar Oct 03 '22 04:10 iasukas