Skip to content

Instantly share code, notes, and snippets.

@PythonCoderAS
Created May 10, 2022 23:09
Show Gist options
  • Select an option

  • Save PythonCoderAS/4731e2017689f5f73ab9db6b16db846c to your computer and use it in GitHub Desktop.

Select an option

Save PythonCoderAS/4731e2017689f5f73ab9db6b16db846c to your computer and use it in GitHub Desktop.
Template for postgres aerich-compatible tortoise ORM configuration file #tortoise-orm #postgres #asyncpg
from tortoise import Tortoise
project_db = "test"
TORTOISE_ORM = {
"connections": {
"default": {
"engine": "tortoise.backends.asyncpg",
"credentials": {
"user": project_db,
"password": project_db,
"database": project_db,
"host": "localhost",
"port": 5432,
},
},
},
"apps": {
"models": {
"models": [__name__, "aerich.models"],
"default_connection": "default",
},
},
"use_tz": True,
"maxsize": 20,
}
async def init():
"""Initialize the ORM."""
# Here we connect to a SQLite DB file.
# also specify the app name of "models"
# which contain models from "app.models"
await Tortoise.init(TORTOISE_ORM)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment