Documentation
¶
Index ¶
- Constants
- Variables
- func IsPIISemanticType(semanticType string) bool
- func ParseModels(s string) []string
- func RedactFieldValues(values *FieldValues)
- func RedactQueryResult(result *QueryResult)
- type Card
- type Client
- func (c *Client) DecodeJSON(resp *http.Response, v any) error
- func (c *Client) Do(req *http.Request) (*http.Response, error)
- func (c *Client) EnrichSemanticTypes(result *QueryResult, databaseID int)
- func (c *Client) ExportNativeQuery(databaseID int, sql string, format string) ([]byte, error)
- func (c *Client) ExportStructuredQuery(databaseID, tableID int, filters [][]any, limit int, format string) ([]byte, error)
- func (c *Client) Get(endpoint string, params url.Values) (*http.Response, error)
- func (c *Client) GetCard(id int) (*Card, error)
- func (c *Client) GetDashboard(id int) (*Dashboard, error)
- func (c *Client) GetDashboardParamValues(dashboardID int, paramKey string) (*ParameterValues, error)
- func (c *Client) GetDatabase(id int) (*Database, error)
- func (c *Client) GetDatabaseFields(id int) ([]Field, error)
- func (c *Client) GetDatabaseMetadata(id int) (*DatabaseMetadata, error)
- func (c *Client) GetDatabaseSchema(id int, schema string) ([]Table, error)
- func (c *Client) GetField(id int) (*Field, error)
- func (c *Client) GetFieldSummary(id int) ([]FieldSummary, error)
- func (c *Client) GetFieldValues(id int) (*FieldValues, error)
- func (c *Client) GetTable(id int) (*Table, error)
- func (c *Client) GetTableData(id int) (*QueryResult, error)
- func (c *Client) GetTableFKs(id int) ([]ForeignKey, error)
- func (c *Client) GetTableMetadata(id int) (*TableMetadata, error)
- func (c *Client) ListCards() ([]Card, error)
- func (c *Client) ListDashboards() ([]Dashboard, error)
- func (c *Client) ListDatabaseSchemas(id int) ([]string, error)
- func (c *Client) ListDatabases(includeTables bool) ([]Database, error)
- func (c *Client) ListTables() ([]Table, error)
- func (c *Client) Post(endpoint string, body any) (*http.Response, error)
- func (c *Client) RunCard(id int) (*QueryResult, error)
- func (c *Client) RunCardWithParams(id int, params map[string]string) (*QueryResult, error)
- func (c *Client) RunDashboardCard(dashboardID, dashcardID, cardID int, params map[string]string) (*QueryResult, error)
- func (c *Client) RunNativeQuery(databaseID int, sql string) (*QueryResult, error)
- func (c *Client) RunStructuredQuery(databaseID, tableID int, filters [][]any, limit int) (*QueryResult, error)
- func (c *Client) Search(query string, models []string) ([]SearchResult, error)
- func (c *Client) SearchDashboardParamValues(dashboardID int, paramKey string, query string) (*ParameterValues, error)
- type DashCard
- type DashParameter
- type DashParameterMapping
- type DashTab
- type Dashboard
- type Database
- type DatabaseMetadata
- type DatasetQuery
- type FKFieldRef
- type FKTableRef
- type Field
- type FieldSummary
- type FieldValues
- type ForeignKey
- type HTTPDoer
- type NativeQuery
- type ParameterValue
- type ParameterValues
- type QueryParameter
- type QueryResult
- type QueryResultData
- type ResultColumn
- type SearchResult
- type StructuredQuery
- type Table
- type TableMetadata
- type TemplateTag
Constants ¶
const RedactedValue = "[REDACTED]"
RedactedValue is the replacement string for redacted PII values.
Variables ¶
var UserAgent = "mb-cli/" + version.Version
Functions ¶
func IsPIISemanticType ¶ added in v0.1.3
IsPIISemanticType returns true if the given Metabase semantic type is considered PII.
func ParseModels ¶
ParseModels splits a comma-separated models string into a slice.
func RedactFieldValues ¶ added in v0.1.3
func RedactFieldValues(values *FieldValues)
RedactFieldValues replaces all values in a FieldValues struct with RedactedValue.
func RedactQueryResult ¶ added in v0.1.3
func RedactQueryResult(result *QueryResult)
RedactQueryResult replaces values in PII columns with RedactedValue.
Types ¶
type Card ¶
type Card struct {
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
DatabaseID int `json:"database_id"`
Display string `json:"display"`
QueryType string `json:"query_type,omitempty"`
CollectionID *int `json:"collection_id,omitempty"`
Archived bool `json:"archived"`
DatasetQuery *DatasetQuery `json:"dataset_query,omitempty"`
ResultMetadata []Field `json:"result_metadata,omitempty"`
VisualizationSettings map[string]any `json:"visualization_settings,omitempty"`
}
Card represents a Metabase saved question (card).
type Client ¶
Client represents the Metabase API client.
func (*Client) DecodeJSON ¶
DecodeJSON decodes a JSON response body into the provided value.
func (*Client) EnrichSemanticTypes ¶ added in v0.1.3
func (c *Client) EnrichSemanticTypes(result *QueryResult, databaseID int)
EnrichSemanticTypes fills in missing semantic types on result columns by looking up field metadata from the database. This is needed for native SQL queries where Metabase does not return semantic types in the result columns.
func (*Client) ExportNativeQuery ¶
ExportNativeQuery executes a native SQL query and returns the result in the specified export format.
func (*Client) ExportStructuredQuery ¶ added in v0.1.2
func (c *Client) ExportStructuredQuery(databaseID, tableID int, filters [][]any, limit int, format string) ([]byte, error)
ExportStructuredQuery executes an MBQL structured query and returns the result in the specified export format.
func (*Client) Get ¶
Get performs a GET request to the given endpoint with optional query parameters.
func (*Client) GetDashboard ¶ added in v0.2.0
GetDashboard retrieves a single dashboard by ID.
func (*Client) GetDashboardParamValues ¶ added in v0.2.0
func (c *Client) GetDashboardParamValues(dashboardID int, paramKey string) (*ParameterValues, error)
GetDashboardParamValues retrieves valid values for a dashboard parameter.
func (*Client) GetDatabase ¶
GetDatabase retrieves a single database by ID.
func (*Client) GetDatabaseFields ¶
GetDatabaseFields retrieves all fields in a database.
func (*Client) GetDatabaseMetadata ¶
func (c *Client) GetDatabaseMetadata(id int) (*DatabaseMetadata, error)
GetDatabaseMetadata retrieves full metadata (tables + fields) for a database.
func (*Client) GetDatabaseSchema ¶
GetDatabaseSchema retrieves tables in a specific schema of a database.
func (*Client) GetFieldSummary ¶
func (c *Client) GetFieldSummary(id int) ([]FieldSummary, error)
GetFieldSummary retrieves summary statistics for a field. The API returns pairs like [["count",2],["distincts",2]].
func (*Client) GetFieldValues ¶
func (c *Client) GetFieldValues(id int) (*FieldValues, error)
GetFieldValues retrieves distinct values for a field.
func (*Client) GetTableData ¶
func (c *Client) GetTableData(id int) (*QueryResult, error)
GetTableData retrieves raw data for a table.
func (*Client) GetTableFKs ¶
func (c *Client) GetTableFKs(id int) ([]ForeignKey, error)
GetTableFKs retrieves foreign key relationships for a table.
func (*Client) GetTableMetadata ¶
func (c *Client) GetTableMetadata(id int) (*TableMetadata, error)
GetTableMetadata retrieves table metadata with field details.
func (*Client) ListDashboards ¶ added in v0.2.0
ListDashboards retrieves all dashboards.
func (*Client) ListDatabaseSchemas ¶
ListDatabaseSchemas retrieves schema names for a database.
func (*Client) ListDatabases ¶
ListDatabases retrieves all databases. If includeTables is true, tables are included.
func (*Client) ListTables ¶
ListTables retrieves all tables.
func (*Client) RunCard ¶
func (c *Client) RunCard(id int) (*QueryResult, error)
RunCard executes a saved question and returns the query result.
func (*Client) RunCardWithParams ¶ added in v0.2.0
RunCardWithParams executes a saved question with parameter values.
func (*Client) RunDashboardCard ¶ added in v0.2.0
func (c *Client) RunDashboardCard(dashboardID, dashcardID, cardID int, params map[string]string) (*QueryResult, error)
RunDashboardCard executes a dashboard card with parameter values.
func (*Client) RunNativeQuery ¶
func (c *Client) RunNativeQuery(databaseID int, sql string) (*QueryResult, error)
RunNativeQuery executes a native SQL query against the specified database.
func (*Client) RunStructuredQuery ¶ added in v0.1.2
func (c *Client) RunStructuredQuery(databaseID, tableID int, filters [][]any, limit int) (*QueryResult, error)
RunStructuredQuery executes an MBQL structured query with filters.
func (*Client) Search ¶
func (c *Client) Search(query string, models []string) ([]SearchResult, error)
Search searches across all Metabase items.
func (*Client) SearchDashboardParamValues ¶ added in v0.2.0
func (c *Client) SearchDashboardParamValues(dashboardID int, paramKey string, query string) (*ParameterValues, error)
SearchDashboardParamValues searches dashboard parameter values.
type DashCard ¶ added in v0.2.0
type DashCard struct {
ID int `json:"id"`
CardID *int `json:"card_id,omitempty"`
Card *Card `json:"card,omitempty"`
TabID *int `json:"dashboard_tab_id,omitempty"`
ParameterMappings []DashParameterMapping `json:"parameter_mappings,omitempty"`
}
DashCard represents a card placed on a dashboard.
type DashParameter ¶ added in v0.2.0
type DashParameter struct {
ID string `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
Type string `json:"type"`
}
DashParameter represents a dashboard filter parameter.
type DashParameterMapping ¶ added in v0.2.0
type DashParameterMapping struct {
CardID int `json:"card_id,omitempty"`
ParameterID string `json:"parameter_id"`
Target []any `json:"target,omitempty"`
}
DashParameterMapping describes how a dashboard parameter maps to a card target.
type Dashboard ¶ added in v0.2.0
type Dashboard struct {
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
DashCards []DashCard `json:"dashcards,omitempty"`
Parameters []DashParameter `json:"parameters,omitempty"`
Tabs []DashTab `json:"tabs,omitempty"`
Archived bool `json:"archived"`
}
Dashboard represents a Metabase dashboard.
type Database ¶
type Database struct {
ID int `json:"id"`
Name string `json:"name"`
Engine string `json:"engine"`
Details any `json:"details,omitempty"`
Tables []Table `json:"tables,omitempty"`
}
Database represents a Metabase database.
type DatabaseMetadata ¶
type DatabaseMetadata struct {
ID int `json:"id"`
Name string `json:"name"`
Engine string `json:"engine"`
Tables []TableMetadata `json:"tables,omitempty"`
}
DatabaseMetadata represents full database metadata including tables and fields.
type DatasetQuery ¶
type DatasetQuery struct {
Database int `json:"database"`
Type string `json:"type"`
Native *NativeQuery `json:"native,omitempty"`
Query *StructuredQuery `json:"query,omitempty"`
}
DatasetQuery represents a query request to the Metabase dataset API.
type FKFieldRef ¶
type FKFieldRef struct {
ID int `json:"id"`
Name string `json:"name"`
Table FKTableRef `json:"table"`
}
FKFieldRef represents a field reference in a foreign key.
type FKTableRef ¶
FKTableRef represents a table reference in a foreign key.
type Field ¶
type Field struct {
ID int `json:"id"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
BaseType string `json:"base_type"`
DatabaseType string `json:"database_type"`
SemanticType string `json:"semantic_type,omitempty"`
TableID int `json:"table_id"`
TableName string `json:"table_name,omitempty"`
}
Field represents a Metabase field (column).
type FieldSummary ¶
FieldSummary represents summary statistics for a field.
type FieldValues ¶
FieldValues represents distinct values for a field.
type ForeignKey ¶
type ForeignKey struct {
Relationship string `json:"relationship"`
Origin FKFieldRef `json:"origin"`
Destination FKFieldRef `json:"destination"`
}
ForeignKey represents a foreign key relationship.
type NativeQuery ¶
type NativeQuery struct {
Query string `json:"query"`
TemplateTags map[string]TemplateTag `json:"template-tags,omitempty"`
}
NativeQuery represents the native SQL query part of a dataset query.
type ParameterValue ¶ added in v0.2.0
ParameterValue represents a value and optional display label for a parameter.
func (*ParameterValue) UnmarshalJSON ¶ added in v0.2.0
func (p *ParameterValue) UnmarshalJSON(data []byte) error
UnmarshalJSON supports Metabase parameter value tuples: [value] or [value, label].
type ParameterValues ¶ added in v0.2.0
type ParameterValues struct {
Values []ParameterValue `json:"values"`
HasMoreValues bool `json:"has_more_values"`
}
ParameterValues represents valid values for a dashboard parameter.
type QueryParameter ¶ added in v0.2.0
type QueryParameter struct {
ID string `json:"id"`
Type string `json:"type,omitempty"`
Target []any `json:"target,omitempty"`
Value any `json:"value"`
}
QueryParameter represents a parameter passed to a card or dashboard query.
type QueryResult ¶
type QueryResult struct {
Data QueryResultData `json:"data"`
}
QueryResult represents the result of a dataset query.
type QueryResultData ¶
type QueryResultData struct {
Columns []ResultColumn `json:"cols"`
Rows [][]any `json:"rows"`
}
QueryResultData holds the columns and rows of a query result.
type ResultColumn ¶
type ResultColumn struct {
Name string `json:"name"`
DisplayName string `json:"display_name"`
BaseType string `json:"base_type"`
SemanticType string `json:"semantic_type,omitempty"`
}
ResultColumn describes a column in a query result.
type SearchResult ¶
type SearchResult struct {
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Model string `json:"model"`
DatabaseID int `json:"database_id,omitempty"`
TableID int `json:"table_id,omitempty"`
CollectionID *int `json:"collection_id,omitempty"`
Archived bool `json:"archived"`
}
SearchResult represents an item returned by the Metabase search API.
type StructuredQuery ¶ added in v0.1.2
type StructuredQuery struct {
SourceTable any `json:"source-table"`
SourceCardID *int `json:"source-card,omitempty"`
Filter []any `json:"filter,omitempty"`
Limit int `json:"limit,omitempty"`
}
StructuredQuery represents an MBQL structured query.
type Table ¶
type Table struct {
ID int `json:"id"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
Schema string `json:"schema"`
DBId int `json:"db_id"`
EntityType string `json:"entity_type,omitempty"`
}
Table represents a Metabase table.
type TableMetadata ¶
type TableMetadata struct {
ID int `json:"id"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
Schema string `json:"schema"`
DBId int `json:"db_id"`
Fields []Field `json:"fields,omitempty"`
}
TableMetadata represents table metadata including field details.
type TemplateTag ¶ added in v0.2.0
type TemplateTag struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
DisplayName string `json:"display-name,omitempty"`
Type string `json:"type,omitempty"`
WidgetType string `json:"widget-type,omitempty"`
Required bool `json:"required,omitempty"`
}
TemplateTag represents a native query template tag.