mirror of
				https://github.com/fastapi/sqlmodel.git
				synced 2025-10-31 01:58:00 +08:00 
			
		
		
		
	 fa2f178b8a
			
		
	
	fa2f178b8a
	
	
	
		
			
			Co-authored-by: Mohamed Farahat <farahats9@yahoo.com> Co-authored-by: Stefan Borer <stefan.borer@gmail.com> Co-authored-by: Peter Landry <peter.landry@gmail.com> Co-authored-by: Anton De Meester <antondemeester+github@gmail.com>
		
			
				
	
	
		
			29 lines
		
	
	
		
			797 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			797 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| from typing import Optional
 | |
| 
 | |
| import pytest
 | |
| from sqlmodel import Field, Session, SQLModel, create_engine
 | |
| 
 | |
| 
 | |
| def test_query(clear_sqlmodel):
 | |
|     class Hero(SQLModel, table=True):
 | |
|         id: Optional[int] = Field(default=None, primary_key=True)
 | |
|         name: str
 | |
|         secret_name: str
 | |
|         age: Optional[int] = None
 | |
| 
 | |
|     hero_1 = Hero(name="Deadpond", secret_name="Dive Wilson")
 | |
| 
 | |
|     engine = create_engine("sqlite://")
 | |
| 
 | |
|     SQLModel.metadata.create_all(engine)
 | |
|     with Session(engine) as session:
 | |
|         session.add(hero_1)
 | |
|         session.commit()
 | |
|         session.refresh(hero_1)
 | |
| 
 | |
|     with Session(engine) as session:
 | |
|         with pytest.warns(DeprecationWarning):
 | |
|             query_hero = session.query(Hero).first()
 | |
|         assert query_hero
 | |
|         assert query_hero.name == hero_1.name
 |