pystachio icon indicating copy to clipboard operation
pystachio copied to clipboard

Idea: Value constraints

Open kevints opened this issue 12 years ago • 2 comments

Often we want to restrict the set of values on a field to a subset of those allowed by the type, and often the best place to do this is the data model definition itself. For example:

class Car(Struct):
  model = String
  max_speed = Integer().constrain(GreaterThan(10))
  serial = Required(String().constrain(Match(r'^[0-9]{7}-[0-9A-F]{3}$')))

goal: serializability: just as the pystachio schema can currently be shipped with the data, constraints should be shippable as well

non-goal: arbitrary code: while it's tempting to just add a callback field, doing so would impair portability

Usage example:

car = Car(max_speed='{{ speed }}').bind(speed=5)
car.interpolate() # should return a failure code.

For inspiration see postgresql CHECK constraints.

kevints avatar Jun 06 '13 21:06 kevints

@kevints are you in a position to code or review for this? I'm willing to be the complement either way.

jsirois avatar Mar 15 '16 23:03 jsirois

@jsirois unfortunately I'm not in a position to do either right now.

kevints avatar Mar 31 '16 02:03 kevints