phase 2 initial test

This commit is contained in:
2026-05-06 23:39:04 +02:00
parent 8592fc5d65
commit 57991e5406
17 changed files with 720 additions and 133 deletions
+31
View File
@@ -0,0 +1,31 @@
package db
import (
"fmt"
_ "github.com/lib/pq"
"xorm.io/xorm"
"xorm.io/xorm/log"
)
func Open(dataSourceName string, debug bool) (*xorm.Engine, error) {
engine, err := xorm.NewEngine("postgres", dataSourceName)
if err != nil {
return nil, fmt.Errorf("open db: %w", err)
}
if debug {
engine.SetLogLevel(log.LOG_DEBUG)
} else {
engine.SetLogLevel(log.LOG_WARNING)
}
engine.SetMaxOpenConns(25)
engine.SetMaxIdleConns(5)
if err := engine.Ping(); err != nil {
return nil, fmt.Errorf("ping db: %w", err)
}
return engine, nil
}