mirror of
https://github.com/fastapi/sqlmodel.git
synced 2025-08-14 17:41:37 +08:00
📝 Add source examples for Python 3.9 and 3.10 (#715)
* 📝 Add source examples for Python 3.9 and 3.10 * ✅ Add tests for new source examples for Python 3.9 and 3.10, still needs pytest markers * ✅ Add tests for fastapi examples * ✅ Update tests for FastAPI app testing, for Python 3.9 and 3.10, fixing multi-app testing conflicts * ✅ Require Python 3.9 and 3.10 for tests * ✅ Update tests with missing markers
This commit is contained in:

committed by
GitHub

parent
cce30d7546
commit
d8effcbc5c
16
docs_src/tutorial/create_db_and_table/tutorial001_py310.py
Normal file
16
docs_src/tutorial/create_db_and_table/tutorial001_py310.py
Normal file
@ -0,0 +1,16 @@
|
||||
from sqlmodel import Field, SQLModel, create_engine
|
||||
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
secret_name: str
|
||||
age: int | None = None
|
||||
|
||||
|
||||
sqlite_file_name = "database.db"
|
||||
sqlite_url = f"sqlite:///{sqlite_file_name}"
|
||||
|
||||
engine = create_engine(sqlite_url, echo=True)
|
||||
|
||||
SQLModel.metadata.create_all(engine)
|
22
docs_src/tutorial/create_db_and_table/tutorial002_py310.py
Normal file
22
docs_src/tutorial/create_db_and_table/tutorial002_py310.py
Normal file
@ -0,0 +1,22 @@
|
||||
from sqlmodel import Field, SQLModel, create_engine
|
||||
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
secret_name: str
|
||||
age: int | None = None
|
||||
|
||||
|
||||
sqlite_file_name = "database.db"
|
||||
sqlite_url = f"sqlite:///{sqlite_file_name}"
|
||||
|
||||
engine = create_engine(sqlite_url, echo=True)
|
||||
|
||||
|
||||
def create_db_and_tables():
|
||||
SQLModel.metadata.create_all(engine)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
create_db_and_tables()
|
22
docs_src/tutorial/create_db_and_table/tutorial003_py310.py
Normal file
22
docs_src/tutorial/create_db_and_table/tutorial003_py310.py
Normal file
@ -0,0 +1,22 @@
|
||||
from sqlmodel import Field, SQLModel, create_engine # (2)!
|
||||
|
||||
|
||||
class Hero(SQLModel, table=True): # (3)!
|
||||
id: int | None = Field(default=None, primary_key=True) # (4)!
|
||||
name: str # (5)!
|
||||
secret_name: str # (6)!
|
||||
age: int | None = None # (7)!
|
||||
|
||||
|
||||
sqlite_file_name = "database.db" # (8)!
|
||||
sqlite_url = f"sqlite:///{sqlite_file_name}" # (9)!
|
||||
|
||||
engine = create_engine(sqlite_url, echo=True) # (10)!
|
||||
|
||||
|
||||
def create_db_and_tables(): # (11)!
|
||||
SQLModel.metadata.create_all(engine) # (12)!
|
||||
|
||||
|
||||
if __name__ == "__main__": # (13)!
|
||||
create_db_and_tables() # (14)!
|
Reference in New Issue
Block a user