diff --git a/dbt2looker/cli.py b/dbt2looker/cli.py index 35c0050..73485fa 100644 --- a/dbt2looker/cli.py +++ b/dbt2looker/cli.py @@ -95,6 +95,11 @@ def run(): default=DEFAULT_LOOKML_OUTPUT_DIR, type=str, ) + argparser.add_argument( + '--model-connection', + help='DB Connection Name for generated model files', + type=str, + ) args = argparser.parse_args() logging.basicConfig( level=getattr(logging, args.log_level), @@ -125,12 +130,14 @@ def run(): logging.info(f'Generated {len(lookml_views)} lookml views in {os.path.join(args.output_dir, "views")}') # Generate Lookml models + connection_name = args.model_connection or dbt_project_config.name lookml_models = [ - generator.lookml_model_from_dbt_model(model, dbt_project_config.name) + generator.lookml_model_from_dbt_model(model, connection_name) for model in typed_dbt_models ] for model in lookml_models: with open(os.path.join(args.output_dir, model.filename), 'w') as f: f.write(model.contents) + logging.info(f'Generated {len(lookml_models)} lookml models in {args.output_dir}') logging.info('Success') diff --git a/dbt2looker/generator.py b/dbt2looker/generator.py index ac7aa73..9b95438 100644 --- a/dbt2looker/generator.py +++ b/dbt2looker/generator.py @@ -329,11 +329,11 @@ def lookml_view_from_dbt_model(model: models.DbtModel, adapter_type: models.Supp return models.LookViewFile(filename=filename, contents=contents) -def lookml_model_from_dbt_model(model: models.DbtModel, dbt_project_name: str): +def lookml_model_from_dbt_model(model: models.DbtModel, connection_name: str): # Note: assumes view names = model names # and models are unique across dbt packages in project lookml = { - 'connection': dbt_project_name, + 'connection': connection_name, 'include': '/views/*', 'explore': { 'name': model.name,