Skip to content

Commit

Permalink
Merge pull request #14 from bachng2017/drop_database
Browse files Browse the repository at this point in the history
Drop database
  • Loading branch information
ZoranPandovski authored Dec 7, 2022
2 parents 1e0f0bc + 827e0ba commit 207bc19
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dbt/adapters/mindsdb/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def open(cls, connection):
port=credentials.port,
username=credentials.username,
password=credentials.password,
database=credentials.database
database=credentials.database,
buffered=True
)
connection.state = 'open'
connection.handle = handle
Expand Down
20 changes: 20 additions & 0 deletions dbt/adapters/mindsdb/relation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from dataclasses import dataclass

from dbt.adapters.base.relation import BaseRelation, Policy
from dbt.contracts.relation import ComponentName


@dataclass
class MindsdbQuotePolicy(Policy):
database: bool = False
schema: bool = False
identifier: bool = False


@dataclass(frozen=True, eq=False, repr=False)
class MindsdbRelation(BaseRelation):
quote_policy: MindsdbQuotePolicy = MindsdbQuotePolicy()

# Overridden as Mindsdb converts relation identifiers to lowercase
def _is_exactish_match(self, field: ComponentName, value: str) -> bool:
return self.path.get_lowered_part(field) == value.lower()
5 changes: 4 additions & 1 deletion dbt/include/mindsdb/macros/materialization/database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

-- build model
{%- call statement('main') -%}
DROP DATABASE IF EXISTS {{ database }};
CREATE DATABASE {{ database }}
{%- endcall -%}
{%- call statement('main') -%}
DROP DATABASE IF EXISTS {{ database }}
{%- endcall -%}


Expand Down
12 changes: 12 additions & 0 deletions dbt/include/mindsdb/macros/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% macro mindsdb__create_schema(relation) -%}
{%- call statement('create_schema') -%}
SELECT 1
{% endcall %}
{% endmacro %}


{% macro mindsdb__drop_schema(relation) -%}
{%- call statement('drop_schema') -%}
drop database if exists {{ relation.without_identifier() }}
{% endcall %}
{% endmacro %}

0 comments on commit 207bc19

Please sign in to comment.