add setup insert methods
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
type Language struct {
|
||||
ID uint
|
||||
|
||||
@@ -15,9 +21,77 @@ type SetupLanguage struct {
|
||||
Modules []SetupLanguageModule
|
||||
}
|
||||
|
||||
func (l SetupLanguage) Insert(tx *sqlx.Tx, data *InsertId[uint]) error {
|
||||
const query = `
|
||||
INSERT INTO setup_language (setup_id, label)
|
||||
VALUES ($1, $2)
|
||||
RETURNING id`
|
||||
|
||||
args := []any{data.id, l.Label}
|
||||
|
||||
err := tx.QueryRowx(query, args...).Scan(&l.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
InsertSlice(tx, l.Modules, &InsertId[string]{id: l.ID})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l SetupLanguage) InsertCtx(ctx context.Context, tx *sqlx.Tx, data *InsertId[uint]) error {
|
||||
const query = `
|
||||
INSERT INTO setup_language (setup_id, label)
|
||||
VALUES ($1, $2)
|
||||
RETURNING id`
|
||||
|
||||
args := []any{data.id, l.Label}
|
||||
|
||||
err := tx.QueryRowxContext(ctx, query, args...).Scan(&l.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
InsertSlice(tx, l.Modules, &InsertId[string]{id: l.ID})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type SetupLanguageModule struct {
|
||||
ID string
|
||||
|
||||
Label string
|
||||
Path string
|
||||
}
|
||||
|
||||
func (l SetupLanguageModule) Insert(tx *sqlx.Tx, data *InsertId[string]) error {
|
||||
const query = `
|
||||
INSERT INTO setup_language_module (setup_language_id, label, path)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING id`
|
||||
|
||||
args := []any{data.id, l.Label, l.Path}
|
||||
|
||||
err := tx.QueryRowx(query, args...).Scan(&l.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l SetupLanguageModule) InsertCtx(ctx context.Context, tx *sqlx.Tx, data *InsertId[string]) error {
|
||||
const query = `
|
||||
INSERT INTO setup_language_module (setup_language_id, label, path)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING id`
|
||||
|
||||
args := []any{data.id, l.Label, l.Path}
|
||||
|
||||
err := tx.QueryRowxContext(ctx, query, args...).Scan(&l.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user