finish setup data insertion, add world insertion

This commit is contained in:
lbenedar
2026-04-22 18:18:43 +03:00
parent 21abe68858
commit f46ff8333e
66 changed files with 2257 additions and 676 deletions

View File

@@ -62,3 +62,40 @@ type SystemUpdate struct {
HasUpdate bool
Version string
}
func (s *SystemUpdate) Query(data *InsertId[uint]) {
data.query = fmt.Sprintf(`
INSERT INTO system_update (%s, has_update, version)
VALUES ($1, $2, $3)
RETURNING id`, data.fieldName)
}
func (s *SystemUpdate) Insert(tx *sqlx.Tx, data *InsertId[uint]) error {
if data.query == "" {
return ErrNoQuery
}
args := []any{data.id, s.HasUpdate, s.Version}
err := tx.QueryRowx(data.query, args...).Scan(&s.ID)
if err != nil {
return err
}
return nil
}
func (s *SystemUpdate) InsertCtx(ctx context.Context, tx *sqlx.Tx, data *InsertId[uint]) error {
if data.query == "" {
return ErrNoQuery
}
args := []any{data.id, s.HasUpdate, s.Version}
err := tx.QueryRowxContext(ctx, data.query, args...).Scan(&s.ID)
if err != nil {
return err
}
return nil
}