From 8768b50aededdc0470ba01d6ddd64a87c51b9506 Mon Sep 17 00:00:00 2001 From: skshetry <18718008+skshetry@users.noreply.github.com> Date: Sun, 3 Dec 2023 19:23:09 +0545 Subject: [PATCH] experimental: support connection strings for databases (#10125) * experimental: support connection strings for databases using connectorx This adds an experimental support for connector strings using connectorx. User has to provide config for the connection strings with: Example: ```console dvc config --local db_connection.pg postgres://user:pass@localhost:5432/database ``` And then, they can import using: ```console dvc import-db --sql 'query' --conn pg ``` Check supported databases and how to configure in https://sfu-db.github.io/connector-x/databases.html. This `db_connection` config is subject to change. connectorx still has the same problem with dbt as before: no support for streaming, but it'll be a bit more simpler to configure with the connection strings. * add pandas to deps * sqlalchemy * dbt streaming sql * fix test * remove connectorx * remove check in set * use mode='wb' for serialization --- dvc/commands/config.py | 40 ++--- dvc/commands/imp_db.py | 76 ++++++++++ dvc/config.py | 6 +- dvc/config_schema.py | 11 +- dvc/database/__init__.py | 22 +++ dvc/database/dbt_models.py | 40 +++++ dvc/database/dbt_query.py | 88 +++++++++++ dvc/database/dbt_runner.py | 61 ++++++++ dvc/database/dbt_utils.py | 100 ++++++++++++ dvc/database/serializer.py | 48 ++++++ dvc/database/sqla.py | 73 +++++++++ dvc/dependency/db.py | 104 +++++++------ dvc/repo/imp_db.py | 3 +- dvc/utils/db.py | 252 ------------------------------- pyproject.toml | 3 + tests/func/test_cli.py | 2 +- tests/func/test_import_db.py | 58 ++++++- tests/func/test_import_db_e2e.py | 17 ++- 18 files changed, 673 insertions(+), 331 deletions(-) create mode 100644 dvc/database/__init__.py create mode 100644 dvc/database/dbt_models.py create mode 100644 dvc/database/dbt_query.py create mode 100644 dvc/database/dbt_runner.py create mode 100644 dvc/database/dbt_utils.py create mode 100644 dvc/database/serializer.py create mode 100644 dvc/database/sqla.py delete mode 100644 dvc/utils/db.py diff --git a/dvc/commands/config.py b/dvc/commands/config.py index ff8461bc6..6cd50a780 100644 --- a/dvc/commands/config.py +++ b/dvc/commands/config.py @@ -1,6 +1,8 @@ import argparse import os +from funcy import set_in + from dvc.cli.command import CmdBaseNoRepo from dvc.cli.utils import append_doc_link from dvc.log import logger @@ -8,7 +10,7 @@ from dvc.ui import ui logger = logger.getChild(__name__) -NAME_REGEX = r"^(?Premote\.)?(?P
[^\.]*)\.(?P