diff --git a/documentation-website/Writerside/topics/DAO-Table-Types.topic b/documentation-website/Writerside/topics/DAO-Table-Types.topic
index 7bf03b8e23..214967a260 100644
--- a/documentation-website/Writerside/topics/DAO-Table-Types.topic
+++ b/documentation-website/Writerside/topics/DAO-Table-Types.topic
@@ -11,7 +11,10 @@
Apart from the core
The Exposed supports the following data types in the table definition: The The
+ The Some of the databases (e.g. MySQL, PostgreSQL, H2) support explicit ENUM types. Because keeping such columns
- in sync with
- Kotlin enumerations using only JDBC metadata could be a huge challenge, Exposed doesn't provide a
- possibility to manage
- such columns in an automatic way, but that doesn't mean that you can't use such column types. You have two options to work with ENUM database types and you should use
+ Some databases (e.g. MySQL, PostgreSQL, H2) support explicit enum types. Because keeping such columns
+ in sync with Kotlin enumerations using only JDBC metadata could be a huge challenge, Exposed doesn't
+ provide a possibility to manage such columns in an automatic way, but that doesn't mean that you can't
+ use such column types.
+
+ To work with enum database types, use the
+
+ As a JDBC driver can provide/expect specific classes for ENUM types, you must also provide from/to
- transformation functions for
- them when defining a For a class like
+ As a JDBC driver can provide/expect specific classes for enum types, you must also provide from/to
+ transformation functions for them when defining a custom enumeration.
+
+ For a class like PostgreSQL requires that ENUM is defined as a separate type, so you have to create it before creating
+ PostgreSQL requires that enum is defined as a separate type, so you have to create it before creating
your table.
Also, the PostgreSQL JDBC driver returns Add the following dependencies to your
+ Add the following dependencies to your
+ Here's an example that leverages kotlinx.serialization
+
+ Here's an example that leverages
+
+ JSON path strings can be used to extract values (either as JSON or as a scalar value) at a specific
field/key: The JSON functions The JSON functions
+
+ JSON columns also accept JSON arrays as input values. For example, using the serializable data class
PostgreSQL and H2 databases support the explicit ARRAY data type,
- with multi-dimensional arrays being supported by PostgreSQL. PostgreSQL and H2 databases support the explicit array data type,
+ with multidimensional arrays being supported by PostgreSQL. Exposed allows defining columns as arrays, with the stored contents being any out-of-the-box or custom data type.
If the contents are of a type with a supported A single element in a stored array can be accessed using the index reference A new subarray can also be accessed by using
+ A new subarray can also be accessed by using
+
+ In the case of multidimensional arrays, the In the case of multidimensional arrays, the Both arguments for these bounds are optional if using PostgreSQL. An array column can also be used as an argument for the
+ An array column can also be used as an argument for the If a database-specific data type is not immediately supported by Exposed, any existing and open column type
- class can be extended or
- a custom
+ If a database-specific data type is not immediately supported by Exposed, any existing and open column type
+ class can be extended, or a custom
+
+ The following examples describe different ways to customize a column type, register a column with the custom
type,
and then start using it in transactions. The
+ The
+
+ Transformation could be also defined as an implementation of Transformation could be also defined as an implementation of the
+
+
- Special case is
diff --git a/documentation-website/Writerside/topics/SQL-Functions.md b/documentation-website/Writerside/topics/SQL-Functions.md
index e8ff51c155..746ebd1192 100644
--- a/documentation-website/Writerside/topics/SQL-Functions.md
+++ b/documentation-website/Writerside/topics/SQL-Functions.md
@@ -20,36 +20,48 @@ val fullNames = FooTable.select(trimmedAndLoweredFullName).map { it[trimmedAndLo
```
## String functions
-### LowerCase/UpperCase
-Returns a lower-cased/upper-cased string value.
+### Lower case and upper case
+To convert a string expression to lower-case or upper-case, use the [`.lowerCase()`](https://jetbrains.github.io/Exposed/api/exposed-core/org.jetbrains.exposed.sql/lower-case.html)
+and
+[`.upperCase()`](https://jetbrains.github.io/Exposed/api/exposed-core/org.jetbrains.exposed.sql/upper-case.html)
+functions respectively.
+
```kotlin
val lowerCasedName = FooTable.name.lowerCase()
val lowerCasedNames = FooTable.select(lowerCasedName).map { it[lowerCasedName] }
```
### Substring
-Returns a substring value from the specified start and with the specified length.
+The [.substring()](https://jetbrains.github.io/Exposed/api/exposed-core/org.jetbrains.exposed.sql/substring.html)
+function returns a substring value from the specified start and with the specified length.
+
```kotlin
val shortenedName = FooTable.name.substring(start = 1, length = 3)
val shortenedNames = FooTable.select(shortenedName).map { it[shortenedName] }
```
-### Concat
-Returns a string value that concatenates the text representations of all non-null input values, separated by an optional separator.
+### Concatenate
+The [concat()](https://jetbrains.github.io/Exposed/api/exposed-core/org.jetbrains.exposed.sql/-i-sql-expression-builder/concat.html)
+function returns a string value that concatenates the text representations of all non-null input values, separated by an optional separator.
+
```kotlin
val userName = concat(stringLiteral("User - "), FooTable.name)
val userNames = FooTable.select(userName).map { it[userName] }
```
### Locate
-Returns the index of the first occurrence of a specified substring or 0.
+The [.locate()](https://jetbrains.github.io/Exposed/api/exposed-core/org.jetbrains.exposed.sql/locate.html)
+function returns the index of the first occurrence of a specified substring or 0.
+
```kotlin
val firstAIndex = FooTable.name.locate("a")
val firstAIndices = FooTable.select(firstAIndex).map { it[firstAIndex] }
```
-### CharLength
-Returns the length, measured in characters, or `null` if the String value is null.
+### Character length
+The [.charLength()](https://jetbrains.github.io/Exposed/api/exposed-core/org.jetbrains.exposed.sql/char-length.html)
+function returns the length, measured in characters, or `null` if the String value is null.
+
```kotlin
val nameLength = FooTable.name.charLength()
val nameLengths = FooTable.select(nameLength).map { it[nameLength] }
@@ -59,7 +71,12 @@ val nameLengths = FooTable.select(nameLength).map { it[nameLength] }
## Aggregating functions
These functions should be used in queries with [groupBy](DSL-Querying-data.topic#group-by).
### Min/Max/Average
-Returns minimum/maximum/average value and can be applied to any comparable expression:
+To get the minimum, maximum, and average values, use the
+[.min()](https://jetbrains.github.io/Exposed/api/exposed-core/org.jetbrains.exposed.sql/min.html)
+[.max()](https://jetbrains.github.io/Exposed/api/exposed-core/org.jetbrains.exposed.sql/max.html)
+and [.avg](https://jetbrains.github.io/Exposed/api/exposed-core/org.jetbrains.exposed.sql/avg.html) functions
+respectively. These functions can be applied to any comparable expression:
+
```kotlin
val minId = FooTable.id.min()
val maxId = FooTable.id.max()
@@ -88,9 +105,9 @@ val replacedName = CustomFunction
- To define a schema in Exposed, use the
- To create a new schema, use the If you have many schemas, and you want to set a default one, you can use the If you have many schemas, and you want to set a default one, you can use the
+
+
- To drop a schema, use the
- A database table is represented by an object inherited from a table class.
+ A database table is represented by an object inherited from a
To configure a custom name for a table, which will be used in actual SQL queries, pass it to the The
+ The For example, to make the population column
+ For example, to make the population column nullable, use the following code:
+ Table
class, Exposed provides the base
- IdTable
class and its subclasses through the DAO API.
+
+ IdTable
+
+ class and its subclasses through the DAO API.
IdTable
class extends Table
and is
diff --git a/documentation-website/Writerside/topics/Data-Types.topic b/documentation-website/Writerside/topics/Data-Types.topic
index 0904e208c8..663c984f6c 100644
--- a/documentation-website/Writerside/topics/Data-Types.topic
+++ b/documentation-website/Writerside/topics/Data-Types.topic
@@ -6,44 +6,119 @@
-
+ integer
- translates to DB INT
short
- translates to DB SMALLINT
long
- BIGINT
float
- FLOAT
decimal
- DECIMAL
with scale and precisionbool
- BOOLEAN
char
- CHAR
varchar
- VARCHAR
with lengthtext
- TEXT
enumeration
- INT
ordinal valueenumerationByName
- VARCHAR
customEnumeration
- see additional sectionblob
- BLOB
binary
- VARBINARY
with lengthuuid
- BINARY(16)
reference
- a foreign keyarray
- ARRAY
integer
INT
+ short
SMALLINT
+ long
BIGINT
+ float
FLOAT
+ decimal
DECIMAL
with scale and precision
+ bool
BOOLEAN
+ char
CHAR
+ varchar
VARCHAR
with length
+ text
TEXT
+ enumeration
INT
ordinal value
+ enumerationByName
VARCHAR
+ customEnumeration
blob
BLOB
+ binary
VARBINARY
with length
+ uuid
BINARY(16)
+ reference
array
ARRAY
+ exposed-java-time
extension
(org.jetbrains.exposed:exposed-java-time:$exposed_version
) provides additional types:
-
+ date
- DATETIME
time
- TIME
datetime
- DATETIME
timestamp
- TIMESTAMP
duration
- DURATION
date
DATETIME
+ time
TIME
+ datetime
DATETIME
+ timestamp
TIMESTAMP
+ duration
DURATION
+ exposed-json
extension (org.jetbrains.exposed:exposed-json:$exposed_version
)
- provides additional types
- (see how to use):
-
+ json
- JSON
jsonb
- JSONB
exposed-json
extension (org.jetbrains.exposed:exposed-json:$exposed_version
)
+ provides the following additional types. For more information, see
+
+ :
+ json
JSON
+ jsonb
JSONB
+ customEnumeration()
- (available since version 0.10.3) in both cases:.customEnumeration()
+
+ function in one of the following ways:
+
-
- sql
parameter in customEnumeration()
+ sql
parameter in .customEnumeration()
can be left as null
.
sql
- parameter in customEnumeration()
.
+ sql
+ parameter in .customEnumeration()
.
customEnumeration
.enum class Foo { BAR, BAZ }
, you can use the provided code below for your
- specific database:enum class Foo { BAR, BAZ }
, you can use the following code for your
+ specific database:
+ PGobject
instances for such values, so a PGobject
with its type manually set to the ENUM type needs to be used for the toDb
parameter.
@@ -124,8 +211,11 @@
build.gradle.kts
:kotlinx.serialization
+
to support
@Serializable
classes. It uses a simpler form of json()
that relies on the
library's KSerializer
interface:.name
and .language
respectively.
- exists()
and contains()
are currently supported as well:.exists()
+
+ and
+
+ .contains()
+
+ are currently supported as well:
+ Project
from the
example above, the following details some ways to create such a column:ColumnType
in the exposed-core
module,
@@ -318,7 +421,7 @@
} } }
}
- get()
operator:
slice()
, which takes a lower and upper bound
- (inclusive):.slice()
+
+ , which takes a lower and upper bound
+ (inclusive):
+ slice()
calls can be nested:.slice()
calls can be nested:ANY
and ALL
SQL
- operators, either by providing the entire column or a new array expression via slice()
:ANY
and ALL
SQL
+ operators, either by providing the entire column or a new array expression via .slice()
:
+ ColumnType
class can be implemented to achieve the same functionality.ColumnType
+
+ class can be implemented to achieve the same functionality.
+ transform
function is used to apply custom transformations to the mealTime
- column:.transform()
+
+ function is used to apply custom transformations to the mealTime
+ column:
+
-
- wrap
function transforms the stored LocalTime
values into
+ wrap()
function transforms the stored LocalTime
values into
Meal
enums. It checks the hour of the stored time and returns the corresponding meal type.
unwrap
function transforms Meal
enums back into LocalTime
+ unwrap()
function transforms Meal
enums back into LocalTime
values for storage in the database.
ColumnTransformer
interface and
- reused among different tables:ColumnTransformer
+
+ interface and reused across different tables:
+ nullTransform()
method.
- That method applies a special transformation that allows a non-nullable database column
- to accept and/or return values as `null` on the client side.
+ The
+
+ .nullTransform()
+
+ method applies a special transformation that allows a non-nullable database column
+ to accept and/or return values as null
on the client side.
Schema
class:
+ To define a schema in Exposed, use the
+
+ Schema
+
+ class:
createSchema()
method provided by SchemaUtils
:
+ To create a new schema, use the
+
+ .createSchema()
+
+ method provided by SchemaUtils
:
setSchema()
+ .setSchema()
+
method from SchemaUtils
:
dropSchema()
method provided by SchemaUtils
:
+ To drop a schema, use the
+
+ .dropSchema()
+
+ method provided by SchemaUtils
:
Table
class.
name
- parameter of the Table()
constructor.
+ parameter of the Table
constructor.
NOT NULL
SQL constraint restricts the column to accept the null
value. By
+ NOT NULL
SQL constraint restricts the column to accept the null
value. By
default, Exposed applies this constraint to
- all the columns. To allow the column to be nullable, apply the nullable()
method to a
- definition of an appropriate column.nullable
, use the following code:.nullable()
+
+ method to a definition of an appropriate column.
default(defaultValue: T)
accepts a value with a type of the column.defaultExpression(defaultValue: Expression<T>)
accepts an expression.clientDefault(defaultValue: () -> T)
accepts a function.default(defaultValue: T)
+
+ accepts a value with a type of the column.
+ defaultExpression(defaultValue: Expression<T>)
+
+ accepts an expression.
+ clientDefault(defaultValue: () -> T)
+
+ accepts a function.
+ For example, to configure the default value for the name
column, use the following code:
+ For example, to configure the default value for the name
column, use the following code:
+
TRIGGER
+ or with a DEFAULT
clause, for example.
For example:
The INDEX
SQL constraint makes traversing through tables quicker. Exposed supports the
- index()
method.
- It has six parameters, most of which are optional:
val customIndexName: String? = null
is a custom name for the index, which will be used
- in actual SQL queries.
- val unique: Boolean
defines whether the index is unique or not.val columns: List<Column<*>>
defines a column set.val functions: List<ExpressionWithColumnType<*>>? = null
defines functional
- key parts.
- val indexType: String? = null
is a custom type. Can be "BTREE"
- or "HASH"
.
- val filterCondition: (SqlExpressionBuilder.() -> Op<Boolean>)? = null
defines
- a condition used to create a partial index.
-
+ The INDEX
SQL constraint makes traversing through tables quicker. Exposed supports the
+
+ .index()
+
+ method. It has six parameters, most of which are optional:
+
customIndexName: String? = null
unique: Boolean
columns: List<Column<*>>
functions: List<ExpressionWithColumnType<*>>? = null
indexType: String? = null
"BTREE"
or "HASH"
.
+ filterCondition: (SqlExpressionBuilder.() -> Op<Boolean>)? = null
The simplest way to create an index is to use an extension function directly on a column. For example, to
apply a non-unique
INDEX
constraint to the name
column, use the following code:
If the parameter customIndexName
is not set, the name of the index is determined by the
- table and column names.
Also, Exposed supports complex indexes. If you have a frequent query for two columns, Exposed can perform
- it more efficiently.
- It creates a tree from the first column with the references to the second one. For example, to create a
- non-unique complex
- index on the name
and population
columns, paste the following code:
+ If the customIndexName
parameter is not set, the name of the index is determined by the
+ table and column names.
+
+ If you have a frequent query for two columns, Exposed can perform it more efficiently.
+ It creates a tree from the first column with the references to the second one. For example,
+ to create a non-unique complex index on the name
and population
columns,
+ paste the following code:
+
+ Exposed also supports creating an index with a custom type. For example, to retrieve data from the
+ name
column faster with a hash function for traversing, use the following code:
+
Exposed also supports creating an index with a custom type. For example, to retrieve data from the name
- column faster
- with a hash function for traversing, use the following code:
Some databases support functional key parts that index expressions instead of columns directly:
Operator expressions, like plus()
, are also accepted by the functions
- parameter.
Some databases support creating a partial index by defining a filter expression to improve querying - performance. The - created index will only contain entries for the table rows that match this predicate:
- +
+ Operator expressions, like plus()
, are also accepted by the functions
+ parameter.
+
+ Some databases support creating a partial index by defining a filter expression to improve querying + performance. The created index will only contain entries for the table rows that match this predicate: +
Once a table has been created, the list of its indices can be accessed using the property Table.indices
.
- Table indices
- are represented by the data class Index
, so its properties can be checked in the following
- manner, for example:
+ Once a table has been created, the list of its indices can be accessed using the property
+ Table.indices
. Table indices are represented by the data class
+
+ Index
+
+ , so its properties can be checked in the following way:
Index
data class can be created directly using its public constructor,
for the purpose of
@@ -231,28 +280,35 @@
The UNIQUE
SQL constraint restricts duplicates within this column. Exposed supports the
- uniqueIndex()
method which
- creates a unique index for the column. This method is the composition of UNIQUE
and INDEX
- constraint, the quicker
- modification of UNIQUE
constraint.
For example, to apply UNIQUE
and INDEX
constraint to the name
- column, use the following code:
+ The UNIQUE
SQL constraint restricts duplicates within this column. Exposed supports the
+
+ .uniqueIndex()
+
+ method which creates a unique index for the column. This method is the composition of
+ UNIQUE
and INDEX
constraint, the quicker modification of UNIQUE
+ constraint.
+
+ For example, to apply UNIQUE
and INDEX
constraint to the name
+ column, use the following code:
+
The PRIMARY KEY
SQL constraint applied to a column means each value in that column
+
+ The PRIMARY KEY
SQL constraint applied to a column means each value in that column
identifies the row. This constraint is the composition
of NOT NULL
and UNIQUE
constraints. To change the column set, add columns, or
- change the primary key name to a custom one, override this field of the table class.
For example, to define the name
column as the primary key, use the following code. The
- "Cities_name" string
- will be used as the constraint name in the actual SQL query, if provided; otherwise a name will be
- generated based on the table's name.
+ For example, to define the name
column as the primary key, use the following code. The
+ "Cities_name" string will be used as the constraint name in the actual SQL query, if provided;
+ otherwise a name will be generated based on the table's name.
+
It is also possible to define a primary key on a table using multiple columns:
- ++ It is also possible to define a primary key on a table using multiple columns: +
Except for CompositeIdTable
, each available class in Exposed that inherits from IdTable
+
+ Except for CompositeIdTable
, each available class in Exposed that inherits from IdTable
has the primaryKey
field automatically defined.
For example, the IntIdTable
by default has an auto-incrementing integer column,
- id
, which is defined as the primary key.
An IdTable
that requires a primary key with multiple columns can be defined using CompositeIdTable
.
- In this case, each column that is a component of the table's id
should be identified by
- entityId()
:
id
, which is defined as the primary key.
+
+
+ An IdTable
that requires a primary key with multiple columns can be defined using CompositeIdTable
.
+ In this case, each column that is a component of the table's ID should be identified by
+ .entityId()
:
+
The FOREIGN KEY
SQL constraint links two tables. A foreign key is a column from one table
- that refers to the primary key
- or columns with a unique index from another table. To configure a foreign key on a column, use reference()
- or optReference()
+
+ The FOREIGN KEY
SQL constraint links two tables. A foreign key is a column from one table
+ that refers to the primary key or columns with a unique index from another table. To configure a
+ foreign key on a column, use
+
+ reference()
+
+ or
+
+ optReference()
+
methods. The latter lets the foreign key accept a null
value. To configure a foreign key on
- multiple columns,
- use foreignKey()
directly within an init
block.
foreignKey()
+
+ function directly within an init
block.
+
reference()
and optReference()
methods have several parameters:
A name for the foreign key constraint.
Enum class ReferenceOption
has five values:
+ Enum class
+
+ ReferenceOption
+
+ has five values:
+
RESTRICT
An option that restricts changes on a referenced column, and the default option for most dialects.
NO_ACTION
The same as RESTRICT in some, but not all, databases, and the default option for Oracle and SQL - Server dialects.
+The same as RESTRICT
in some, but not all, databases, and the default option for
+ Oracle and SQL Server dialects.
CASCADE
An option that allows updating or deleting the referring rows.
SET_NULL
An option that sets the referring column values to null.
+An option that sets the referring column values to null
.
SET_DEFAULT
An option that sets the referring column values to the default value.
The CHECK
SQL constraint checks that all values in a column match some condition. Exposed
- supports the check()
method.
- You apply this method to a column and pass the appropriate condition to it.
For example, to check that the name
column contains strings that begin with a capital
- letter, use the following code:
+ The CHECK
SQL constraint checks that all values in a column match some condition. Exposed
+ supports the
+
+ .check()
+
+ method. You apply this method to a column and pass the appropriate condition to it.
+
+ For example, to check that the name
column contains strings that begin with a capital
+ letter, use the following code:
+
- To create a table within a database, you need to use the SchemaUtils.create()
- method within a transaction:
+ To create a table within a database, you need to use the
+
+ SchemaUtils.create()
+
+ method within a
+
+ transaction
+
+ :