Skip to content

Commit

Permalink
Merge pull request #372 from fishtown-analytics/dont-namespace-adapte…
Browse files Browse the repository at this point in the history
…r-funcs

add adapter funcs directly to context
  • Loading branch information
drewbanin authored Apr 10, 2017
2 parents a6554fa + 31e901e commit f1dcad4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions dbt/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ def get_compiler_context(self, model, flat_graph):
context['adapter'] = wrapper
context['flags'] = dbt.flags

context.update(wrapper.get_context_functions())

context['run_started_at'] = '{{ run_started_at }}'
context['invocation_id'] = '{{ invocation_id }}'
context['sql_now'] = adapter.date_function()
Expand Down
15 changes: 14 additions & 1 deletion dbt/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,20 @@ class DatabaseWrapper(object):
functions.
"""

context_functions = [
"already_exists",
"get_columns_in_table",
"get_missing_columns"
]

def __init__(self, model, adapter, profile):
self.model = model
self.adapter = adapter
self.profile = profile

def get_context_functions(self):
return {name: getattr(self, name) for name in self.context_functions}

def already_exists(self, schema, table):
return self.adapter.already_exists(
self.profile, schema, table, self.model.get('name'))
Expand Down Expand Up @@ -184,6 +193,8 @@ def wrap(model, project, context, injected_graph):

profile = project.run_environment()

db_wrapper = DatabaseWrapper(model, adapter, profile)

opts = {
"materialization": get_materialization(model),
"model": model,
Expand All @@ -194,7 +205,9 @@ def wrap(model, project, context, injected_graph):
"post_hooks": post_hooks,
"sql": rendered_query,
"flags": dbt.flags,
"adapter": DatabaseWrapper(model, adapter, profile),
"adapter": db_wrapper
}

opts.update(db_wrapper.get_context_functions())

return do_wrap(model, opts, injected_graph, context, project)

0 comments on commit f1dcad4

Please sign in to comment.