fix(db_context): lazy load on uow.Begin()

This commit is contained in:
Kristian Borgwarth 2026-04-04 01:06:04 +02:00
parent b3c87e9621
commit 81c177bca2
6 changed files with 7 additions and 15 deletions

View file

@ -13,7 +13,7 @@ func main() {
server := server.NewServer()
server.RegisterHandler("initialize", handlers.NewInitializeHandler())
server.RegisterHandler("createNote", handlers.NewCreateNoteHandler())
server.RegisterHandler("create_note", handlers.NewCreateNoteHandler())
if err := server.Run(os.Stdin, os.Stdout); err != nil {
slog.Error("server error", "error", err)

View file

@ -15,7 +15,6 @@ type createNoteCommand struct {
Title string `json:"title"`
TemplatePath string `json:"templatePath"`
Path string `json:"path"`
Vars map[string]string `json:"vars"`
}
type CreateNoteHandler struct{

BIN
dendrite

Binary file not shown.

View file

@ -21,11 +21,11 @@ func InitializeDBContext(vaultPath string) (error) {
return nil
}
func GetDBContext() (*DBContext, error) {
func GetDBContext() (*DBContext) {
if dbContext == nil {
panic("DBContext is not initialized. Call InitializeDbContext first.")
}
return dbContext, nil
return dbContext
}
func CloseDBContext() error {

View file

@ -8,21 +8,17 @@ import (
)
type UnitOfWork struct {
dbContext *sql.DB
Transaction *sql.Tx
FileStore *store.FileStore
}
func NewUnitOfWork() *UnitOfWork {
db, err := persistence.GetDBContext()
if err != nil {
panic("failed to get DB context: " + err.Error())
}
return &UnitOfWork{dbContext: db.DB, FileStore: store.NewFileStore()}
return &UnitOfWork{FileStore: store.NewFileStore()}
}
func (u *UnitOfWork) Begin() (tx *sql.Tx, err error) {
tx, err = u.dbContext.Begin()
dbContext := persistence.GetDBContext()
tx, err = dbContext.DB.Begin()
if err != nil {
return nil, err
}

View file

@ -29,10 +29,7 @@ func NewDBFixture() *DBFixture {
dbPath := filepath.Join(os.TempDir(), ".index", "index.db")
dbContext, err := persistence.GetDBContext()
if err != nil {
panic("failed to get DB context: " + err.Error())
}
dbContext := persistence.GetDBContext()
return &DBFixture{
DB: dbContext.DB,