@@ -8,7 +8,11 @@ _Async SQLAlchemy 2 for FastAPI — boilerplate, pagination, and seamless sessio
88[ ![ Conventional Commits] ( https://img.shields.io/badge/Conventional%20Commits-1.0.0-brightgreen.svg )] ( https://conventionalcommits.org )
99[ ![ GitHub License] ( https://img.shields.io/github/license/hadrien/fastsqla )] ( https://github.com/hadrien/FastSQLA/blob/main/LICENSE )
1010
11- ** Documentation** : https://hadrien.github.io/FastSQLA/
11+ ** Documentation** : [ https://hadrien.github.io/FastSQLA/ ] ( https://hadrien.github.io/FastSQLA/ )
12+
13+ ** Github Repo:** [ https://github.com/hadrien/fastsqla ] ( https://github.com/hadrien/fastsqla )
14+
15+ -----------------------------------------------------------------------------------------
1216
1317` FastSQLA ` is an [ ` SQLAlchemy 2 ` ] ( https://docs.sqlalchemy.org/en/20/ ) extension for
1418[ ` FastAPI ` ] ( https://fastapi.tiangolo.com/ ) .
@@ -147,11 +151,13 @@ class Hero(Base):
147151 id : Mapped[int ] = mapped_column(primary_key = True )
148152 name: Mapped[str ] = mapped_column(unique = True )
149153 secret_identity: Mapped[str ]
154+ age: Mapped[int ]
150155
151156
152157class HeroBase (BaseModel ):
153158 name: str
154159 secret_identity: str
160+ age: int
155161
156162
157163class HeroModel (HeroBase ):
@@ -160,21 +166,21 @@ class HeroModel(HeroBase):
160166
161167
162168@app.get (" /heros" , response_model = Page[HeroModel])
163- async def list_users (paginate : Paginate):
169+ async def list_heros (paginate : Paginate):
164170 stmt = select(Hero)
165171 return await paginate(stmt)
166172
167173
168174@app.get (" /heros/{hero_id} " , response_model = Item[HeroModel])
169- async def get_user (hero_id : int , session : Session):
175+ async def get_hero (hero_id : int , session : Session):
170176 hero = await session.get(Hero, hero_id)
171177 if hero is None :
172178 raise HTTPException(HTTPStatus.NOT_FOUND , " Hero not found" )
173179 return {" data" : hero}
174180
175181
176182@app.post (" /heros" , response_model = Item[HeroModel])
177- async def create_user (new_hero : HeroBase, session : Session):
183+ async def create_hero (new_hero : HeroBase, session : Session):
178184 hero = Hero(** new_hero.model_dump())
179185 session.add(hero)
180186 try :
@@ -197,22 +203,23 @@ sqlite3 db.sqlite <<EOF
197203CREATE TABLE hero (
198204 id INTEGER PRIMARY KEY AUTOINCREMENT,
199205 name TEXT NOT NULL UNIQUE, -- Unique hero name (e.g., Superman)
200- secret_identity TEXT NOT NULL -- Secret identity (e.g., Clark Kent)
206+ secret_identity TEXT NOT NULL, -- Secret identity (e.g., Clark Kent)
207+ age INTEGER NOT NULL -- Age of the hero (e.g., 30)
201208);
202209
203- -- Insert heroes with their name and secret identity
204- INSERT INTO hero (name, secret_identity) VALUES ('Superman', 'Clark Kent');
205- INSERT INTO hero (name, secret_identity) VALUES ('Batman', 'Bruce Wayne');
206- INSERT INTO hero (name, secret_identity) VALUES ('Wonder Woman', 'Diana Prince');
207- INSERT INTO hero (name, secret_identity) VALUES ('Iron Man', 'Tony Stark');
208- INSERT INTO hero (name, secret_identity) VALUES ('Spider-Man', 'Peter Parker');
209- INSERT INTO hero (name, secret_identity) VALUES ('Captain America', 'Steve Rogers');
210- INSERT INTO hero (name, secret_identity) VALUES ('Black Widow', 'Natasha Romanoff');
211- INSERT INTO hero (name, secret_identity) VALUES ('Thor', 'Thor Odinson');
212- INSERT INTO hero (name, secret_identity) VALUES ('Scarlet Witch', 'Wanda Maximoff');
213- INSERT INTO hero (name, secret_identity) VALUES ('Doctor Strange', 'Stephen Strange');
214- INSERT INTO hero (name, secret_identity) VALUES ('The Flash', 'Barry Allen');
215- INSERT INTO hero (name, secret_identity) VALUES ('Green Lantern', 'Hal Jordan');
210+ -- Insert heroes with their name, secret identity, and age
211+ INSERT INTO hero (name, secret_identity, age ) VALUES ('Superman', 'Clark Kent', 30 );
212+ INSERT INTO hero (name, secret_identity, age ) VALUES ('Batman', 'Bruce Wayne', 35 );
213+ INSERT INTO hero (name, secret_identity, age ) VALUES ('Wonder Woman', 'Diana Prince', 30 );
214+ INSERT INTO hero (name, secret_identity, age ) VALUES ('Iron Man', 'Tony Stark', 45 );
215+ INSERT INTO hero (name, secret_identity, age ) VALUES ('Spider-Man', 'Peter Parker', 25 );
216+ INSERT INTO hero (name, secret_identity, age ) VALUES ('Captain America', 'Steve Rogers', 100 );
217+ INSERT INTO hero (name, secret_identity, age ) VALUES ('Black Widow', 'Natasha Romanoff', 35 );
218+ INSERT INTO hero (name, secret_identity, age ) VALUES ('Thor', 'Thor Odinson', 1500 );
219+ INSERT INTO hero (name, secret_identity, age ) VALUES ('Scarlet Witch', 'Wanda Maximoff', 30 );
220+ INSERT INTO hero (name, secret_identity, age ) VALUES ('Doctor Strange', 'Stephen Strange', 40 );
221+ INSERT INTO hero (name, secret_identity, age ) VALUES ('The Flash', 'Barry Allen', 28 );
222+ INSERT INTO hero (name, secret_identity, age ) VALUES ('Green Lantern', 'Hal Jordan', 35 );
216223EOF
217224```
218225
0 commit comments