Jaymon / prom

A PostgreSQL or SQLite orm for Python
MIT License
22 stars 4 forks source link

EnumField #44

Closed Jaymon closed 2 years ago

Jaymon commented 7 years ago

a field that converts to an int behind the scenes, but allows the live object to have a set of values, so you could do something like:

class Foo(Orm):
  bar = EnumField("a", "b", "c", "d")

f = Foo()
f.bar = ["a", "b"]
f.save() # bar will save into the db as 3

f2 = f.query.get_pk(f.pk)
f2.bar # ["a", "b"]

So the enum field will set the appropriate field setters to make sure the the live orm always has a set of values, and that the db always gets the int, when it creates the field it takes the values you passed into it and sets their values in the order they are passed in, doubling the value as it goes, so

EnumField("a", "b", "c", "d")
a = 1
b = 2
c = 4
d = 8
Jaymon commented 2 years ago

I think this is actually superceded by extras.config.Field's enum support