createTable

abstract fun createTable(table: KQLiteTable)

Creates a new table in the database based on the provided table definition. This function generates and executes a CREATE TABLE SQL statement. It also automatically creates any indexes defined on the table.

The table structure, including column names, data types, constraints (like PRIMARY KEY, NOT NULL, UNIQUE, DEFAULT), and FOREIGN KEY references, is derived from the properties and constraints defined within the KQLiteTable object.

Example:

// Define a table object
object UserTable : KQLiteTable("users") {
val id = integerColumn("id").primaryKey().autoIncrement()
val name = textColumn("name").notNull()
val email = textColumn("email").unique()
}

// Create the table using the schema
schema.createTable(UserTable)

This will execute an SQL statement similar to: CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, email TEXT UNIQUE);

Author

MOHAMMAD AZIM ANSARI

Parameters

table

The KQLiteTable object that defines the structure of the table to be created.

See also

Throws

if an error occurs during table or index creation, such as a syntax error or if a table with the same name already exists.