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

@@ -1,5 +1,11 @@
package db
import (
"context"
"github.com/jmoiron/sqlx"
)
type Index struct {
ID string
@@ -8,3 +14,40 @@ type Index struct {
Name string
Type string
}
func (i *Index) Query(data *InsertId[string]) {
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[string]) 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[string]) 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
}