Skip to content

Commit

Permalink
feat: configure connection name (#78)
Browse files Browse the repository at this point in the history
Co-authored-by: Chaim Turkel <[email protected]>
  • Loading branch information
owlas and chaimt authored Dec 1, 2022
1 parent 9079198 commit 285bc99
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion dbt2looker/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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')
4 changes: 2 additions & 2 deletions dbt2looker/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 285bc99

Please sign in to comment.