The getView()
and createView()
functions let you save either an existing view or a newly created view into a variable.
Syntax
Use the getView()
method to get an existing view:
/**
* Get a view by name
*
* @param name name of the view
* @return View object
*/
public View getView(String name);
or use createView
to create a view:
/**
* Create a view
*
* @param name name of the view
* @param query Query object
* @return View object
*/
public View createView(String name, Query query);
/**
* Create a view
*
* @param name name of the view
* @param sql SQL string
* @return View object
*/
public View createView(String name, String sql);
Example
Get a view
Project mindsdb = server.getProject();
View views = mindsdb.getView("my_view");
Create a view
Query query = server.query("SELECT * FROM example_db.car_info LIMIT 50;");
View carInfoView = mindsdb.createView("car_info_view", query);
// or
View carInfoView = mindsdb.createView("car_info_view", "SELECT * FROM example_db.car_info LIMIT 50;");