create View
Creates a new view in the database.
A view is a virtual table based on the result-set of an SQL statement. This function generates and executes a CREATE VIEW ... AS SELECT ... SQL statement.
The view's structure and content are defined by the provided selectStatement. The viewTable parameter is used to assign a name to the view.
Example:
// Define a table object to represent the view
object ActiveUserView : KQLiteTable("active_users_view") {
val userId = longColumn("user_id").primaryKey()
val userName = stringColumn("user_name")
val status = booleanColumn("status")
}
// Create a view that shows users with a status of 'active'
schema.createView(ActiveUserView) {
UserTable.select().where { UserTable.status EQ true }
}This will execute an SQL statement similar to: CREATE VIEW "active_users_view" AS SELECT * FROM "users" WHERE "status" = 1;
After creation, you can query the view just like a regular table.
Author
MOHAMMAD AZIM ANSARI
Parameters
The KQLiteTable object representing the view to be created. Its tableName property will be used as the name of the view.
A lambda function that returns a SelectStatement. The result set of this statement defines the view.
See also
Throws
if an error occurs during the creation of the view, such as a syntax error or if a view/table with the same name already exists.