#database.py
from sqlmodel import SQLModel, create_engine, Session
sqlite_file_name = "database.db"
sqlite_url = f"sqlite:///{sqlite_file_name}"
connect_args = {"check_same_thread": False}
engine = create_engine(sqlite_url,connect_args=connect_args)
def create_db_and_tables():
SQLModel.metadata.create_all(engine)
def get_session():
with Session(engine) as session:
yield session
#models.py
# app/models.py
# app/models.py
from sqlmodel import SQLModel, Field
from typing import Optional
class BookBase(SQLModel):
title: str
author: Optional[str]
class Book(BookBase, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
class BookCreate(BookBase):
pass
class BookRead(BookBase):
id: int
配件回老家了吧
最新推荐文章于 2024-07-13 03:24:31 发布