Skip to content

Commit

Permalink
save types and update api
Browse files Browse the repository at this point in the history
  • Loading branch information
hughhhh committed May 14, 2021
1 parent 74473e2 commit 182eb3c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
11 changes: 11 additions & 0 deletions superset-frontend/src/views/CRUD/data/database/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ type DatabaseUser = {
last_name: string;
};

type DatabaseParameters = {
database: string;
engine: string;
host: string;
password?: string;
port: number;
query: Object;
username: string;
};

export type DatabaseObject = {
// Connection + general
id?: number;
Expand All @@ -30,6 +40,7 @@ export type DatabaseObject = {
created_by?: null | DatabaseUser;
changed_on_delta_humanized?: string;
changed_on?: string;
parameters?: DatabaseParameters;

// Performance
cache_timeout?: string;
Expand Down
1 change: 1 addition & 0 deletions superset/databases/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
"allow_ctas",
"allow_cvas",
"allow_dml",
"parameters",
"force_ctas_schema",
"allow_multi_schema_metadata_fetch",
"impersonate_user",
Expand Down
18 changes: 15 additions & 3 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
from sqlalchemy.sql import expression, Select

from superset import app, db_engine_specs, is_feature_enabled
from superset.db_engine_specs.base import TimeGrain
from superset.db_engine_specs.base import BasicParametersMixin, TimeGrain
from superset.extensions import cache_manager, encrypted_field_factory, security_manager
from superset.models.helpers import AuditMixinNullable, ImportExportMixin
from superset.models.tags import FavStarUpdater
Expand Down Expand Up @@ -212,6 +212,7 @@ def data(self) -> Dict[str, Any]:
"allows_cost_estimate": self.allows_cost_estimate,
"allows_virtual_table_explore": self.allows_virtual_table_explore,
"explore_database_id": self.explore_database_id,
"parameters": self.parameters,
}

@property
Expand All @@ -222,6 +223,17 @@ def unique_name(self) -> str:
def url_object(self) -> URL:
return make_url(self.sqlalchemy_uri_decrypted)

@property
def parameters(self) -> Optional[Dict[str, Any]]:
# Build parameters if db_engine_spec is a subclass of BasicParametersMixin
parameters = {"engine": self.backend}

if issubclass(self.db_engine_spec, BasicParametersMixin):
uri = make_url(self.sqlalchemy_uri_decrypted)
return {**parameters, **self.db_engine_spec.get_parameters_from_uri(uri)}

return parameters

@property
def backend(self) -> str:
sqlalchemy_url = make_url(self.sqlalchemy_uri_decrypted)
Expand Down Expand Up @@ -568,10 +580,10 @@ def get_all_schema_names(

@property
def db_engine_spec(self) -> Type[db_engine_specs.BaseEngineSpec]:
return self.get_db_engine_spec_for_backend(self.backend)
engines = db_engine_specs.get_engine_specs()
return engines.get(self.backend, db_engine_specs.BaseEngineSpec)

@classmethod
@utils.memoized
def get_db_engine_spec_for_backend(
cls, backend: str
) -> Type[db_engine_specs.BaseEngineSpec]:
Expand Down

0 comments on commit 182eb3c

Please sign in to comment.