Database#
Classes related to database endpoints
- class metabase_tools.models.database_model.DatabaseItem(*, id, name=None, description=None, features, cache_field_values_schedule, timezone=None, auto_run_queries, metadata_sync_schedule, caveats=None, is_full_sync, updated_at, native_permissions=None, details, is_sample, is_on_demand, options=None, engine, refingerprint=None, created_at, points_of_interest=None, schedules=None, cache_ttl=None, creator_id=None, initial_sync_status=None, settings=None, **extra_data)#
Database object class with related methods
- Parameters:
id (int | str) –
name (str | None) –
description (str | None) –
features (list[str]) –
cache_field_values_schedule (str) –
timezone (str | None) –
auto_run_queries (bool) –
metadata_sync_schedule (str) –
caveats (str | None) –
is_full_sync (bool) –
updated_at (datetime) –
native_permissions (str | None) –
details (dict[str, Any]) –
is_sample (bool) –
is_on_demand (bool) –
options (str | None) –
engine (str) –
refingerprint (str | None) –
created_at (datetime) –
points_of_interest (str | None) –
schedules (dict[str, Any] | None) –
cache_ttl (int | None) –
creator_id (int | None) –
initial_sync_status (str | None) –
settings (Any | None) –
extra_data (Any) –
- archive()#
Generic method for archiving an object
- Raises:
InvalidParameters – Targets and jsons are both None
- Returns:
Object of the relevant type
- Return type:
T
- Parameters:
self (T) –
- classmethod construct(_fields_set=None, **values)#
Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = ‘allow’ was set since it adds all passed values
- Parameters:
_fields_set (SetStr | None) –
values (Any) –
- Return type:
Model
- copy(*, include=None, exclude=None, update=None, deep=False)#
Duplicate a model, optionally choose which fields to include, exclude and change.
- Parameters:
include (AbstractSetIntStr | MappingIntStrAny | None) – fields to include in new model
exclude (AbstractSetIntStr | MappingIntStrAny | None) – fields to exclude from new model, as with values this takes precedence over include
update (DictStrAny | None) – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data
deep (bool) – set to True to make a deep copy of the model
self (Model) –
- Returns:
new model instance
- Return type:
Model
- delete()#
Deletes the database
- Parameters:
self (DatabaseItem) –
- Return type:
None
- dict(*, include=None, exclude=None, by_alias=False, skip_defaults=None, exclude_unset=False, exclude_defaults=False, exclude_none=False)#
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
- Parameters:
include (AbstractSetIntStr | MappingIntStrAny | None) –
exclude (AbstractSetIntStr | MappingIntStrAny | None) –
by_alias (bool) –
skip_defaults (bool | None) –
exclude_unset (bool) –
exclude_defaults (bool) –
exclude_none (bool) –
- Return type:
DictStrAny
- json(*, include=None, exclude=None, by_alias=False, skip_defaults=None, exclude_unset=False, exclude_defaults=False, exclude_none=False, encoder=None, models_as_dict=True, **dumps_kwargs)#
Generate a JSON representation of the model, include and exclude arguments as per dict().
encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().
- Parameters:
include (AbstractSetIntStr | MappingIntStrAny | None) –
exclude (AbstractSetIntStr | MappingIntStrAny | None) –
by_alias (bool) –
skip_defaults (bool | None) –
exclude_unset (bool) –
exclude_defaults (bool) –
exclude_none (bool) –
encoder (Callable[[Any], Any] | None) –
models_as_dict (bool) –
dumps_kwargs (Any) –
- Return type:
unicode
- refresh()#
Returns refreshed copy of the database
- Returns:
self
- Return type:
- Parameters:
self (DatabaseItem) –
- set_adapter(adapter)#
Sets the adapter on an object
- Parameters:
adapter (MetabaseApi) – Connection to MetabaseApi
- Return type:
None
- unarchive()#
Generic method for unarchiving an object
- Raises:
InvalidParameters – Targets and jsons are both None
- Returns:
Object of the relevant type
- Return type:
T
- Parameters:
self (T) –
- update(engine=MissingParam(), schedules=MissingParam(), refingerprint=MissingParam(), points_of_interest=MissingParam(), description=MissingParam(), name=MissingParam(), caveats=MissingParam(), cache_ttl=MissingParam(), details=MissingParam(), **kwargs)#
Updates a database using the provided parameters
- Parameters:
self (DatabaseItem) –
engine (str, optional) –
schedules (dict[str, Any], optional) –
refingerprint (bool, optional) –
points_of_interest (str, optional) –
description (str, optional) –
name (str, optional) –
caveats (str, optional) –
cache_ttl (int, optional) –
details (dict[str, Any], optional) –
kwargs (Any) –
- Returns:
DatabaseItem
- Return type:
- classmethod update_forward_refs(**localns)#
Try to update ForwardRefs on fields based on this Model, globalns and localns.
- Parameters:
localns (Any) –
- Return type:
None
Classes related to database endpoints
- class metabase_tools.endpoints.databases_endpoint.Databases(adapter)#
Database related endpoint methods
- Parameters:
adapter (MetabaseApi) –
- create(name=MissingParam(), engine=MissingParam(), details=MissingParam(), is_full_sync=MissingParam(), is_on_demand=MissingParam(), schedules=MissingParam(), auto_run_queries=MissingParam(), **kwargs)#
Create a new database
- Parameters:
name (str, optional) –
engine (str, optional) –
details (dict[str, Any], optional) –
is_full_sync (bool, optional) –
is_on_demand (bool, optional) –
schedules (dict[str, Any], optional) –
auto_run_queries (bool, optional) –
kwargs (Any) –
- Returns:
DatabaseItem
- Return type:
- get(targets=None)#
Fetch list of databases
- Parameters:
targets (list[int], optional) – If provided, the list of databases to fetch
- Returns:
list[DatabaseItem]
- Return type:
list[DatabaseItem]
- search(search_params, search_list=None)#
Method to search a list of databases meeting a list of parameters
- Parameters:
search_params (list[dict]) – Each dict contains search criteria and returns 1 result
search_list (list[DatabaseItem], optional) – Provide to search an existing list, by default pulls from API
- Returns:
List of databases of the relevant type
- Return type:
list[DatabaseItem]