nidus-sync/db/query/comms/text_job.go

43 lines
1.4 KiB
Go
Raw Normal View History

package comms
import (
"context"
"github.com/Gleipnir-Technology/jet/postgres"
"github.com/Gleipnir-Technology/nidus-sync/db"
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/comms/model"
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/comms/table"
)
func TextJobComplete(ctx context.Context, txn db.Ex, id int64) error {
statement := table.TextJob.UPDATE(
table.TextJob.Completed,
).SET(
table.TextJob.Completed.SET(postgres.LOCALTIMESTAMP()),
).WHERE(
table.TextJob.ID.EQ(postgres.Int(id)),
)
return db.ExecuteNoneTx(ctx, txn, statement)
}
func TextJobFromID(ctx context.Context, txn db.Ex, id int64) (model.TextJob, error) {
statement := table.TextJob.SELECT(
table.TextJob.AllColumns,
).FROM(table.TextJob).
WHERE(table.TextJob.ID.EQ(postgres.Int(id)))
return db.ExecuteOneTx[model.TextJob](ctx, txn, statement)
}
func TextJobInsert(ctx context.Context, txn db.Ex, m model.TextJob) (model.TextJob, error) {
statement := table.TextJob.INSERT(
table.TextJob.MutableColumns,
).MODEL(m)
return db.ExecuteOneTx[model.TextJob](ctx, txn, statement)
}
func TextJobsWaitingFromDestination(ctx context.Context, txn db.Ex, destination string) ([]model.TextJob, error) {
statement := table.TextJob.SELECT(
table.TextJob.AllColumns,
).FROM(table.TextJob).
WHERE(table.TextJob.Destination.EQ(postgres.String(destination)).AND(
table.TextJob.Completed.IS_NULL()))
return db.ExecuteManyTx[model.TextJob](ctx, txn, statement)
}