Skip to content

Commit

Permalink
fix: jeez forgot about conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
amiller68 committed Jan 25, 2024
1 parent 1f649d5 commit 5bdeeae
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions src/database/models/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,20 @@ impl Game {
// Insert the FEN into the database if it doesn't already exist
// Return the position ID
let board_fen = board.fen();

// TODO: this is super gross, but I can't figure out how to do this in one query
let position_id = sqlx::query_scalar!(
r#"INSERT INTO positions (board)
VALUES ($1)
RETURNING id as "id: Uuid"
r#"
WITH attempted_insert AS (
INSERT INTO positions (board)
VALUES ($1)
ON CONFLICT (board)
DO NOTHING
RETURNING id
)
SELECT id FROM attempted_insert
UNION ALL
SELECT id as "id: Uuid" FROM positions WHERE board = $1
LIMIT 1;
"#,
board_fen,
)
Expand Down

0 comments on commit 5bdeeae

Please sign in to comment.