Revert "db: prepare moving to comfylite3"
This reverts commit cd1959d824
.
This commit is contained in:
parent
b90d5c7601
commit
4db333848b
|
@ -2,9 +2,9 @@ package api
|
|||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"sync"
|
||||
|
||||
"github.com/davidroman0O/comfylite3"
|
||||
"github.com/stephenafamo/bob"
|
||||
"github.com/teivah/broadcast"
|
||||
"github.com/tigorlazuardi/redmage/api/bmessage"
|
||||
|
@ -19,7 +19,7 @@ import (
|
|||
|
||||
type API struct {
|
||||
db bob.Executor
|
||||
txAble txAble
|
||||
sqldb *sql.DB
|
||||
|
||||
scheduler *scheduler.Scheduler
|
||||
|
||||
|
@ -38,7 +38,7 @@ type API struct {
|
|||
}
|
||||
|
||||
type Dependencies struct {
|
||||
DB *comfylite3.ComfyDB
|
||||
DB *sql.DB
|
||||
Config *config.Config
|
||||
Reddit *reddit.Reddit
|
||||
Publisher message.Publisher
|
||||
|
@ -55,7 +55,7 @@ func New(deps Dependencies) *API {
|
|||
|
||||
api := &API{
|
||||
db: bob.New(deps.DB),
|
||||
txAble: deps.DB,
|
||||
sqldb: deps.DB,
|
||||
downloadBroadcast: broadcast.NewRelay[bmessage.ImageDownloadMessage](),
|
||||
config: deps.Config,
|
||||
imageSemaphore: make(chan struct{}, deps.Config.Int("download.concurrency.images")),
|
||||
|
|
|
@ -2,20 +2,15 @@ package api
|
|||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/stephenafamo/bob"
|
||||
"github.com/tigorlazuardi/redmage/pkg/errs"
|
||||
)
|
||||
|
||||
type txAble interface {
|
||||
BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
|
||||
}
|
||||
|
||||
type executor func(exec bob.Executor) error
|
||||
|
||||
func (api *API) withTransaction(ctx context.Context, f executor) (err error) {
|
||||
tx, err := api.txAble.BeginTx(ctx, nil)
|
||||
tx, err := api.sqldb.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return errs.Wrapw(err, "failed to begin transaction")
|
||||
}
|
||||
|
|
22
cli/serve.go
22
cli/serve.go
|
@ -28,18 +28,12 @@ var serveCmd = &cobra.Command{
|
|||
}
|
||||
defer tele.Close()
|
||||
|
||||
database, err := db.NewComfy(cfg)
|
||||
database, err := db.Open(cfg)
|
||||
if err != nil {
|
||||
log.New(cmd.Context()).Err(err).Error("failed to open database")
|
||||
log.New(cmd.Context()).Err(err).Error("failed to open connection to database")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// database, err := db.Open(cfg)
|
||||
// if err != nil {
|
||||
// log.New(cmd.Context()).Err(err).Error("failed to open connection to database")
|
||||
// os.Exit(1)
|
||||
// }
|
||||
|
||||
pubsubDB, err := pubsub.New(cfg)
|
||||
if err != nil {
|
||||
log.New(cmd.Context()).Err(err).Error("failed to open connection to pubsub database")
|
||||
|
@ -57,18 +51,18 @@ var serveCmd = &cobra.Command{
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
// loggedDb := db.ApplyLogger(cfg, database)
|
||||
// if err != nil {
|
||||
// log.New(cmd.Context()).Err(err).Error("failed to connect database")
|
||||
// os.Exit(1)
|
||||
// }
|
||||
loggedDb := db.ApplyLogger(cfg, database)
|
||||
if err != nil {
|
||||
log.New(cmd.Context()).Err(err).Error("failed to connect database")
|
||||
os.Exit(1)
|
||||
}
|
||||
red := &reddit.Reddit{
|
||||
Client: reddit.NewRedditHTTPClient(cfg),
|
||||
Config: cfg,
|
||||
}
|
||||
|
||||
api := api.New(api.Dependencies{
|
||||
DB: database,
|
||||
DB: loggedDb,
|
||||
Config: cfg,
|
||||
Reddit: red,
|
||||
Publisher: publisher,
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
package db
|
||||
|
||||
import (
|
||||
"github.com/davidroman0O/comfylite3"
|
||||
"github.com/tigorlazuardi/redmage/config"
|
||||
"github.com/tigorlazuardi/redmage/pkg/errs"
|
||||
)
|
||||
|
||||
func NewComfy(cfg *config.Config) (*comfylite3.ComfyDB, error) {
|
||||
target := cfg.String("db.string")
|
||||
db, err := comfylite3.Comfy(comfylite3.WithPath(target))
|
||||
if err != nil {
|
||||
return db, errs.Wrapf(err, "failed to create/open comfy db at %q", target)
|
||||
}
|
||||
return db, nil
|
||||
}
|
Loading…
Reference in a new issue