Python-With-Gtk-Template/src/utils/models.py

26 lines
624 B
Python
Raw Normal View History

2023-09-18 01:08:09 +00:00
# Python imports
from typing import Optional
2023-09-18 01:08:09 +00:00
# Lib imports
from sqlmodel import Field, Session, SQLModel, create_engine
2023-09-18 01:08:09 +00:00
# Application imports
2023-09-18 01:08:09 +00:00
class User(SQLModel, table = True):
id: Optional[int] = Field(default = None, primary_key = True)
name: str
password: str
email: Optional[str] = None
2023-09-18 01:08:09 +00:00
# NOTE: for sake of example we create an admin user with no password set.
user = User(name = "Admin", password = "", email = "admin@domain.com")
engine = create_engine("sqlite:///database.db")
SQLModel.metadata.create_all(engine)
2023-09-18 01:08:09 +00:00
with Session(engine) as session:
session.add(user)
session.commit()