|
1 | | -import MSSQLConnector |
2 | | -import MariaDBConnector |
3 | | -import OracleConnector |
4 | | -import PostgresConnector |
| 1 | +from MSSQLConnector import MSSQLConnector |
| 2 | +from MariaDBConnector import MariaDBConnector |
| 3 | +from OracleConnector import OracleConnector |
| 4 | +from PostgresConnector import PostgresConnector |
5 | 5 | from SQLYExecutionError import SQLYExecutionError |
6 | | -import SQLiteConnector |
| 6 | +from SQLYUtils import SQLYUtils |
| 7 | +from SQLiteConnector import SQLiteConnector |
7 | 8 |
|
8 | 9 |
|
9 | 10 | class DatabaseConnector: |
@@ -51,3 +52,22 @@ def get_connector(db_type, connection): |
51 | 52 | if db_type not in connectors: |
52 | 53 | raise SQLYExecutionError("Unsupported database type: " + db_type) |
53 | 54 | return connectors[db_type](connection) |
| 55 | + |
| 56 | + def execute_query(self, query: dict, db_type: str, connection: Any): |
| 57 | + """ |
| 58 | + Executes a SQLY query against a specified database. |
| 59 | +
|
| 60 | + Args: |
| 61 | + query (dict): The query dictionary" |
| 62 | + db_type (str): The type of the database (e.g., "sqlite", "mariadb", "postgres", "oracle", "mssql"). |
| 63 | + connection: The connection object or parameters required to establish the database connection. |
| 64 | +
|
| 65 | + Returns: |
| 66 | + The result of the executed query. |
| 67 | +
|
| 68 | + Raises: |
| 69 | + SQLYExecutionError: If the query is invalid or an error occurs during execution. |
| 70 | + """ |
| 71 | + db_connector = DatabaseConnector.get_connector(db_type, connection) |
| 72 | + sql, params = SQLYUtils.translate_to_sql(query) |
| 73 | + return db_connector.execute(sql, params) |
0 commit comments