@@ -38,37 +38,37 @@ def cls_to_dbscheme(cls: schema.Class):
3838 )
3939 # use property-specific tables for 1-to-many and 1-to-at-most-1 properties
4040 for f in cls .properties :
41- if f .is_optional :
41+ if f .is_repeated :
4242 yield Table (
43- keyset = KeySet (["id" ]),
43+ keyset = KeySet (["id" , "index" ]),
4444 name = inflection .tableize (f"{ cls .name } _{ f .name } " ),
4545 columns = [
4646 Column ("id" , type = dbtype (cls .name )),
47- Column (f .name , dbtype (f .type )),
48- ],
47+ Column ("index" , type = "int" ),
48+ Column (inflection .singularize (f .name ), dbtype (f .type )),
49+ ]
4950 )
50- elif f .is_repeated :
51+ elif f .is_optional :
5152 yield Table (
52- keyset = KeySet (["id" , "index" ]),
53+ keyset = KeySet (["id" ]),
5354 name = inflection .tableize (f"{ cls .name } _{ f .name } " ),
5455 columns = [
5556 Column ("id" , type = dbtype (cls .name )),
56- Column ("index" , type = "int" ),
57- Column (inflection .singularize (f .name ), dbtype (f .type )),
58- ]
57+ Column (f .name , dbtype (f .type )),
58+ ],
5959 )
6060
6161
6262def get_declarations (data : schema .Schema ):
6363 return [d for cls in data .classes for d in cls_to_dbscheme (cls )]
6464
6565
66- def get_includes (data : schema .Schema , include_dir : pathlib .Path ):
66+ def get_includes (data : schema .Schema , include_dir : pathlib .Path , swift_dir : pathlib . Path ):
6767 includes = []
6868 for inc in data .includes :
6969 inc = include_dir / inc
7070 with open (inc ) as inclusion :
71- includes .append (SchemeInclude (src = inc .relative_to (paths . swift_dir ), data = inclusion .read ()))
71+ includes .append (SchemeInclude (src = inc .relative_to (swift_dir ), data = inclusion .read ()))
7272 return includes
7373
7474
@@ -78,8 +78,8 @@ def generate(opts, renderer):
7878
7979 data = schema .load (input )
8080
81- dbscheme = Scheme (src = input .relative_to (paths .swift_dir ),
82- includes = get_includes (data , include_dir = input .parent ),
81+ dbscheme = Scheme (src = input .relative_to (opts .swift_dir ),
82+ includes = get_includes (data , include_dir = input .parent , swift_dir = opts . swift_dir ),
8383 declarations = get_declarations (data ))
8484
8585 renderer .render (dbscheme , out )
0 commit comments