54 lines
969 B
Go
54 lines
969 B
Go
package db
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
)
|
|
|
|
type Compatibility struct {
|
|
ID uint
|
|
|
|
Minimum string
|
|
Verified string
|
|
Maximum string
|
|
}
|
|
|
|
func (c Compatibility) Query(data *InsertId[string]) {
|
|
data.query = fmt.Sprintf(`
|
|
INSERT INTO compatibility (%s, minimum, verified, maximum)
|
|
VALUES ($1, $2, $3, $4)
|
|
RETURNING id`, data.fieldName)
|
|
}
|
|
|
|
func (c Compatibility) Insert(tx *sqlx.Tx, data *InsertId[string]) error {
|
|
if data.query == "" {
|
|
return ErrNoQuery
|
|
}
|
|
|
|
args := []any{data.id, c.Minimum, c.Verified, c.Maximum}
|
|
|
|
err := tx.QueryRow(data.query, args...).Scan(&c.ID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (c Compatibility) InsertCtx(ctx context.Context, tx *sqlx.Tx, data *InsertId[string]) error {
|
|
if data.query == "" {
|
|
return ErrNoQuery
|
|
}
|
|
|
|
args := []any{data.id, c.Minimum, c.Verified, c.Maximum}
|
|
|
|
err := tx.QueryRowContext(ctx, data.query, args...).Scan(&c.ID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|