11import click
22from typing import List
3+
4+ from linkml_runtime import SchemaView
35from linkml_runtime .linkml_model import SchemaDefinition , ClassDefinitionName , SlotDefinitionName
4- from linkml .utils .formatutils import underscore
5- from linkml .utils .schemaloader import SchemaLoader
6- from semsql import get_viewdef
7-
8- def all_slots (schema : SchemaDefinition , cn : ClassDefinitionName ) -> List [SlotDefinitionName ]:
9- c = schema .classes [cn ]
10- slots = list (c .slots )
11- if c .is_a :
12- slots += all_slots (schema , c .is_a )
13- if c .mixins :
14- for m in c .mixins :
15- slots += all_slots (schema , m )
16- return slots
6+ from linkml_runtime .utils .formatutils import underscore
7+ from semsql .sqlutils .viewgen import get_viewdef
8+
9+
10+
1711
1812@click .command ()
1913@click .argument ('inputs' , nargs = - 1 )
@@ -32,16 +26,17 @@ def cli(inputs, name: str, index: bool):
3226 """
3327 for input in inputs :
3428 with open (input , 'r' ) as stream :
35- schema = SchemaLoader (input ).schema
36- for cn , c in schema .classes .items ():
29+ sv = SchemaView (input )
30+ schema = sv .schema
31+ for cn , c in sv .all_classes ().items ():
3732 tn = underscore (cn )
3833 if name is None or str (cn ) == name or tn == name :
39- view = get_viewdef (schema , c )
34+ view = get_viewdef (c )
4035 if view is not None :
4136 print (f'DROP VIEW { tn } ;' )
4237 print (f'CREATE TABLE { tn } AS { view } ;' )
4338 if index :
44- for sn in all_slots ( schema , cn ):
39+ for sn in sv . class_slots ( cn ):
4540 colname = underscore (sn )
4641 print (f'CREATE INDEX { tn } _{ colname } ON { tn } ({ colname } );' )
4742
0 commit comments