edgedb: move Calculations into own type

This commit is contained in:
2024-05-05 22:05:10 +02:00
parent f00efe607f
commit 10c7f2656c
2 changed files with 20 additions and 3 deletions
+11 -1
View File
@@ -63,8 +63,9 @@ module default {
required type: str {
readonly := true;
}
calculations: array<json> {
required multi calculations: Calculations {
readonly := true;
on source delete delete target;
}
}
@@ -80,4 +81,13 @@ module default {
}
}
type Calculations {
required turn: int32 {
readonly := true;
}
required data: array<json> {
readonly := true;
}
}
}
+9 -2
View File
@@ -55,7 +55,14 @@ class EdgeDB:
snake := (
insert Snake {
type := <str>$snake_type,
calculations := <array<json>>$calculations
calculations := (
with input_data := <array <tuple <turn: int32, data: array<json>>> >$calculations
for tupel_data in array_unpack(input_data)
insert Calculations {
turn := tupel_data.turn,
data := tupel_data.data
}
)
}
)
}""",
@@ -76,7 +83,7 @@ class EdgeDB:
settings=json.dumps(game_board.ruleset["settings"]),
snake_type=game_board.snake_class.__class__.__name__,
calculations=[ json.dumps(ele) for ele in game_board.snake_class.get_history() ],
calculations=[ tuple([ele["turn"], [json.dumps(calc) for calc in ele["data"]]]) for ele in game_board.snake_class.get_history() ],
)
def save(self, game_board:GameBoard):