finish setup insert method, refactor sql migration file

This commit is contained in:
lbenedar
2026-04-17 17:33:21 +03:00
parent 1b7c7e9ae3
commit 21abe68858
47 changed files with 2054 additions and 1056 deletions

View File

@@ -14,20 +14,26 @@ type CoreUpdate struct {
CanUpdate bool
CouldReachWebsite bool
SlowResponse bool
WillDisableModules bool
Version string
Channel string
WillDisableModules bool
}
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 {
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)
if data.query == "" {
return ErrNoQuery
}
args := []any{data.id, c.HasUpdate, c.CanUpdate, c.CouldReachWebsite, c.SlowResponse, c.Version, c.Channel, c.WillDisableModules}
args := []any{data.id, c.HasUpdate, c.CanUpdate, c.CouldReachWebsite, c.SlowResponse, c.WillDisableModules, c.Version, c.Channel}
err := tx.QueryRowx(query, args...).Scan(&c.ID)
err := tx.QueryRowx(data.query, args...).Scan(&c.ID)
if err != nil {
return err
}
@@ -36,14 +42,13 @@ func (c *CoreUpdate) Insert(tx *sqlx.Tx, data *InsertId[uint]) error {
}
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)
if data.query == "" {
return ErrNoQuery
}
args := []any{data.id, c.HasUpdate, c.CanUpdate, c.CouldReachWebsite, c.SlowResponse, c.Version, c.Channel, c.WillDisableModules}
args := []any{data.id, c.HasUpdate, c.CanUpdate, c.CouldReachWebsite, c.SlowResponse, c.WillDisableModules, c.Version, c.Channel}
err := tx.QueryRowxContext(ctx, query, args...).Scan(&c.ID)
err := tx.QueryRowxContext(ctx, data.query, args...).Scan(&c.ID)
if err != nil {
return err
}