54 lines
900 B
Go
54 lines
900 B
Go
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
)
|
|
|
|
type Index struct {
|
|
ID string
|
|
|
|
Folder string
|
|
Img string
|
|
Name string
|
|
Type string
|
|
}
|
|
|
|
func (i *Index) Query(data *InsertId[uint]) {
|
|
data.query = `
|
|
INSERT INTO index_ (pack_id, id, folder, img, name, type)
|
|
VALUES ($1, $2, $3, $4, $5, $6)
|
|
RETURNING id`
|
|
}
|
|
|
|
func (i *Index) Insert(tx *sqlx.Tx, data *InsertId[uint]) error {
|
|
if data.query == "" {
|
|
return ErrNoQuery
|
|
}
|
|
|
|
args := []any{data.id, i.ID, i.Folder, i.Img, i.Name, i.Type}
|
|
|
|
_, err := tx.Exec(data.query, args...)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (i *Index) InsertCtx(ctx context.Context, tx *sqlx.Tx, data *InsertId[uint]) error {
|
|
if data.query == "" {
|
|
return ErrNoQuery
|
|
}
|
|
|
|
args := []any{data.id, i.ID, i.Folder, i.Img, i.Name, i.Type}
|
|
|
|
_, err := tx.ExecContext(ctx, data.query, args...)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|