2 ms·
Yes, I read them back as a JS object in whole on login. A few things are mandatory (hp, position) but most are optional and are only checked where needed.
by Kiro 10y ago
Yes, I read them back as a JS object in whole on login. A few things are mandatory (hp, position) but most are optional and are only checked where needed.
if (player.hasSomeProp) {
doStuff(player);
}
With your suggestion I would have a table with 200 fields and would probably have to add a lot of related tables since some of the props are arrays, objects etc. I also would lose the ability to just load the player as is (player = documentFromDB).
With "no-brainer" I mean it doesn't take any effort when developing since the representation of the player object in runtime is exactly the same as it's stored in the database.
- pythonaut_16 10y agoI don't know anything about your game but I wonder if you could use SQLite to a similar effect. If you just want things as JS objects, you could have a Player table with a column for playerID and a column for the JSON string. I'm not saying you shouldn't use Mongo/NoSQL, I just think SQLite is an interesting potential choice. (e.g. https://sqlite.org/appfileformat.html https://sqlite.org/appfileformat.html)
- elmigranto 10y agoI wasn't really suggesting anything, but if I were, Postgres and its binary JSON (`jsonb`) would be there alongside with full and easy indexing support and other SQL nicities like constraints, triggers, transactions, custom procedures, etc. There are also excellent out-of-the-box support for arrays, enums, custom types, and JS procedures if you so desire. All that comes with consistent syntax, great aggregation functions, JOINs; and all those 43 years of advancement mentioned in general. Read the docs, you'll be amazed with what you're missing :) General overview https://www.postgresql.org/docs/current/static/tutorial.html https://www.postgresql.org/docs/current/static/tutorial.html JSON support specifically https://www.postgresql.org/docs/current/static/datatype-json.html https://www.postgresql.org/docs/current/static/datatype-json...