MySQL API 3.6

A simplified API to get you started with SQL databases

  1. Vagdedes
    Tested Minecraft Versions:
    • 1.7
    • 1.8
    • 1.9
    • 1.10
    • 1.11
    • 1.12
    • 1.13
    • 1.14
    • 1.15
    • 1.16
    • 1.17
    • 1.18
    Languages Supported:
    English
    MySQL API is a library-plugin that simplifies the process of running a database. SQL commands are replaced with methods that require a few arguments in order to execute a query.

    [/COLOR]

    Permissions
    mysql.admin - Gives your permission to /mysql command.

    Commands

    /mysql reload/rl - Reloads the configuration.
    /mysql connect - Connects the plugin to the database.
    /mysql disconnect - Disconnects the plugin from the database.
    /mysql reconnect - Resets the plugin's connection to the database.

    Config API

    Class: me.vagdedes.basic.Config
    This class will control the plugin's configuration. It is recommended to reconnect the database after configuration changes.
    Code (Text):

    void create() // Creates the config or object if doesn't exist.
    void reload() // Reloads the plugin config.
    void clear() // Clears the mysql configuration file.

    String getHost() // Returns the host.
    String getUser() // Returns the user.
    String getPassword() // Returns the password.
    String getDatabase() // Returns the database.
    String getPort() // Returns the port.
    String getDriver() // Returns the driver.
    String getTLS() // Returns the TLS version.
    Boolean getSSL() // Returns "true" if SSL connection is enabled.

    void setHost(String s) // Changes the host.
    void setUser(String s) // Changes the user
    void setPassword(String s) // Changes the password.
    void setDatabase(String s) // Changes the database.
    void setPort(String s) // Changes the port.
    void setDriver(String s) // Changes the driver.
    void setTLS(String s) // Changes the TLS version.
    void setSSL(Boolean b) // Changes the SSL connection.
     
    Basic API
    Class: me.vagdedes.mysql.MySQL
    This class contains the base methods of the API. The update() and query() methods can be used to extend the API's capabilities.
    Code (Text):

    void connect() // Connects to the database.
    void disconnect() // Disconnects from the database.
    void reconnect() // Restarts the connection to the database.
    Boolean isConnected() // Checks if the connection exists.
    void update(String command) // Excecutes an update to the database.
    ResultSet query(String command) // Returns a query from the database.
    Connection getConnection() // Returns the mysql current connection.
     
    Advanced API
    Class: me.vagdedes.mysql.SQL
    If the advanced methods of the SQL class aren't enough for your systems, you can still make your own by using MySQL's class update() and query() methods.
    Code (Text):

    void deleteTable(String table) // Deletes a table from the database.
    void truncateTable(String table) // Clears a table in the database.
    Integer countRows(String table) // Coureturns retunrs the number of rows in a table.
    Boolean tableExists(String table) // Returns if a table exists in the database.

    void set(String selected, Object object, String column, String logic_gate, String data, String table) // Updates the data of a column with your inserted object.
    SQL.set("cooldown", 5, "name", "=", "Player", "basic_table"); // Example

    void set(String selected, Object object, String where_arguments, String table) // Updates the data of a column with your inserted object based on multiple arguments.
    SQL.set("cooldown", 5, new String[]{"name=Player", "cooldown=0"}, "basic_table"); // Example

    void deleteData(String column, String logic_gate, String data, String table) // Deletes data from a table.
    SQL.deleteData("nickname", "=", "George2009", "ranks"); // Example

    void insertData(String columns, String values, String table) // Inserts data into a table.
    SQL.insertData("name, kit, cooldown", " 'Sam', 'Fisherman', '29' ", "kitpvp"); // Example

    void upsert(String selected, Object object, String column, String data, String table) // Updates the data of a column with your inserted object if it exists, or alternatively inserts a new row to the table.
    SQL.upsert("cooldown", 5, "name", "Player", "basic_table"); // Example

    Boolean exists(String column, String data, String table) // Checks if a data exists in a certain column.
    Boolean b = SQL.exists("custom_nickname", "&1J&2o&3h&4n", "player_settings"); // Example

    void createTable(String table, String columns) // Creates a new table if it doesn't already exist.
    SQL.createTable("ranks", "rank INT (11), join_date TIMESTAMP"); // Example

    Object get(String selected, String column, String logic_gate, String data, String table) // Returns an object variable owned by the selected column.
    Object o = SQL.get("kills", "uuid", "!=", "deleted_player", "pvp_stats"); // Example

    Object get(String selected, String[] where_arguments, String table) // Returns an object variable owned by the selected columns.
    Object o = SQL.get("kills", new String[]{"uuid != deleted_player", "enabled = 1"}, "pvp_stats"); // Example

    ArrayList<Object> listGet(String selected, String column, String logic_gate, String data, String table) // Returns an object variable owned by the selected column.
    ArrayList<Object> arrayList = SQL.listGet("kills", "uuid", "!=", "deleted_player", "pvp_stats"); // Example

    for (Object individual : arrayList) {
        // Do Stuff
    }

    ArrayList<Object> listGet(String selected, String[] where_arguments, String table) // Returns an object variable owned by the selected columns.
    ArrayList<Object> arrayList = SQL.listGet("kills", new String[]{"uuid != deleted_player", "enabled = 1"}, "pvp_stats"); // Example

    for (Object individual : arrayList) {
        // Do Stuff
    }
     
    Asynchronous Processing
    To process tasks asynchronously, use the following method provided by the Bukkit library.
    Code (Text):

    Bukkit.getScheduler().runTaskAsynchronously(pluginObject, () -> {
        // implement code here
    });
     
    Terms Of Use

Recent Updates

  1. Version 3.6
  2. Version 3.5
  3. Version 3.4

Recent Reviews

  1. jaylawl
    jaylawl
    4/5,
    Version: 3.5
    The only gripe i have with this, is that everything is static and you're "handicapped" into only being able to have but 1 connection at a time. Otherwise great tool :-)
    1. Vagdedes
      Author's Response
      The purpose of this API is to be simple and to get a new developer started with SQL, that's because it will probably never see multiple connection capabilities, it's too complex for them.
  2. Kidalder
    Kidalder
    5/5,
    Version: 3.5
    This API is great! Great time saver for smaller projects and the dev support is amazing, had an issue with the plugin and the dev updated it within just 1 day after they found the issue. Just a side note I wouldn't recommend this for more complex plugins that require more complex SQL commands because there are some limits to the API, But I think it is very good for setting up a simple database in very little time.
  3. hswhsw
    hswhsw
    5/5,
    Version: 3.3
    This makes me more lazy because i dont't have to make sql thingy.
    Really useful and using it well.
  4. mathiaseklund
    mathiaseklund
    5/5,
    Version: 3.3
    I like this resource very much as I am often too lazy to make my own SQL Handler when making private projects.

    Would be awesome if you could add a custom event that's fired when the SQL connection is established. :)
  5. minping
    minping
    5/5,
    Version: 3.3
    Works like magic! I love this API, but why is it prints "SQL connected" every query?
  6. hanktnt
    hanktnt
    5/5,
    Version: 3.3
    great api but can you add an example XD
    im a beginner
    thx dude
    love this api.
    1. Vagdedes
      Author's Response
      Thanks for the review. The resource's overview page is full of examples of how you can and should use this plugin.
  7. minez
    minez
    5/5,
    Version: 3.2
    Great plugin. I would like to add a full asynchronous, but this is only at the request of the author. Thanks!
    1. Vagdedes
      Author's Response
      Thanks for the review. Near the bottom of the overview page, it's explained how to execute a method asynchronously.
  8. Jochyoua
    Jochyoua
    5/5,
    Version: 3.2
    Using this with my plugin, not really used to MySQL but this API helps me a lot, really nice author and great API :)
  9. Bruce0203
    Bruce0203
    5/5,
    Version: 3.2
    This API is my first Using API.
    Really helpful nice plugin.
    Thank you for made this.
  10. Scofield__
    Scofield__
    5/5,
    Version: 3.1
    Love this API. And really helpful support. fixed an issue in 10 minutes, Keep it up 5*