Saving complex data structures to SQL

Discussion in 'Spigot Plugin Development' started by buoobuoo, Dec 5, 2019 at 12:21 AM.

  1. Hey guys, I was just wondering if any of you guys know of a resource that Parses any data structure to something I could save to SQL.
    So for my player I have a system which you can swap out Abilities, each ability has augments to it & a level. I also have to save their Ability 'inventory' with data for their un-used abilities
  2. Strahan


    It sounds like you mean to save a serialized string to the database. You could do that (you could convert to a JSONObject), but IMO that's not the right way to leverage a database. I prefer to have explicit fields for each data value.
  3. The problem is i dont have a definite amount of fields per player, some abilities could have 12 modifiers, some just 1. So i'd rather have it into a string. I might try and use a JSONObject
  4. You'd probably be better off using MongoDB in this situation. It basically uses JSON as the structure and can easily be (de)serialized
  5. Im too lazy for this :ROFLMAO: save it in a BLOB
  6. Strahan


    That's what the R in RDBMS is for; relational :) My keys storage database stores program keys / serials for various programs. Some need just a key, some a key and username, some a key username and email. Variable fields. So I just store the program in a programs table then the data for the program in another table linked to programs by the index of the programs table entry. Then I could have any amount of data per record.

    If being able to query individual parts of the data is not important to you though, then yea, just throw it all serialized into one field.
  7. If you want to save this data, that contains 12 abilities once, 16 abilities another time then you could just serialize it with ObjectOutputStream and ObjectInputStream (writeObject, readObject)
    It would be easier with mongo or simply json serializing with Gson (Gson#fromJson etc)