Package io.github.coho04.mysql.entities
Class Database
java.lang.Object
io.github.coho04.mysql.entities.Database
- All Implemented Interfaces:
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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.github.coho04.mysql.interfaces.QueryHelper
QueryHelper.ResultSetHandler<T>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
createTable
(String name) Creates a new table with the given name.void
createTable
(String name, String[] columns) Creates a new table with the given name and columns (if specified).void
createTable
(String name, List<String> columns) Creates a new table with the given name and columns.void
drop()
Drops the database.boolean
existsTable
(String name) Checks if a table exists in the database.getName()
Retrieves the name of the database.Retrieves a table from the database with the given name.Retrieves a list of tables from the database.void
Renames the database.void
Sets the name of the database.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.github.coho04.mysql.interfaces.QueryHelper
executeQuery, executeQuery, executeUpdate, executeUpdate
-
Constructor Details
-
Database
Creates a new instance of the Database class.- Parameters:
name
- the name of the databasemysql
- the MYSQL object used to interact with the database
-
-
Method Details
-
getName
Retrieves the name of the database.- Returns:
- the name of the database
-
setName
Sets the name of the database.- Parameters:
name
- the new name for the database
-
rename
Renames the database.- Parameters:
name
- the new name for the database
-
drop
public void drop()Drops the database. -
getTable
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
Retrieves a list of tables from the database.- Returns:
- a list of tables in the database
-
createTable
Creates a new table with the given name.- Parameters:
name
- the name of the table to create
-
createTable
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 modifycolumns
- an array of column names to add to the table (optional)
-
createTable
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 modifycolumns
- a list of column names to add to the table (optional)
-
existsTable
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
-