fix errors on insertion to game, fix db creation of game
This commit is contained in:
@@ -48,10 +48,14 @@ type World struct {
|
||||
|
||||
func (w *World) Query(data *InsertId[string]) {
|
||||
data.query = fmt.Sprintf(`
|
||||
INSERT INTO world (%s, id, title, description, version, system, background, join_theme,
|
||||
INSERT INTO world (%[1]s, id, title, description, version, system, background, join_theme,
|
||||
core_version, system_version, last_played, playtime, availability, next_session, socket,
|
||||
protected, exclusive_, persistent_storage, locked, owned, has_storage)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21)`,
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21)
|
||||
ON CONFLICT(id) DO UPDATE SET
|
||||
%[1]s = EXCLUDED.%[1]s,
|
||||
updated_at = datetime('now')
|
||||
RETURNING (created_at == updated_at) AS was_inserted`,
|
||||
data.fieldName)
|
||||
}
|
||||
|
||||
@@ -92,12 +96,16 @@ func (w *World) Insert(tx *sqlx.Tx, data *InsertId[string]) error {
|
||||
w.CoreVersion, w.SystemVersion, w.LastPlayed, w.Playtime, w.Availability, w.NextSession, w.Socket,
|
||||
w.Protected, w.Exclusive, w.PersistentStorage, w.Locked, w.Owned, w.HasStorage}
|
||||
|
||||
_, err := tx.Exec(data.query, args...)
|
||||
var isInserted bool
|
||||
err := tx.QueryRowx(data.query, args...).Scan(&isInserted)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return w.InsertObjects(tx)
|
||||
if isInserted {
|
||||
return w.InsertObjects(tx)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *World) InsertCtx(ctx context.Context, tx *sqlx.Tx, data *InsertId[string]) error {
|
||||
@@ -109,10 +117,14 @@ func (w *World) InsertCtx(ctx context.Context, tx *sqlx.Tx, data *InsertId[strin
|
||||
w.CoreVersion, w.SystemVersion, w.LastPlayed, w.Playtime, w.Availability, w.NextSession, w.Socket,
|
||||
w.Protected, w.Exclusive, w.PersistentStorage, w.Locked, w.Owned, w.HasStorage}
|
||||
|
||||
_, err := tx.ExecContext(ctx, data.query, args...)
|
||||
var isInserted bool
|
||||
err := tx.QueryRowxContext(ctx, data.query, args...).Scan(&isInserted)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return w.InsertObjects(tx)
|
||||
if isInserted {
|
||||
return w.InsertObjects(tx)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user