What's Changed
* Added Support for Autoincrement, ForeignKeys, Relationship, sqlalchemy type within for ModelField, PrimaryKey, Default (39), Unique fieldsby codemation in https://github.com/codemation/pydbantic/pull/39
* New Relationship mapping options
* Sqlalchemy type definitions
Examples
python
from uuid import uuid4
from datetime import datetime
from typing import List, Optional, Union
import sqlalchemy
from pydbantic import DataBaseModel, PrimaryKey, Unique, Relationship, ForeignKey
def uuid_str():
return str(uuid4())
class Department(DataBaseModel):
department_id: str = PrimaryKey()
name: str
company: str
is_sensitive: bool = False
positions: List[Optional['Positions']] = []
class Positions(DataBaseModel):
position_id: str = PrimaryKey()
name: str
department: Department = None
employees: List[Optional['Employee']] = []
class EmployeeInfo(DataBaseModel):
__tablename__ = "employee_info"
ssn: Optional[int] = PrimaryKey(sqlalchemy_type=sqlalchemy.Integer, autoincrement=True)
bio_id: str = Unique(sqlalchemy.String(50), default=uuid_str)
first_name: str
last_name: str
address: str
address2: Optional[str]
city: Optional[str]
zip: Optional[int]
new: Optional[str]
employee: Optional['Employee'] = Relationship("Employee", 'bio_id', 'employee_id')
class Employee(DataBaseModel):
__tablename__ = "employee"
employee_id: str = PrimaryKey()
emp_ssn: Optional[int] = ForeignKey(EmployeeInfo, 'ssn')
employee_info: Optional[EmployeeInfo] = Relationship("EmployeeInfo", 'employee_id', 'bio_id')
position: List[Optional[Positions]] = []
salary: float
is_employed: bool
date_employed: Optional[str]
def time_now():
return datetime.now().isoformat()
def get_uuid4():
return str(uuid4())
class Coordinate(DataBaseModel):
id: str = PrimaryKey(default=get_uuid4)
lat_long: tuple
journeys: List[Optional["Journey"]] = []
class Journey(DataBaseModel):
trip_id: str = PrimaryKey(default=get_uuid4)
waypoints: List[Optional[Coordinate]] = []
**Full Changelog**: https://github.com/codemation/pydbantic/compare/0.0.27...0.0.28