more checks for table and pydantic model creation

This commit is contained in:
collerek
2020-08-03 17:49:01 +02:00
parent 876f225d0b
commit d7355b8c9b
5 changed files with 75 additions and 14 deletions

View File

@ -1,5 +1,6 @@
import datetime
import decimal
from typing import Any
import pydantic
import sqlalchemy
@ -10,6 +11,10 @@ from orm.exceptions import ModelDefinitionError
class BaseField:
__type__ = None
def __new__(cls, *args, **kwargs):
cls.__annotations__ = {}
return super().__new__(cls)
def __init__(self, *args, **kwargs):
name = kwargs.pop('name', None)
args = list(args)
@ -32,6 +37,10 @@ class BaseField:
self.index = kwargs.pop('index', None)
self.unique = kwargs.pop('unique', None)
self.pydantic_only = kwargs.pop('pydantic_only', False)
if self.pydantic_only and self.primary_key:
raise ModelDefinitionError('Primary key column cannot be pydantic only.')
def get_column(self, name=None) -> sqlalchemy.Column:
name = self.name or name
constraints = self.get_constraints()