add setup insert methods
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
type GameOptions struct {
|
||||
ID uint
|
||||
|
||||
@@ -8,23 +14,95 @@ type GameOptions struct {
|
||||
Port int
|
||||
}
|
||||
|
||||
func (g *GameOptions) Insert(tx *sqlx.Tx, gameId *InsertId[uint]) error {
|
||||
query := `
|
||||
INSERT INTO featured_content (game_id, language, update_channel, port)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING id`
|
||||
|
||||
args := []any{gameId.id, g.Language, g.UpdateChannel, g.Port}
|
||||
|
||||
err := tx.QueryRowx(query, args...).Scan(&g.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *GameOptions) InsertCtx(ctx context.Context, tx *sqlx.Tx, gameId *InsertId[uint]) error {
|
||||
query := `
|
||||
INSERT INTO featured_content (game_id, language, update_channel, port)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING id`
|
||||
|
||||
args := []any{gameId.id, g.Language, g.UpdateChannel, g.Port}
|
||||
|
||||
err := tx.QueryRowxContext(ctx, query, args...).Scan(&g.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type SetupOptions struct {
|
||||
ID uint
|
||||
|
||||
CompressSocket bool
|
||||
CompressStatic bool
|
||||
CSSTheme string
|
||||
DataPath string
|
||||
Fullscreen bool
|
||||
Hostname string
|
||||
HotReload bool
|
||||
Language string
|
||||
LocalHostname string
|
||||
UpdateChannel string
|
||||
Port int
|
||||
CompressSocket bool
|
||||
CompressStatic bool
|
||||
Fullscreen bool
|
||||
HotReload bool
|
||||
ProxySSL bool
|
||||
Telemetry bool
|
||||
UpdateChannel string
|
||||
Upnp bool
|
||||
DeleteNEDB bool
|
||||
NoBackups bool
|
||||
}
|
||||
|
||||
func (s *SetupOptions) Insert(tx *sqlx.Tx, setupId *InsertId[uint]) error {
|
||||
query := `
|
||||
INSERT INTO featured_content (setup_id, compress_socket, compress_static, css_theme, data_path,
|
||||
fullscreen, hostname, hot_reload, language, local_hostname, port,
|
||||
proxy_ssl, telemetry, update_channel, upnp, delete_nedb, no_backups)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)
|
||||
RETURNING id`
|
||||
|
||||
args := []any{setupId.id, s.CompressSocket, s.CompressStatic, s.CSSTheme, s.DataPath,
|
||||
s.Fullscreen, s.Hostname, s.HotReload, s.Language, s.LocalHostname, s.Port,
|
||||
s.ProxySSL, s.Telemetry, s.UpdateChannel, s.Upnp, s.DeleteNEDB, s.NoBackups}
|
||||
|
||||
err := tx.QueryRowx(query, args...).Scan(&s.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SetupOptions) InsertCtx(ctx context.Context, tx *sqlx.Tx, setupId *InsertId[uint]) error {
|
||||
query := `
|
||||
INSERT INTO featured_content (setup_id, compress_socket, compress_static, css_theme, data_path,
|
||||
fullscreen, hostname, hot_reload, language, local_hostname, port,
|
||||
proxy_ssl, telemetry, update_channel, upnp, delete_nedb, no_backups)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)
|
||||
RETURNING id`
|
||||
|
||||
args := []any{setupId.id, s.CompressSocket, s.CompressStatic, s.CSSTheme, s.DataPath,
|
||||
s.Fullscreen, s.Hostname, s.HotReload, s.Language, s.LocalHostname, s.Port,
|
||||
s.ProxySSL, s.Telemetry, s.UpdateChannel, s.Upnp, s.DeleteNEDB, s.NoBackups}
|
||||
|
||||
err := tx.QueryRowxContext(ctx, query, args...).Scan(&s.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user