mirror of
https://github.com/hanzoai/agents.git
synced 2026-10-30 18:48:36 +00:00
gorm is gone from the module. The schema layer runs on hanzoai/orm/relational over hanzoai/sqlite; the query layer is untouched, because it was already raw SQL on a *sql.DB — 81 such calls against 39 gorm references in one 7000-line file. This also makes the package work cgo-free for the first time. It opened through mattn, whose cgo-free build is a stub that accepts sql.Open and fails at the first statement: `Binary was compiled with 'CGO_ENABLED=0' ... This is a stub`. Measured on the storage suite: 63 failures before, 0 now, on BOTH builds. No test that passed before fails now. The schema is unchanged where it counts. Same 30 tables. Compared index by index on what each one indexes — table, columns, uniqueness — nothing was lost. Index NAMES move to xorm's IDX_/UQE_ convention, and did_registry's uniqueness on root_did becomes a named index instead of an inline table constraint: the same guarantee, differently expressed. No FOREIGN KEY was dropped because this schema declared none. NOT NULL rises from 111 to 133 — stricter, and only on a database created fresh, since Sync2 adopts an existing one rather than rebuilding it.
36 lines
1.1 KiB
Go
36 lines
1.1 KiB
Go
package storage
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/hanzoai/orm/relational"
|
|
)
|
|
|
|
// openEngine binds the relational engine to driverName/dsn and hands its
|
|
// connection pool back to the caller as the store's only *sql.DB, so the ORM
|
|
// and the hand-written SQL in this package share one pool and one transaction
|
|
// scope. Times are read and written in UTC, matching what the raw statements
|
|
// store.
|
|
func openEngine(driverName, dsn string) (*relational.Engine, error) {
|
|
engine, err := relational.NewEngine(driverName, dsn)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to open %s engine: %w", driverName, err)
|
|
}
|
|
engine.TZLocation = time.UTC
|
|
engine.DatabaseTZ = time.UTC
|
|
return engine, nil
|
|
}
|
|
|
|
// session returns an auto-closing engine session bound to ctx.
|
|
func (ls *LocalStorage) session(ctx context.Context) (*relational.Session, error) {
|
|
if err := ctx.Err(); err != nil {
|
|
return nil, fmt.Errorf("context cancelled: %w", err)
|
|
}
|
|
if ls.engine == nil {
|
|
return nil, fmt.Errorf("relational engine is not initialized")
|
|
}
|
|
return ls.engine.Context(ctx), nil
|
|
}
|