Releases: codemation/pydbantic
Releases · codemation/pydbantic
0.0.36
What's Changed
- Added supported sa_type verification & annotation field generators by @codemation in #48
Full Changelog: 0.0.35...0.0.36
0.0.35
What's Changed
- Improved Field annotations of sqlalchemy_type argument in Default, Unique, PrimaryKey, ModelField by @codemation in #47
Full Changelog: 0.0.34...0.0.35
0.0.34
What's Changed
- updated .all, .filter, .select List Type annotations by @codemation in #46
Full Changelog: 0.0.33...0.0.34
0.0.33
What's Changed
- Improved return type & cls model annotations by @codemation in #45
Full Changelog: 0.0.32...0.0.33
0.0.32
What's Changed
- fixed relationship_definitions single direction by @codemation in #44
Full Changelog: 0.0.31...0.0.32
0.0.31
Full Changelog: 0.0.30...0.0.31
0.0.30
What's Changed
- allowing >=1.9.1 pydantic version by @codemation in #43
Full Changelog: 0.0.29...0.0.30
0.0.29
What's Changed
- Replace pydantic Field usage with custom Field class which limits kw… by @codemation in #41
Full Changelog: 0.0.28...0.0.29
0.0.28 - Sqlalchemy Type definition, and Relationship / Foreign Key definitions, support for Autoincrement
What's Changed
- Added Support for Autoincrement, ForeignKeys, Relationship, sqlalchemy type within for ModelField, PrimaryKey, Default (#39), Unique fieldsby @codemation in #39
- New Relationship mapping options
- Sqlalchemy type definitions
Examples
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: 0.0.27...0.0.28
0.0.27
Full Changelog: 0.0.26...0.0.27