Skip to content

Commit eef140c

Browse files
committed
Codegen: implement set in dbschemegen
1 parent bba5d9d commit eef140c

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

misc/codegen/generators/dbschemegen.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,16 @@ def cls_to_dbscheme(cls: schema.Class, lookup: typing.Dict[str, schema.Class], a
6464
)
6565
# use property-specific tables for 1-to-many and 1-to-at-most-1 properties
6666
for f in cls.properties:
67-
if f.is_repeated:
67+
if f.is_unordered:
68+
yield Table(
69+
name=inflection.tableize(f"{cls.name}_{f.name}"),
70+
columns=[
71+
Column("id", type=dbtype(cls.name)),
72+
Column(inflection.singularize(f.name), dbtype(f.type, add_or_none_except)),
73+
],
74+
dir=dir,
75+
)
76+
elif f.is_repeated:
6877
yield Table(
6978
keyset=KeySet(["id", "index"]),
7079
name=inflection.tableize(f"{cls.name}_{f.name}"),

misc/codegen/test/test_dbschemegen.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,32 @@ def test_final_class_with_repeated_field(generate, property_cls, dir_param):
168168
)
169169

170170

171+
def test_final_class_with_repeated_unordered_field(generate, dir_param):
172+
assert generate([
173+
schema.Class("Object", group=dir_param.input, properties=[
174+
schema.RepeatedUnorderedProperty("foo", "bar"),
175+
]),
176+
]) == dbscheme.Scheme(
177+
src=schema_file.name,
178+
includes=[],
179+
declarations=[
180+
dbscheme.Table(
181+
name="objects",
182+
columns=[
183+
dbscheme.Column('id', '@object', binding=True),
184+
], dir=dir_param.expected,
185+
),
186+
dbscheme.Table(
187+
name="object_foos",
188+
columns=[
189+
dbscheme.Column('id', '@object'),
190+
dbscheme.Column('foo', 'bar'),
191+
], dir=dir_param.expected,
192+
),
193+
],
194+
)
195+
196+
171197
def test_final_class_with_predicate_field(generate, dir_param):
172198
assert generate([
173199
schema.Class("Object", group=dir_param.input, properties=[

0 commit comments

Comments
 (0)