Get back to compiling, but using new jet for publicreport
This was an epically long change, and a terrible idea, but it compiles. This was essentially a cascade that came about because I can't blend jet and bob in the same transaction. In for a penny, I guess...
This commit is contained in:
parent
a95e44cf42
commit
fcd95f1a25
65 changed files with 3129 additions and 3457 deletions
64
db/updater.go
Normal file
64
db/updater.go
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
//"github.com/go-jet/jet/v2"
|
||||
"github.com/go-jet/jet/v2/postgres"
|
||||
)
|
||||
|
||||
type Updater[T postgres.Table, M any] struct {
|
||||
Columns postgres.ColumnList
|
||||
//Columns []jet.Column
|
||||
Model M
|
||||
Table T
|
||||
|
||||
buildWhere func(pk_values ...interface{}) postgres.BoolExpression
|
||||
}
|
||||
|
||||
func (u Updater[T, M]) Execute(ctx context.Context, txn Ex, pk_values ...interface{}) error {
|
||||
statement := u.Table.
|
||||
UPDATE(u.Columns).
|
||||
MODEL(u.Model).
|
||||
WHERE(u.buildWhere(pk_values...))
|
||||
return ExecuteNoneTx(ctx, txn, statement)
|
||||
}
|
||||
func (u Updater[T, M]) Has(c postgres.Column) bool {
|
||||
for _, col := range u.Columns {
|
||||
if col == c {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
func (u *Updater[T, M]) Set(c postgres.Column) {
|
||||
u.Columns = append(u.Columns, c)
|
||||
}
|
||||
func (u *Updater[T, M]) Unset(c postgres.Column) {
|
||||
var index = -1
|
||||
for i, col := range u.Columns {
|
||||
if col == c {
|
||||
index = i
|
||||
}
|
||||
}
|
||||
if index > -1 {
|
||||
u.Columns[index] = u.Columns[len(u.Columns)-1]
|
||||
u.Columns = u.Columns[:len(u.Columns)-1]
|
||||
}
|
||||
}
|
||||
func NewUpdater[T postgres.Table, M any](
|
||||
table T,
|
||||
pk_columns ...postgres.ColumnInteger,
|
||||
) Updater[T, M] {
|
||||
return Updater[T, M]{
|
||||
Columns: postgres.ColumnList{},
|
||||
Table: table,
|
||||
buildWhere: func(pk_values ...interface{}) postgres.BoolExpression {
|
||||
conditions := make([]postgres.BoolExpression, len(pk_columns))
|
||||
for i, col := range pk_columns {
|
||||
conditions[i] = col.EQ(postgres.Int64(pk_values[i].(int64)))
|
||||
}
|
||||
return postgres.AND(conditions...)
|
||||
},
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue