Skip to content

Commit

Permalink
replace register_tortoise in sqlite example (fixes #1901)
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Oct 27, 2023
1 parent d8530a6 commit 58ab41a
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions examples/sqlite_database/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@
from typing import List

import models
from tortoise.contrib.fastapi import register_tortoise
from tortoise import Tortoise

from nicegui import app, ui

register_tortoise(
app,
db_url='sqlite://db.sqlite3',
modules={'models': ['models']}, # tortoise will look for models in this main module
generate_schemas=True, # in production you should use version control migrations instead
)

async def init_db() -> None:
await Tortoise.init(db_url='sqlite://db.sqlite3', modules={'models': ['models']})
await Tortoise.generate_schemas()


async def close_db() -> None:
await Tortoise.close_connections()

app.on_startup(init_db)
app.on_shutdown(close_db)


@ui.refreshable
Expand Down

0 comments on commit 58ab41a

Please sign in to comment.