class Cowboy(sheraf.models.IntOrderedNamedAttributesModel): table = "my_model_queryset" age = sheraf.IntegerAttribute() name = sheraf.StringAttribute(default="John Doe") email = sheraf.StringAttribute().index(unique=True) genre = sheraf.StringAttribute(default="M") size = sheraf.IntegerAttribute().index()
class Model(tests.UUIDAutoModel): set = sheraf.SetAttribute( sheraf.SetAttribute( sheraf.StringAttribute(), persistent_type=persistent_type, ), persistent_type=persistent_type, ).index()
class CommonModelDefaultValuesMethodsA(tests.IntAutoModel): def lower(self, value): return {value.lower()} foo = sheraf.StringAttribute() bar = sheraf.SimpleAttribute() theindex = sheraf.Index(foo, bar, values=lower) @theindex.values(bar) def upper(self, bar): return {bar.upper()}
class CommonModelDifferentValuesMethodsB(tests.IntAutoModel): foo = sheraf.StringAttribute() bar = sheraf.SimpleAttribute() theindex = sheraf.Index(foo, bar) @theindex.values(foo) def lower(self, foo): return {foo.lower()} @theindex.values(bar) def upper(self, bar): return {bar.upper()}
class Horseboy(tests.UUIDAutoModel): name = sheraf.StringAttribute() horses = sheraf.IndexedModelAttribute(Horse)
class Horse(sheraf.AttributeModel): name = sheraf.StringAttribute().index(primary=True) size = sheraf.IntegerAttribute()
class M(tests.UUIDAutoModel): foo = sheraf.StringAttribute()
m = Model.create() m.set = {1, 2, 3} m.edit({"set": [1, 2]}, deletion=True) assert {1, 2} == set(m.set) m.edit({"set": [1, 2]}, edition=True) assert {1, 2} == set(m.set) m.edit({"set": [1, 2, 3]}, addition=True) assert {1, 2, 3} == set(m.set) @pytest.mark.parametrize("persistent_type", [sheraf.types.Set, set]) @pytest.mark.parametrize("subattribute", [None, sheraf.StringAttribute()]) def test_indexation(sheraf_database, persistent_type, subattribute): class Model(tests.UUIDAutoModel): set = sheraf.SetAttribute( subattribute, persistent_type=persistent_type, ).index() with sheraf.connection(commit=True) as conn: m = Model.create(set=["foo", "bar"]) assert {m.raw_identifier: m.mapping} == dict( conn.root()[Model.table]["set"]["foo"] ) assert {m.raw_identifier: m.mapping} == dict( conn.root()[Model.table]["set"]["bar"] )
class Cowboy(sheraf.Model): table = "future_cowboys" name = sheraf.StringAttribute().index()
class Model(tests.UUIDAutoModel): attr = sheraf.StringAttribute().index()
class CliModel(sheraf.Model): table = "climymodel" foo = sheraf.StringAttribute().index() boo = sheraf.StringAttribute().index()