Package mindsdb.models
Class Database
java.lang.Object
mindsdb.models.Database
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.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncreateTable
(String name, Query query, boolean replace) Create a table from a querycreateTable
(String name, tech.tablesaw.api.Table df, boolean replace) Create a table from a queryvoid
Drop table by nameGet table by nameList all tables in databaseCreate a new Query objecttoString()
-
Constructor Details
-
Database
Create a new Database object- Parameters:
project
- - Project objectname
- - Name of the databaseengine
- - Engine of the database
-
Database
Create a new Database object- Parameters:
project
- - Project objectname
- - Name of the database
-
Database
Create a new Database object- Parameters:
api
- - RestAPI objectname
- - Name of the databaseengine
- - Engine of the database
-
-
Method Details
-
query
Create a new Query object- Parameters:
sql
- - SQL query string- Returns:
- Query object
-
toString
-
listTables
List all tables in database- Returns:
- List of Table objects
-
getTable
Get table by name- Parameters:
tableName
- - name of table- Returns:
- Table object
-
dropTable
Drop table by name- Parameters:
tableName
- - name of table
-
createTable
Create a table from a query- Parameters:
name
- - Name of the tabledf
- - Table to create the table fromreplace
- - Replace the table if it already exists- Returns:
- Table
-
createTable
Create a table from a query- Parameters:
name
- - Name of the tablequery
- - Query to create the table fromreplace
- - Replace the table if it already exists- Returns:
- Table
-