| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import pathlib
- current = pathlib.Path(__file__).parent
- root = current.parent
- import sys
- sys.path.append(str(root))
- import assets
- import sqlmodel
- def drop_database() -> None:
- db = pathlib.Path("./003-product_app.db")
- if db.is_file():
- db.unlink()
- drop_database()
- connection = sqlmodel.create_engine("sqlite:///003-product_app.db")
- sqlmodel.SQLModel.metadata.create_all(connection)
- app = assets.product_app(connection)
- print("App initialized.")
- create = app.create({
- "barcode": "123456789012",
- "name": "Sample",
- "description": "This is sample name.",
- "author": "John Snow",
- "image": "https://uuu.owo.pl",
- "stock_count": "10"
- })
- print("Create:")
- print(create)
- print()
- select = app.get_barcode("123456789012")
- print("Select by barcode:")
- print(select)
- print()
- select = app.get_name("Sample")
- print("Select by name:")
- print(select)
- print()
- create = app.create({
- "barcode": "210987654321",
- "name": "Second sample",
- "description": "This is sample item second.",
- "author": "other",
- "image": "https://test.pl",
- "stock_count": "20"
- })
- print("Create second:")
- print(create)
- print()
- alls = app.all()
- print("Select all:")
- print(alls)
- print()
- drop_database()
|