Add models package with embedded DB interface pattern

- internal/models/model.go: DB interface + Base struct for all models
- internal/models/channel.go: Channel model with DB access for relation queries
- Database.NewChannel() factory injects db reference into model instances
- Uses interface to avoid circular imports (models -> db)
This commit is contained in:
clawbot
2026-02-09 12:24:23 -08:00
parent 8bb083a7f8
commit 5e9be8ccaf
3 changed files with 69 additions and 8 deletions

18
internal/models/model.go Normal file
View File

@@ -0,0 +1,18 @@
package models
import "database/sql"
// DB is the interface that models use to query relations.
// This avoids a circular import with the db package.
type DB interface {
GetDB() *sql.DB
}
// Base is embedded in all model structs to provide database access.
type Base struct {
db DB
}
func (b *Base) SetDB(d DB) {
b.db = d
}