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

@@ -20,15 +20,23 @@ type Release struct {
Suffix string
}
func (r *Release) Insert(tx *sqlx.Tx, data *InsertId[uint]) error {
query := fmt.Sprintf(`
INSERT INTO release_ (%s, generation, channel, suffix, build, node_version, max_generation, max_stable_generation, time)
func (r *Release) Query(data *InsertId[uint]) {
data.query = fmt.Sprintf(`
INSERT INTO release_ (%s, generaion, build, node_version, max_generation, max_stable_generation,
time, channel, suffix)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
RETURNING id`, data.fieldName)
}
args := []any{data.id, r.Generation, r.Channel, r.Suffix, r.Build, r.NodeVersion, r.MaxGeneration, r.MaxStableGeneration, r.Time}
func (r *Release) Insert(tx *sqlx.Tx, data *InsertId[uint]) error {
if data.query == "" {
return ErrNoQuery
}
err := tx.QueryRowx(query, args...).Scan(&r.ID)
args := []any{data.id, r.Generation, r.Build, r.NodeVersion, r.MaxGeneration, r.MaxStableGeneration,
r.Time, r.Channel, r.Suffix}
err := tx.QueryRowx(data.query, args...).Scan(&r.ID)
if err != nil {
return err
}
@@ -37,14 +45,14 @@ func (r *Release) Insert(tx *sqlx.Tx, data *InsertId[uint]) error {
}
func (r *Release) InsertCtx(ctx context.Context, tx *sqlx.Tx, data *InsertId[uint]) error {
query := fmt.Sprintf(`
INSERT INTO release_ (%s, generation, channel, suffix, build, node_version, max_generation, max_stable_generation, time)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
RETURNING id`, data.fieldName)
if data.query == "" {
return ErrNoQuery
}
args := []any{data.id, r.Generation, r.Channel, r.Suffix, r.Build, r.NodeVersion, r.MaxGeneration, r.MaxStableGeneration, r.Time}
args := []any{data.id, r.Generation, r.Build, r.NodeVersion, r.MaxGeneration, r.MaxStableGeneration,
r.Time, r.Channel, r.Suffix}
err := tx.QueryRowxContext(ctx, query, args...).Scan(&r.ID)
err := tx.QueryRowxContext(ctx, data.query, args...).Scan(&r.ID)
if err != nil {
return err
}