|
35 | 35 | class PostgresSQLToJSONSchema(SQLToJSONSchema): |
36 | 36 | """Custom SQL to JSON Schema conversion for Postgres.""" |
37 | 37 |
|
38 | | - def __init__(self, dates_as_string: bool, json_as_object: bool, *args, **kwargs): |
| 38 | + def __init__(self, *, dates_as_string: bool, json_as_object: bool, **kwargs): |
39 | 39 | """Initialize the SQL to JSON Schema converter.""" |
40 | | - super().__init__(*args, **kwargs) |
| 40 | + super().__init__(**kwargs) |
41 | 41 | self.dates_as_string = dates_as_string |
42 | 42 | self.json_as_object = json_as_object |
43 | 43 |
|
| 44 | + @classmethod |
| 45 | + def from_config(cls, config: dict) -> PostgresSQLToJSONSchema: |
| 46 | + """Instantiate the SQL to JSON Schema converter from a config dictionary.""" |
| 47 | + return cls( |
| 48 | + dates_as_string=config["dates_as_string"], |
| 49 | + json_as_object=config["json_as_object"], |
| 50 | + ) |
| 51 | + |
44 | 52 | @functools.singledispatchmethod |
45 | 53 | def to_jsonschema(self, column_type: t.Any) -> dict: |
46 | 54 | """Customize the JSON Schema for Postgres types.""" |
@@ -132,6 +140,8 @@ def patched_conform(elem: t.Any, property_schema: dict) -> t.Any: |
132 | 140 | class PostgresConnector(SQLConnector): |
133 | 141 | """Connects to the Postgres SQL source.""" |
134 | 142 |
|
| 143 | + sql_to_jsonschema_converter = PostgresSQLToJSONSchema |
| 144 | + |
135 | 145 | def __init__( |
136 | 146 | self, |
137 | 147 | config: dict | None = None, |
@@ -160,14 +170,6 @@ def __init__( |
160 | 170 |
|
161 | 171 | super().__init__(config=config, sqlalchemy_url=sqlalchemy_url) |
162 | 172 |
|
163 | | - @functools.cached_property |
164 | | - def sql_to_jsonschema(self): |
165 | | - """Return a mapping of SQL types to JSON Schema types.""" |
166 | | - return PostgresSQLToJSONSchema( |
167 | | - dates_as_string=self.config["dates_as_string"], |
168 | | - json_as_object=self.config["json_as_object"], |
169 | | - ) |
170 | | - |
171 | 173 | def get_schema_names(self, engine: Engine, inspected: Inspector) -> list[str]: |
172 | 174 | """Return a list of schema names in DB, or overrides with user-provided values. |
173 | 175 |
|
|
0 commit comments