primary Key
Defines a PRIMARY KEY PrimaryKeyConstraint constraint on one or more KQLiteTable columns.
A PRIMARY KEY constraint uniquely identifies each record in a table. A table can have only one PRIMARY KEY, which can consist of a single column or multiple columns (a composite primary key). Primary key columns must contain UNIQUE values and cannot contain NULL values.
This function is used within the constraints block of a KQLiteTable definition. You can specify the conflict resolution strategy by chaining PrimaryKeyConstraint.onConflict on the result.
Example (Single Column Primary Key)
object Artists : KQLiteTable("artists") {
val artistId = longColumn("ArtistId").notNull()
val name = textColumn("Name")
override val constraints: (ConstraintBuilder.() -> Unit)? = {
primaryKey(artistId)
}
}Content copied to clipboard
Example (Composite Primary Key)
object PlaylistTracks : KQLiteTable("playlist_track") {
val playlistId = longColumn("PlaylistId")
val trackId = longColumn("TrackId")
override val constraints: (ConstraintBuilder.() -> Unit)? = {
primaryKey(playlistId, trackId)
}
}Content copied to clipboard
Return
A PrimaryKeyConstraint object representing the defined constraint.
Author
MOHAMMAD AZIM ANSARI
Parameters
column
Single column for primary key, multiple columns for composite key.