Search
 
SCRIPT & CODE EXAMPLE
 

SQL

postgresql fastapi sqlmodel example

import os

from sqlmodel import SQLModel

from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
from sqlalchemy.orm import sessionmaker


DATABASE_URL = os.environ.get("DATABASE_URL")

engine = create_async_engine(DATABASE_URL, echo=True, future=True)


async def init_db():
    async with engine.begin() as conn:
        # await conn.run_sync(SQLModel.metadata.drop_all)
        await conn.run_sync(SQLModel.metadata.create_all)


async def get_session() -> AsyncSession:
    async_session = sessionmaker(
        engine, class_=AsyncSession, expire_on_commit=False
    )
    async with async_session() as session:
        yield session
Comment

PREVIOUS NEXT
Code Example
Sql :: oracle tablespace autoextend 
Sql :: sql order by clause 
Sql :: join multiple tables in sql 
Sql :: Oracle SQL join three tables and group by column 
Sql :: read sql file in python pandas 
Sql :: how to populate a table in MySQL from and existing csv file 
Sql :: postgres execute multiple sql file from command line 
Sql :: sqlstate[hy000] [2006] mysql server has gone away laravel 
Sql :: sqlalchemy filter by relationship 
Sql :: mysql write into table 
Sql :: postgres enumerated type 
Sql :: mysql null 
Sql :: xampp mysql problem detected port 3306 in use by 
Sql :: sql create table as 
Sql :: delete join sql server 
Sql :: sqlite select regex 
Sql :: Why mysql is used? 
Sql :: limit rows after order by oracle 
Sql :: mysql backup certain tables workbench 
Sql :: sql table contains 
Sql :: pl sql revoke role from user 
Sql :: how to use 3 fields as primary key in sql tables? 
Sql :: sql server manager close connection 
Sql :: use mysql 8 without password 
Sql :: deduplicate delimited string bigquery 
Sql :: oracle call a function in a insert statement 
Sql :: prepared statement mysql java delete selected rows 
Sql :: get total and distict row diff in sql 
Sql :: Stack conditions in CASE statement in PL/SQL 
Sql :: amount of entries in a table psql 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =