make deletion easyer when linked with other objects and make gameboard url into a function

This commit is contained in:
2024-05-08 19:04:58 +02:00
parent a09c05b6ec
commit da0347731c
2 changed files with 13 additions and 5 deletions
+13 -3
View File
@@ -1,13 +1,17 @@
module default {
function is_winner_me(winner: str) -> bool
using (winner = "me");
function gameboard_url(id: uuid) -> str
using ("https://play.battlesnake.com/game/" ++ <str>id);
type GameBoard {
overloaded required id: uuid {
readonly := true;
constraint exclusive;
}
url: str {
readonly := true;
}
url := gameboard_url(.id);
required created_at: datetime {
readonly := true;
}
@@ -16,12 +20,15 @@ module default {
}
required map: str {
readonly := true;
default := "standard";
}
required single type: GameType {
readonly := true;
on source delete delete target if orphan;
}
required single ruleset: Ruleset {
readonly := true;
on source delete delete target if orphan;
}
required winner: str {
readonly := true;
@@ -32,7 +39,10 @@ module default {
}
required single snake: Snake {
readonly := true;
on source delete delete target if orphan;
}
is_winner_me := is_winner_me(.winner)
}
type GameType {
-2
View File
@@ -35,7 +35,6 @@ class EdgeDB:
self.client.query("""
insert GameBoard {
id := <uuid>$id,
url := <str>$url,
created_at := <datetime>$created_at,
turns := <int32>$turns,
map := <str>$map,
@@ -71,7 +70,6 @@ class EdgeDB:
}""",
id=game_board.id,
url=game_board.url if game_board.url else "",
created_at=datetime.fromtimestamp(game_board.now_date.timestamp(), game_board.now_date.astimezone().tzinfo),
turns=game_board.turn,
map=game_board.map if game_board.map else "standard",