3
3
from linkml_runtime .linkml_model import SchemaDefinition , ClassDefinition , SlotDefinition
4
4
from dataclasses import dataclass
5
5
6
+
7
+ def _map_dbml_type_to_linkml (dbml_type : str ) -> str :
8
+ """
9
+ Maps DBML data types to LinkML types.
10
+
11
+ :param dbml_type: The DBML column type.
12
+ :return: Corresponding LinkML type.
13
+ """
14
+ type_mapping = {
15
+ "int" : "integer" ,
16
+ "varchar" : "string" ,
17
+ "text" : "string" ,
18
+ "float" : "float" ,
19
+ "boolean" : "boolean" ,
20
+ "date" : "date" ,
21
+ "datetime" : "datetime" ,
22
+ }
23
+ return type_mapping .get (dbml_type .lower (), "string" )
24
+
25
+
6
26
@dataclass
7
27
class DbmlImportEngine (ImportEngine ):
8
28
"""
@@ -48,14 +68,14 @@ def convert(
48
68
# Handle primary key and unique constraints
49
69
primary_key_columns = [col for col in table .columns if col .primary_key ]
50
70
unique_columns = [col for col in table .columns if col .unique and not col .primary_key ]
51
- multi_column_unique_keys = table .indexes # Assuming `indexes` captures multi-column unique keys
71
+ # multi_column_unique_keys = table.indexes # Assuming `indexes` captures multi-column unique keys
52
72
53
73
# Process columns
54
74
for column in table .columns :
55
75
slot_name = column .name
56
76
slot_def = SlotDefinition (
57
77
name = slot_name ,
58
- range = self . _map_dbml_type_to_linkml (column .type ),
78
+ range = _map_dbml_type_to_linkml (column .type ),
59
79
description = column .note or f"Column '{ slot_name } '" ,
60
80
required = column in primary_key_columns or column .unique ,
61
81
identifier = column in primary_key_columns , # Mark primary key columns as identifiers
@@ -64,10 +84,10 @@ def convert(
64
84
class_def .slots .append (slot_name )
65
85
processed_slots .add (slot_name )
66
86
67
- # Add multi-column unique keys
68
- for index in multi_column_unique_keys :
69
- if index .unique :
70
- class_def .unique_keys .append ([col .name for col in index .columns ])
87
+ # # Add multi-column unique keys
88
+ # for index in multi_column_unique_keys:
89
+ # if index.unique:
90
+ # class_def.unique_keys.append([col.name for col in index.columns])
71
91
72
92
# Handle single unique column as primary key if no explicit primary key exists
73
93
if not primary_key_columns and len (unique_columns ) == 1 :
@@ -78,21 +98,3 @@ def convert(
78
98
schema .classes [table .name ] = class_def
79
99
80
100
return schema
81
-
82
- def _map_dbml_type_to_linkml (self , dbml_type : str ) -> str :
83
- """
84
- Maps DBML data types to LinkML types.
85
-
86
- :param dbml_type: The DBML column type.
87
- :return: Corresponding LinkML type.
88
- """
89
- type_mapping = {
90
- "int" : "integer" ,
91
- "varchar" : "string" ,
92
- "text" : "string" ,
93
- "float" : "float" ,
94
- "boolean" : "boolean" ,
95
- "date" : "date" ,
96
- "datetime" : "datetime" ,
97
- }
98
- return type_mapping .get (dbml_type .lower (), "string" )
0 commit comments