- #Elixir ecto table names plural or singular how to#
- #Elixir ecto table names plural or singular update#
There's a similar thing going on with users - while there's no logins, I wanted to both be able to identify players throughout a session and let them set a nice, human-friendly nickname.
All games are identified by an ID, which is a random string.
#Elixir ecto table names plural or singular update#
The `GameStore` has functions to retrieve and update existing game states as well as a convenience `get_or_create` function, which returns a game if it already exists or creates a new one if it doesn't. The way it all works is that I pass `GameState` structs around, each one representing a single game. when I deploy) is definitely not ideal - but I never got to solving it. Losing the state of all games on restart (e.g. I thought trying to preserve some state across restarts might be an interesting experiment. One cool thing about ETS, though, is that it should be pretty easy to swap with DETS, which is disk-based. I might experiment with doing that later. It would've been better, probably, to isolate them so each game would have its own GenServer. It works, but it's not isolated - if anything goes wrong with a game it will affect all the others too. What I ended up with is not ideal - I have a single GenServer, called `GameStore`, responsible for reading from and writing to ETS tables. However, I also wanted to see what ETS is all about so I threw it into the mix as a learning experience. Generally a way to store some state in Elixir is a GenServer, which can store things and let other processes read and write them. Still, we do need to remember the state of the game while it’s in progress in a way that’s accessible to all players. I knew up-front there will be no need to permanently store any data.
#Elixir ecto table names plural or singular how to#
Writing Elixir is a totally different experience to Ruby and nothing really carries over in terms of how to structure your app, how to think about solving problems etc. But if you know Rails, abandon any hope of knowing anything about Phoenix, other than "how the web works". Let me tell you, the second half of that sentence is a lie.Įlixir is a nice language, it does compile to Erlang and Phoenix is a web framework for Elixir. I don't know where it was, but the first time I've heard about Phoenix was something like "Oh Elixir is just a nice language, which compiles to Erlang and Phoenix is a Rails-like web framework for Elixir".