|
1 | 1 | from sqlmodel import SQLModel, Field |
2 | 2 | from geoalchemy2 import Geometry |
3 | 3 | from sqlalchemy import Column, Numeric, String, Date |
| 4 | +from typing import Optional |
| 5 | +import datetime |
4 | 6 |
|
5 | | -class StreetTreeRegister(SQLModel): |
6 | | - __tablename__ = "flensburg.street_tree_register" |
| 7 | +class StreetTreeRegister(SQLModel, table=True): |
| 8 | + __tablename__ = "street_tree_register" |
| 9 | + __table_args__ = {'schema': 'flensburg'} |
7 | 10 |
|
8 | | - id: int = Field(primary_key=True, nullable=False) |
9 | | - tree_number = Column(String, nullable=False) |
10 | | - street = Column(String, nullable=False) |
11 | | - area_type = Column(String) |
12 | | - species = Column(String, nullable=False) |
13 | | - north = Column(Numeric, nullable=False) |
14 | | - east = Column(Numeric, nullable=False) |
15 | | - register_date = Column(Date, nullable=False) |
16 | | - type = Column(String, nullable=False) |
17 | | - geom = Column(Geometry('POINT', srid=4326)) |
| 11 | + id: int = Field(primary_key=True) # nullable=False implied for primary_key |
| 12 | + tree_number: str = Field(nullable=False) # simple field, no sa_column so nullable allowed here |
| 13 | + street: str = Field(sa_column=Column(String, nullable=False)) |
| 14 | + area_type: Optional[str] = Field(sa_column=Column(String, nullable=True), default=None) |
| 15 | + species: str = Field(sa_column=Column(String, nullable=False)) |
| 16 | + north: float = Field(sa_column=Column(Numeric, nullable=False)) |
| 17 | + east: float = Field(sa_column=Column(Numeric, nullable=False)) |
| 18 | + registration_date: datetime.date = Field(sa_column=Column(Date(), nullable=False)) |
| 19 | + type: str = Field(sa_column=Column(String, nullable=False)) |
| 20 | + geom: object = Field(sa_column=Column(Geometry('POINT', srid=31467), nullable=True)) # nullable depends on DB column |
0 commit comments