add setup insert methods
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
type CoreUpdate struct {
|
||||
ID uint
|
||||
|
||||
@@ -12,6 +19,38 @@ type CoreUpdate struct {
|
||||
WillDisableModules bool
|
||||
}
|
||||
|
||||
func (c *CoreUpdate) Insert(tx *sqlx.Tx, data *InsertId[uint]) error {
|
||||
query := fmt.Sprintf(`
|
||||
INSERT INTO core_update (%s, has_update, can_update, could_reach_website, slow_response, version, channel, will_disable_modules)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
RETURNING id`, data.fieldName)
|
||||
|
||||
args := []any{data.id, c.HasUpdate, c.CanUpdate, c.CouldReachWebsite, c.SlowResponse, c.Version, c.Channel, c.WillDisableModules}
|
||||
|
||||
err := tx.QueryRowx(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 {
|
||||
query := fmt.Sprintf(`
|
||||
INSERT INTO core_update (%s, has_update, can_update, could_reach_website, slow_response, version, channel, will_disable_modules)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
RETURNING id`, data.fieldName)
|
||||
|
||||
args := []any{data.id, c.HasUpdate, c.CanUpdate, c.CouldReachWebsite, c.SlowResponse, c.Version, c.Channel, c.WillDisableModules}
|
||||
|
||||
err := tx.QueryRowxContext(ctx, query, args...).Scan(&c.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type SystemUpdate struct {
|
||||
ID uint
|
||||
|
||||
|
||||
Reference in New Issue
Block a user