44 lines
974 B
Python
44 lines
974 B
Python
from decimal import Decimal
|
|
from typing import Any, Dict, Optional
|
|
|
|
from sqlalchemy.schema import Column
|
|
from sqlalchemy.types import JSON
|
|
from sqlmodel import Field, SQLModel, Session
|
|
|
|
from mapmakr.database import get_engine
|
|
|
|
|
|
class MarkerBase(SQLModel):
|
|
name: str
|
|
longitude: Decimal = Field(default=0)
|
|
latitude: Decimal = Field(default=0)
|
|
options: Dict[str, Any] = Field(sa_column=Column(JSON))
|
|
|
|
|
|
class Marker(MarkerBase, table=True): # type: ignore[call-arg]
|
|
id: Optional[int] = Field(default=None, primary_key=True)
|
|
|
|
|
|
class MarkerCreate(MarkerBase):
|
|
pass
|
|
|
|
|
|
class MarkerRead(MarkerBase):
|
|
id: int
|
|
|
|
|
|
class MarkerUpdate(SQLModel):
|
|
name: Optional[str] = None
|
|
longitude: Optional[Decimal] = None
|
|
latitude: Optional[Decimal] = None
|
|
options: Optional[Dict[str, Any]] = None
|
|
|
|
|
|
def create_db_tables():
|
|
SQLModel.metadata.create_all(get_engine())
|
|
|
|
|
|
def get_session():
|
|
with Session(get_engine()) as session:
|
|
yield session
|