Class Database

java.lang.Object
io.github.coho04.mysql.entities.Database
All Implemented Interfaces:
QueryHelper

public class Database extends Object implements QueryHelper
The Database class represents a database in a MySQL server. It provides methods to perform various operations on the database, such as renaming, dropping, creating tables, retrieving tables, checking table existence, and getting a specific table.
  • Constructor Details

    • Database

      public Database(String name, MYSQL mysql)
      Creates a new instance of the Database class.
      Parameters:
      name - the name of the database
      mysql - the MYSQL object used to interact with the database
  • Method Details

    • getName

      public String getName()
      Retrieves the name of the database.
      Returns:
      the name of the database
    • setName

      public void setName(String name)
      Sets the name of the database.
      Parameters:
      name - the new name for the database
    • rename

      public void rename(String name)
      Renames the database.
      Parameters:
      name - the new name for the database
    • drop

      public void drop()
      Drops the database.
    • getTable

      public Table getTable(String name)
      Retrieves a table from the database with the given name.
      Parameters:
      name - the name of the table to retrieve
      Returns:
      the table with the given name, or null if it does not exist
    • getTables

      public List<Table> getTables()
      Retrieves a list of tables from the database.
      Returns:
      a list of tables in the database
    • createTable

      public void createTable(String name)
      Creates a new table with the given name.
      Parameters:
      name - the name of the table to create
    • createTable

      public void createTable(String name, String[] columns)
      Creates a new table with the given name and columns (if specified). If the table does not exist, it is created with a primary key column named "id". If the table exists, it checks if the specified columns exist in the table and adds them if they don't.
      Parameters:
      name - the name of the table to create or modify
      columns - an array of column names to add to the table (optional)
    • createTable

      public void createTable(String name, List<String> columns)
      Creates a new table with the given name and columns. If the table does not exist, it is created with a primary key column named "id". If the table exists, it checks if the specified columns exist in the table and adds them if they don't.
      Parameters:
      name - the name of the table to create or modify
      columns - a list of column names to add to the table (optional)
    • existsTable

      public boolean existsTable(String name)
      Checks if a table exists in the database.
      Parameters:
      name - the name of the table to check
      Returns:
      true if the table exists, false otherwise