default
Sets a DEFAULT value for this column.
This constraint specifies a default value to be used for the column if one is not explicitly provided during an INSERT operation. The value must be of a type compatible with the column's data type.
For date/time columns, you can use special generated values like CURRENT_DATE, CURRENT_TIME, and CURRENT_TIMESTAMP.
Example:
object Products : KQLiteTable("products") {
val id = longColumn("id").primaryKey()
val name = textColumn("name").notNull()
// Sets the default price to 0.0
val price = doubleColumn("price").notNull().default(0.0)
// Sets the default status to 'PENDING'
val status = enumColumn("status", Status.entries)
.notNull()
.default(Status.PENDING)
// Sets the default creation time to the current timestamp
val createdAt = dateTimeColumn("created_at")
.notNull()
.default(CURRENT_TIMESTAMP)
}Return
The same KQLiteColumn instance, now with a default value, to allow for further chaining of constraints.
Author
MOHAMMAD AZIM ANSARI
Parameters
The literal value to be used as the default.
Sets a DEFAULT value for this column using com.kqlite.column.Literal.
This overload is used for setting default values that are not literals, but rather are generated by SQLite at the time of insertion. This is commonly used for date and time functions.
Example:
object Logs : KQLiteTable("logs") {
val id = longColumn("id").primaryKey()
// Sets the default creation time to the current UTC timestamp
val createdAt =
dateTimeColumn("created_at")
.notNull()
.default(CURRENT_TIMESTAMP)
// Default JSON Object literal
val settings =
jsonObjectColumn("settings")
.notNull()
.default(JsonObjectLiteral("""{"color": "red", "passive": false}"""))
}Return
The same KQLiteColumn instance, now with a default value expression, to allow for further chaining of constraints.
Author
MOHAMMAD AZIM ANSARI
Parameters
A KQLiteColumn representing a generated value, such as CURRENT_TIMESTAMP.