make deletion easyer when linked with other objects and make gameboard url into a function
This commit is contained in:
+13
-3
@@ -1,13 +1,17 @@
|
|||||||
module default {
|
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 {
|
type GameBoard {
|
||||||
overloaded required id: uuid {
|
overloaded required id: uuid {
|
||||||
readonly := true;
|
readonly := true;
|
||||||
constraint exclusive;
|
constraint exclusive;
|
||||||
}
|
}
|
||||||
url: str {
|
url := gameboard_url(.id);
|
||||||
readonly := true;
|
|
||||||
}
|
|
||||||
required created_at: datetime {
|
required created_at: datetime {
|
||||||
readonly := true;
|
readonly := true;
|
||||||
}
|
}
|
||||||
@@ -16,12 +20,15 @@ module default {
|
|||||||
}
|
}
|
||||||
required map: str {
|
required map: str {
|
||||||
readonly := true;
|
readonly := true;
|
||||||
|
default := "standard";
|
||||||
}
|
}
|
||||||
required single type: GameType {
|
required single type: GameType {
|
||||||
readonly := true;
|
readonly := true;
|
||||||
|
on source delete delete target if orphan;
|
||||||
}
|
}
|
||||||
required single ruleset: Ruleset {
|
required single ruleset: Ruleset {
|
||||||
readonly := true;
|
readonly := true;
|
||||||
|
on source delete delete target if orphan;
|
||||||
}
|
}
|
||||||
required winner: str {
|
required winner: str {
|
||||||
readonly := true;
|
readonly := true;
|
||||||
@@ -32,7 +39,10 @@ module default {
|
|||||||
}
|
}
|
||||||
required single snake: Snake {
|
required single snake: Snake {
|
||||||
readonly := true;
|
readonly := true;
|
||||||
|
on source delete delete target if orphan;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is_winner_me := is_winner_me(.winner)
|
||||||
}
|
}
|
||||||
|
|
||||||
type GameType {
|
type GameType {
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ class EdgeDB:
|
|||||||
self.client.query("""
|
self.client.query("""
|
||||||
insert GameBoard {
|
insert GameBoard {
|
||||||
id := <uuid>$id,
|
id := <uuid>$id,
|
||||||
url := <str>$url,
|
|
||||||
created_at := <datetime>$created_at,
|
created_at := <datetime>$created_at,
|
||||||
turns := <int32>$turns,
|
turns := <int32>$turns,
|
||||||
map := <str>$map,
|
map := <str>$map,
|
||||||
@@ -71,7 +70,6 @@ class EdgeDB:
|
|||||||
}""",
|
}""",
|
||||||
|
|
||||||
id=game_board.id,
|
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),
|
created_at=datetime.fromtimestamp(game_board.now_date.timestamp(), game_board.now_date.astimezone().tzinfo),
|
||||||
turns=game_board.turn,
|
turns=game_board.turn,
|
||||||
map=game_board.map if game_board.map else "standard",
|
map=game_board.map if game_board.map else "standard",
|
||||||
|
|||||||
Reference in New Issue
Block a user