Class Database

java.lang.Object
mindsdb.models.Database

public class Database extends Object
The Database class represents a database in the MindsDB system. It provides methods to interact with the database, such as querying, listing tables, getting a specific table, dropping a table, and creating tables.

The Database class can be instantiated using different constructors depending on the available information (e.g., with a Project object or a RestAPI object).

Example usage:

 
 Server server = MindsDB.connect();
 Database db = server.getDatabase("my_database");
 Query query = db.query("SELECT * FROM my_table");
 List<MDBTable> tables = db.listTables();
 MDBTable table = db.getTable("my_table");
 db.dropTable("my_table");
 MDBTable newTable = db.createTable("new_table", someDataFrame, true);
 
 
The class also overrides the toString method to provide a string representation of the Database object.
See Also:
  • Constructor Details

    • Database

      public Database(Project project, String name, String engine)
      Create a new Database object
      Parameters:
      project - - Project object
      name - - Name of the database
      engine - - Engine of the database
    • Database

      public Database(Project project, String name)
      Create a new Database object
      Parameters:
      project - - Project object
      name - - Name of the database
    • Database

      public Database(RestAPI api, String name, String engine)
      Create a new Database object
      Parameters:
      api - - RestAPI object
      name - - Name of the database
      engine - - Engine of the database
  • Method Details

    • query

      public Query query(String sql)
      Create a new Query object
      Parameters:
      sql - - SQL query string
      Returns:
      Query object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • listTables

      public List<MDBTable> listTables()
      List all tables in database
      Returns:
      List of Table objects
    • getTable

      public MDBTable getTable(String tableName)
      Get table by name
      Parameters:
      tableName - - name of table
      Returns:
      Table object
    • dropTable

      public void dropTable(String tableName)
      Drop table by name
      Parameters:
      tableName - - name of table
    • createTable

      public MDBTable createTable(String name, tech.tablesaw.api.Table df, boolean replace)
      Create a table from a query
      Parameters:
      name - - Name of the table
      df - - Table to create the table from
      replace - - Replace the table if it already exists
      Returns:
      Table
    • createTable

      public MDBTable createTable(String name, Query query, boolean replace)
      Create a table from a query
      Parameters:
      name - - Name of the table
      query - - Query to create the table from
      replace - - Replace the table if it already exists
      Returns:
      Table