9e6bea681f
Añade funciones Go stub para la API de Metabase en dominio infra: auth, CRUD de cards, dashboards y users, execute_query y execute_card. Incluye tipo MetabaseClient y helper HTTP compartido. Todas las funciones son impuras con stubs not-implemented.
87 lines
2.4 KiB
Markdown
87 lines
2.4 KiB
Markdown
---
|
|
name: metabase_create_card
|
|
kind: function
|
|
lang: go
|
|
domain: infra
|
|
version: "1.0.0"
|
|
purity: impure
|
|
signature: "func MetabaseCreateCard(client MetabaseClient, name string, datasetQuery map[string]any, display string, collectionID int, description string) (map[string]any, error)"
|
|
description: "Crea una nueva card/pregunta en Metabase con query SQL nativa o MBQL. Endpoint: POST /api/card."
|
|
tags: [metabase, card, question, create, api]
|
|
uses_functions: []
|
|
uses_types: [MetabaseClient_go_infra]
|
|
returns: []
|
|
returns_optional: false
|
|
error_type: "error_go_core"
|
|
imports: [fmt]
|
|
tested: false
|
|
tests: []
|
|
test_file_path: ""
|
|
file_path: "functions/infra/metabase_create_card.go"
|
|
---
|
|
|
|
## Ejemplo
|
|
|
|
```go
|
|
// Crear pregunta con SQL nativo
|
|
card, err := MetabaseCreateCard(client, "Revenue by Month", map[string]any{
|
|
"database": 1,
|
|
"type": "native",
|
|
"native": map[string]any{
|
|
"query": "SELECT date_trunc('month', created_at) as month, SUM(total) as revenue FROM orders GROUP BY 1 ORDER BY 1",
|
|
},
|
|
}, "line", 5, "Monthly revenue trend")
|
|
|
|
// Crear pregunta con MBQL (structured query)
|
|
card, err := MetabaseCreateCard(client, "Order Count", map[string]any{
|
|
"database": 1,
|
|
"type": "query",
|
|
"query": map[string]any{
|
|
"source-table": 4,
|
|
"aggregation": []any{[]any{"count"}},
|
|
},
|
|
}, "scalar", 0, "Total number of orders")
|
|
```
|
|
|
|
## Notas
|
|
|
|
### Parametros para un LLM
|
|
|
|
| Parametro | Tipo | Requerido | Descripcion |
|
|
|-----------|------|-----------|-------------|
|
|
| client | MetabaseClient | si | Cliente autenticado |
|
|
| name | string | si | Nombre de la pregunta |
|
|
| datasetQuery | map[string]any | si | Query. Ver estructura abajo |
|
|
| display | string | si | Tipo de visualizacion |
|
|
| collectionID | int | no | ID de coleccion. 0 = root collection |
|
|
| description | string | no | Descripcion. Vacio = sin descripcion |
|
|
|
|
### Estructura de datasetQuery
|
|
|
|
**SQL nativo:**
|
|
```json
|
|
{
|
|
"database": <database_id>,
|
|
"type": "native",
|
|
"native": {"query": "SELECT ..."}
|
|
}
|
|
```
|
|
|
|
**MBQL (structured):**
|
|
```json
|
|
{
|
|
"database": <database_id>,
|
|
"type": "query",
|
|
"query": {
|
|
"source-table": <table_id>,
|
|
"aggregation": [["count"]],
|
|
"breakout": [["field", <field_id>, {"temporal-unit": "month"}]],
|
|
"filter": ["=", ["field", <field_id>, null], "value"]
|
|
}
|
|
}
|
|
```
|
|
|
|
### Valores de display
|
|
|
|
table, bar, line, pie, scalar, area, row, combo, funnel, map, scatter, waterfall, progress, gauge
|