Open yi250 opened 2 years ago
Hey, What is the issue exactly? Can you provide more info?
现在好像不可用了,我甚至在文本中调用了代码来运行除了创建数据库之外没有人
'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())
Seems to be unavailable now,
'await' outside function,
I even called the code in text to run no one except to create a database