cards-ajax-bootcamp
here. Feel free to navigate to the relevant files in GitHub while reading the following sections.Games
table.gameState
attribute's data type on line 10: JSON. We can use the JSON data type to break the rule of not storing data structures in a table cell. This is for the following reasons:public/script.js
. When the page loads we display a "Create Game" button. When the user clicks this button we'll create a single game in the database.script.js
create
function creates a new game record using Sequelize. When creating a new game record, we also create and shuffle a new deck and save it in the game record. The game controller has card and deck logic helper functions from previous modules.games.mjs
gameState
JSON type database column. We also had the option of creating a separate JSON column for cardDeck
and playerHand
.
The decision to keep all game state data inside a single column is a trade-off between making more SQL/Sequelize queries to get out more data and keeping your game data more structured. There is no right answer, but we felt the application was simpler to write if the game application code handled all the data inside of gameState
, instead of across different columns.
The caveat is that care must be taken so that the keys and values in gameState
are always in the correct format (e.g., playerHand
is always an array), otherwise hard to spot errors may occur.runGame
function, and renders a Deal Cards button.script.js
games.mjs