refactor(infra): split de drivers pesados a subpaquetes + fix TestSSEHandler
Mueve duckdb_open, clickhouse_open, postgres_open, matrix_* y keyring_token_store
del paquete monolitico functions/infra a subpaquetes propios
(functions/infra/{duckdb,clickhouse,postgres,matrix,keyring}). El paquete infra ya
no importa los drivers (go-duckdb, clickhouse-go, pgx, mautrix, go-keyring), por lo
que las apps que solo usan funciones ligeras (process, cron, http, sqlite) dejan de
arrastrarlos. Reduccion de binarios: dag_engine 72->10MB, registry_api 70->8.7MB,
services_api 70->9MB, call_monitor 68->6.6MB, sqlite_api 70->8.9MB.
Los IDs del registry se mantienen estables (domain: infra en frontmatter). Se
preservan los build tags goolm/libolm de matrix_crypto_init.
Tambien corrige TestSSEHandler: el test leia el body con un unico Read() que con
HTTP chunked solo capturaba el primer evento; ahora usa io.ReadAll hasta EOF.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package duckdb
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
_ "github.com/marcboeker/go-duckdb"
|
||||
)
|
||||
|
||||
// DuckDBOpen opens (or creates) a DuckDB database file.
|
||||
// Pass an empty path or ":memory:" for an in-memory database.
|
||||
// Returns a ready-to-use *sql.DB or an error.
|
||||
func DuckDBOpen(path string) (*sql.DB, error) {
|
||||
dsn := path
|
||||
if dsn == "" {
|
||||
dsn = ":memory:"
|
||||
}
|
||||
db, err := sql.Open("duckdb", dsn)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("duckdb_open: open %q: %w", dsn, err)
|
||||
}
|
||||
if err := db.Ping(); err != nil {
|
||||
db.Close()
|
||||
return nil, fmt.Errorf("duckdb_open: ping %q: %w", dsn, err)
|
||||
}
|
||||
return db, nil
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
---
|
||||
name: duckdb_open
|
||||
kind: function
|
||||
lang: go
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "func DuckDBOpen(path string) (*sql.DB, error)"
|
||||
description: "Abre (o crea) una base de datos DuckDB. Path vacio o ':memory:' abre una base en memoria."
|
||||
tags: [database, duckdb, connection, sql, analytics, pendiente-usar]
|
||||
uses_functions: []
|
||||
uses_types: [db_config_go_infra]
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: ["database/sql", "github.com/marcboeker/go-duckdb"]
|
||||
params:
|
||||
- name: path
|
||||
desc: "ruta del archivo DuckDB o vacio/:memory: para base en memoria"
|
||||
output: "conexion sql.DB abierta a DuckDB"
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "functions/infra/duckdb/duckdb_open.go"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```go
|
||||
// In-memory para analisis temporal
|
||||
db, err := DuckDBOpen("")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer DBClose(db)
|
||||
|
||||
rows, err := DBQuery(db, "SELECT * FROM read_parquet('/data/sales.parquet')")
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Usa el driver `github.com/marcboeker/go-duckdb` (CGO). DuckDB es una base de datos OLAP embebida, ideal para analisis de datos. Path vacio equivale a `:memory:`. Hace ping al abrir para detectar errores temprano.
|
||||
Reference in New Issue
Block a user