add setup insert methods

This commit is contained in:
lbenedar
2026-04-16 18:30:00 +03:00
parent 69d3d38ab7
commit 1b7c7e9ae3
23 changed files with 818 additions and 144 deletions

View File

@@ -1,14 +1,53 @@
package db
import (
"context"
"fmt"
"github.com/jmoiron/sqlx"
)
type Release struct {
ID uint
Generation int
Channel string
Suffix string
Build int
NodeVersion int
MaxGeneration int
MaxStableGeneration int
Time int64
Channel string
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)
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}
err := tx.QueryRowx(query, args...).Scan(&r.ID)
if err != nil {
return err
}
return nil
}
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)
args := []any{data.id, r.Generation, r.Channel, r.Suffix, r.Build, r.NodeVersion, r.MaxGeneration, r.MaxStableGeneration, r.Time}
err := tx.QueryRowxContext(ctx, query, args...).Scan(&r.ID)
if err != nil {
return err
}
return nil
}