Skip to main content

Simple model validations for Elixir and Sqlalchemy

Project description

SQLAlchemy and Elixir validations
=================================

Provide a set of simple yet useful validations for the models:
Sqlalchemy:
-----------
from sqlalchemy_validations import *
people_table = Table(....)
class Person(object)
pass

mapper(Person, people_table,
extension=[Validator(
range_of('age', 0, 150),
format_of('phone', re.compile(r'\d{4}-?\d{4}'))
numericality_of('foo','bar','some_next_field')
)
]
)

Elixir:
-------
from elixir_validations import *
class Person(Entity):
username=Field(Unicode(30),nullable=False,index=True)
email=Field(Unicode,nullable=False)
age=Field(Integer,nullable=False)

validates_uniqueness_of('username')
validates_presence_of('username', 'email')
validates_format_of('email',re.compile("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])"))
validates_numericality_of('age',integer_only = True)

Project details


Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page