Feature Request: Vault Database
markhughes opened this issue ยท 1 comments
I was originally going to start my own plugin called "Bukkit Database" but thought, imagine having to put another plugin on as well as Vault.
So, why doesn't Vault add support for multiple database types. Heres what I mean:
Vault can be configured (yes, a configuration option for Vault) to use with mysql, sqlite, or flat file.
Then we use a sort of "get and set" database (similar to redis?). Heres an example of how it could work.
DatabaseProvider database = DatabaseProvider.setupDatabase("mypluginname");
database.setupCollection("houses").addCol("name", "default value here").addCol("owner", null);
So this creates a database called "mypluginname" and inside this database you can create a collection, in this case it is "houses".
With this, you can add columns to that collection "with column name here", "the default name here".
This should be runnable on plugin load, so if it was to change to this:
database.setupCollection("houses").addCol("name", "default value here").addCol("owner", null).addCol("occupants", 0);
It would realise that name exists, owner exists, but occupants does not. And therefore, it will alter the collection and add it.
Here is an example on how we could add rows.
database.insertRow("houses").col("name", "House of Craft").col("owner", "MarkehMe");
.col stands for each column (obviously) with the key and value to be inserted.
Here is an example on how we would fetch rows.
database.getRow("houses").where("name", "%Craft"); // Fetches rows from houses where column name value ends with "Craft"
database.getRow("houses").where("owner", "MarkehMe"); // Fetches rows from houses where column name value equals "MarkehMe"
It should also be possible to (somehow) migrate between different database types, so say you had a flat file database and wanted to move to a MySQL Database you could do so.
I am happy to help develop this. If not, I'll go ahead and develop BukkitDatabase! Let me know your thoughts.
For some reference, in MySQL these are ALL stored in tables. So when creating a "database" you're actually just creating a unique prefix for your tables. So the collection "houses" would actually be called "mypluginname_houses".
This would also mean the database names would be restrictive to what characters they can contain.
To increase simplicity again, allow it to work out data types itself? Depending on what the default value is. OR even setup so it's like this:
.. .addCol("stringkey", "default value here", String).addCol("integervalue", "default value here", Integer) ... // etc..