65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
package db
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
)
|
|
|
|
type CoreUpdate struct {
|
|
ID uint
|
|
|
|
HasUpdate bool
|
|
CanUpdate bool
|
|
CouldReachWebsite bool
|
|
SlowResponse bool
|
|
WillDisableModules bool
|
|
Version string
|
|
Channel string
|
|
}
|
|
|
|
func (c *CoreUpdate) Query(data *InsertId[uint]) {
|
|
data.query = fmt.Sprintf(`
|
|
INSERT INTO core_update (%s, has_update, can_update, could_reach_website, slow_response, will_disable_modules, version, channel)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
|
RETURNING id`, data.fieldName)
|
|
}
|
|
|
|
func (c *CoreUpdate) Insert(tx *sqlx.Tx, data *InsertId[uint]) error {
|
|
if data.query == "" {
|
|
return ErrNoQuery
|
|
}
|
|
|
|
args := []any{data.id, c.HasUpdate, c.CanUpdate, c.CouldReachWebsite, c.SlowResponse, c.WillDisableModules, c.Version, c.Channel}
|
|
|
|
err := tx.QueryRowx(data.query, args...).Scan(&c.ID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (c *CoreUpdate) InsertCtx(ctx context.Context, tx *sqlx.Tx, data *InsertId[uint]) error {
|
|
if data.query == "" {
|
|
return ErrNoQuery
|
|
}
|
|
|
|
args := []any{data.id, c.HasUpdate, c.CanUpdate, c.CouldReachWebsite, c.SlowResponse, c.WillDisableModules, c.Version, c.Channel}
|
|
|
|
err := tx.QueryRowxContext(ctx, data.query, args...).Scan(&c.ID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type SystemUpdate struct {
|
|
ID uint
|
|
|
|
HasUpdate bool
|
|
Version string
|
|
}
|