98 lines
1.8 KiB
Go
98 lines
1.8 KiB
Go
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
)
|
|
|
|
type Language struct {
|
|
ID uint
|
|
|
|
Lang string
|
|
Name string
|
|
Path string
|
|
}
|
|
|
|
type SetupLanguage struct {
|
|
ID string
|
|
|
|
Label string
|
|
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
|
|
}
|