* feat: add check columns class * feat: write document of check columns part * test: write a test for check columns constraints * fix: debuging test exception raise mysql * fix: set pragma no cover to ignore cov * fix: ignore pytest raise in python 3.x not 10 * feat: set constraint name for check columns * refactor: support index and check overwrites * fix: debuging check constraint arguments * fix: debug coverage all code tests * fix: pass the map of type constraint to counter * refactor: edit check name replace sapce underline * refactor: write new function copy constraints * test: write test for invalid constraint type * fix: debug text cluase replaced names * fix: set pragma no cover for result returned * refactor: no coverage for main if statement * perf: change get constraint copy func code * fix: fix bug in mypy typing check
26 lines
746 B
Python
26 lines
746 B
Python
import datetime
|
|
import databases
|
|
import sqlalchemy
|
|
|
|
import ormar
|
|
|
|
database = databases.Database("sqlite:///db.sqlite")
|
|
metadata = sqlalchemy.MetaData()
|
|
|
|
|
|
class Course(ormar.Model):
|
|
class Meta:
|
|
database = database
|
|
metadata = metadata
|
|
# define your constraints in Meta class of the model
|
|
# it's a list that can contain multiple constraints
|
|
# hera a combination of name and column will have a level check in the db
|
|
constraints = [
|
|
ormar.CheckColumns("start_time < end_time", name="date_check"),
|
|
]
|
|
|
|
id: int = ormar.Integer(primary_key=True)
|
|
name: str = ormar.String(max_length=100)
|
|
start_date: datetime.date = ormar.Date()
|
|
end_date: datetime.date = ormar.Date()
|