From 7cb7d43222910a0d8d6bbe5cf7e6e797f955ef25 Mon Sep 17 00:00:00 2001
From: Viktoriya Nikolova
+ These operations can be performed directly through the methods and properties of the Entity
class
+ associated with the table. For more information, see .
+
To create a new table row, use the new
function on the entity class:
@@ -22,8 +26,8 @@
}
- In the above example StarWarsFilm
would be the entity instance linked to the StarWarsFilms
table.
- For more information, see .
+ In the above example StarWarsFilm
would be the entity instance linked to
+ the StarWarsFilms
table.
To provide a manual id
value to a new entity, pass the value as an argument to the id
parameter:
diff --git a/documentation-website/Writerside/topics/DAO-Table-Types.topic b/documentation-website/Writerside/topics/DAO-Table-Types.topic
index 4c6a91aef7..c97432ca3e 100644
--- a/documentation-website/Writerside/topics/DAO-Table-Types.topic
+++ b/documentation-website/Writerside/topics/DAO-Table-Types.topic
@@ -50,7 +50,7 @@
The following example represents a table with custom columns sequel_id
, name
,
and director
:
IntIdTable
class automatically generates an auto-incrementing integer id
@@ -66,7 +66,17 @@
- An entity instance or a row in the table is defined as a class instance: + Representing database tables as Kotlin objects ensures type safety and allows you to work with database + records just like regular Kotlin objects, taking full advantage of Kotlin's language features. +
+
+ Any IdTable
needs to be associated with an Entity
, because every database record
+ in this table needs to be mapped to an Entity
instance, identified by its primary key.
+
+ An entity instance is defined as a class.
+ For example, given the above table definition of StarWarsFilms
,
+ the corresponding entity class can be defined as follows:
StarWarsFilms
table is an IntIdTable
, the StarWarsFilm
class extends from IntEntity
,
+ which indicates that the id
and primary key of the StarWarsFilm
table is of type Int
.
+ companion object
block defines an EntityClass
which is responsible for maintaining
+ the relation between the StarWarsFilm
class and the actual table object, StarWarsFilms
.
+ by
keyword
+ ensures the data is fetched or updated from the corresponding column when accessed.
+ + Once the entity class is defined, instances of this class allow you to manipulate individual records + from the corresponding table. This could involve + creating a new record, + retrieving a row based on its primary key, + updating values, or + deleting records. +
The following example represents a table with custom columns sequel_id
, name
,
and director
:
IntIdTable
class automatically generates an auto-incrementing integer id
@@ -59,11 +59,57 @@
When the table is created, it corresponds to the following
SQL query:
For more information on defining and configuring tables in Exposed, see .
+ To define multiple columns as part of the primary key and id, use CompositeIdTable
and mark each
+ composite column using entityId()
.
+ Each component column will be available for CRUD operations either individually (as for any standard column)
+ or all together as part of the id
column:
+
+ To define a custom column type as the primary key and id, use a typed IdTable
directly and
+ override the id
column:
+
+ In this example, the id
field is defined as type Column<EntityID<String>>
,
+ to hold String
values with a length of up to 32 characters. Using the
+ override
keyword indicates that this id
column is overriding the default
+ id
column provided by IdTable
.
+
+ Once all columns are defined, the id
column is explicitly set as the primary key for the table,
+ using the override
keyword once again.
+
Representing database tables as Kotlin objects ensures type safety and allows you to work with database @@ -75,99 +121,32 @@
An entity instance is defined as a class.
- For example, given the above table definition of StarWarsFilms
,
+ For example, given the above table definition of StarWarsFilmsTable
,
the corresponding entity class can be defined as follows:
StarWarsFilms
table is an IntIdTable
, the StarWarsFilm
class extends from IntEntity
,
- which indicates that the id
and primary key of the StarWarsFilm
table is of type Int
.
+ Since StarWarsFilmsTable
is an IntIdTable
, the StarWarsFilmsEntity
class extends from IntEntity
,
+ which indicates that the id
and primary key of StarWarsFilmsTable
is of type Int
.
companion object
block defines an EntityClass
which is responsible for maintaining
- the relation between the StarWarsFilm
class and the actual table object, StarWarsFilms
.
+ the relation between the StarWarsFilmsEntity
class and the actual table object, StarWarsFilmsTable
.
by
keyword
ensures the data is fetched or updated from the corresponding column when accessed.
+
Once the entity class is defined, instances of this class allow you to manipulate individual records - from the corresponding table. This could involve - creating a new record, - retrieving a row based on its primary key, - updating values, or - deleting records. -
-To define multiple columns as part of the primary key and id, use CompositeIdTable
and mark each composite column using
- entityId()
.
- Each component column will be available for CRUD operations either individually (as for any standard column) or all together as part of the
- id
column:
To define a custom column type as the primary key and id, use a typed IdTable
directly and override the id
column:
To create a new table row, use the new
function on the entity class:
In the above example StarWarsFilm
would be the entity instance linked to
the StarWarsFilms
table.
@@ -32,103 +26,64 @@
To provide a manual id
value to a new entity, pass the value as an argument to the id
parameter:
If the entity is a CompositeEntity
, the id value can be constructed by creating a component column-to-value association using
CompositeID
:
To read a value from a property, simply access it as you would with any property in a Kotlin class:
-id
property is wrapped as an instance of the EntityID
class.
To access the actual wrapped value, for example the stored Int
from a StarWarsFilm
entity, use EntityID.value
:
- To retrieve entities, use one of the following methods:
all()
function:
- find()
function:
- findById()
function:
-
If the entity is a CompositeEntity
, its id
property can be used to refer to
all composite columns and to get entities,
much like the id
column of its associated CompositeIdTable
:
+ The SQL query would result in something like the following: +
+Suppose that you want to find all users who rated the second Star Wars film with a score greater than 5. First, you would write that query using Exposed DSL.
-
Once the query is defined, you can wrap the result in the User
entity using the
wrapRows()
function to generate entities from the retrieved data:
@@ -136,15 +91,11 @@
To sort results in ascending order, use sortedBy
:
To sort results in descending order, use sortedByDescending
:
You can update the value of a property just as you would with any property in a Kotlin class:
-Entity
, it just stores it on the inner map.
"Flushing" values to the database occurs at the end of the transaction, or before the next SELECT *
from the database.
@@ -163,22 +112,14 @@
To search for an entity by its id and apply an update, use the findByIdAndUpdate()
function:
To search for a single entity by a query and apply an update, use the findSingleByAndUpdate()
function:
To delete a record, use the delete()
function:
Query
to an
Expression
. This can be done using the wrapAsExpression()
function:
- StarWarsFilmsTable
,
the corresponding entity class can be defined as follows:
- StarWarsFilmsTable
is an IntIdTable
, the StarWarsFilmsEntity
class extends from IntEntity
,
From 279329f096677d619eaf5e07d7fa1489de31ffdd Mon Sep 17 00:00:00 2001
From: Viktoriya Nikolova
To create a new table row, use the new
function on the entity class:
In the above example StarWarsFilm
would be the entity instance linked to
the StarWarsFilms
table.
@@ -26,51 +26,51 @@
To provide a manual id
value to a new entity, pass the value as an argument to the id
parameter:
If the entity is a CompositeEntity
, the id value can be constructed by creating a component column-to-value association using
CompositeID
:
To read a value from a property, simply access it as you would with any property in a Kotlin class:
-id
property is wrapped as an instance of the EntityID
class.
To access the actual wrapped value, for example the stored Int
from a StarWarsFilm
entity, use EntityID.value
:
- To retrieve entities, use one of the following methods:
all()
function:
- find()
function:
- findById()
function:
-
If the entity is a CompositeEntity
, its id
property can be used to refer to
all composite columns and to get entities,
much like the id
column of its associated CompositeIdTable
:
The SQL query would result in something like the following:
-Suppose that you want to find all users who rated the second Star Wars film with a score greater than 5. First, you would write that query using Exposed DSL.
-
Once the query is defined, you can wrap the result in the User
entity using the
wrapRows()
function to generate entities from the retrieved data:
@@ -91,11 +91,11 @@
To sort results in ascending order, use sortedBy
:
To sort results in descending order, use sortedByDescending
:
You can update the value of a property just as you would with any property in a Kotlin class:
-Entity
, it just stores it on the inner map.
"Flushing" values to the database occurs at the end of the transaction, or before the next SELECT *
from the database.
@@ -112,14 +112,14 @@
To search for an entity by its id and apply an update, use the findByIdAndUpdate()
function:
To search for a single entity by a query and apply an update, use the findSingleByAndUpdate()
function:
To delete a record, use the delete()
function:
Query
to an
Expression
. This can be done using the wrapAsExpression()
function:
- @@ -12,65 +12,70 @@
These operations can be performed directly through the methods and properties of the Entity
class
- associated with the table. For more information, see .
+ associated with the table. For more information, see .
To create a new table row, use the new
function on the entity class:
- In the above example StarWarsFilm
would be the entity instance linked to
- the StarWarsFilms
table.
+ In the above example StarWarsFilmEntity
would be the entity instance linked to
+ the StarWarsFilmsTable
table.
To provide a manual id
value to a new entity, pass the value as an argument to the id
parameter:
If the entity is a CompositeEntity
, the id value can be constructed by creating a component column-to-value association using
CompositeID
:
To read a value from a property, simply access it as you would with any property in a Kotlin class:
-id
property is wrapped as an instance of the EntityID
class.
To access the actual wrapped value, for example the stored Int
from a StarWarsFilm
entity, use EntityID.value
:
- To retrieve entities, use one of the following methods:
all()
function:
- find()
function:
- findById()
function:
-
If the entity is a CompositeEntity
, its id
property can be used to refer to
all composite columns and to get entities,
much like the id
column of its associated CompositeIdTable
:
The SQL query would result in something like the following:
-Suppose that you want to find all users who rated the second Star Wars film with a score greater than 5. First, you would write that query using Exposed DSL.
-
Once the query is defined, you can wrap the result in the User
entity using the
wrapRows()
function to generate entities from the retrieved data:
- -
To sort results in ascending order, use sortedBy
:
To sort results in descending order, use sortedByDescending
:
You can update the value of a property just as you would with any property in a Kotlin class:
-Entity
, it just stores it on the inner map.
"Flushing" values to the database occurs at the end of the transaction, or before the next SELECT *
from the database.
@@ -112,14 +116,14 @@
To search for an entity by its id and apply an update, use the findByIdAndUpdate()
function:
To search for a single entity by a query and apply an update, use the findSingleByAndUpdate()
function:
To delete a record, use the delete()
function:
Query
to an
Expression
. This can be done using the wrapAsExpression()
function:
- EntityClass
. However, to achieve this functionality, you only need to override
searchQuery()
. The results of the function can then be accessed through a property of the entity class:
-
- + Then, creating and fetching entities would look like this: +
++ Representing database tables as Kotlin objects ensures type safety and allows you to work with database + records just like regular Kotlin objects, taking full advantage of Kotlin's language features. +
+
+ When using the DAO approach, IdTable
needs to be associated with an Entity
, because every database record
+ in this table needs to be mapped to an Entity
instance, identified by its primary key.
+
+ An entity instance is defined as a class.
+ In the following example, StarWarsFilmEntity
is the entity class linked to the table StarWarsFilmsTable
:
+
StarWarsFilmsTable
is an IntIdTable
, the StarWarsFilmsEntity
class extends from IntEntity
,
+ which indicates that the id
and primary key of StarWarsFilmsTable
is of type Int
.
+ companion object
block defines an EntityClass
which is responsible for maintaining
+ the relation between the StarWarsFilmsEntity
class and the actual table object, StarWarsFilmsTable
.
+ by
keyword
+ ensures the data is fetched or updated from the corresponding column when accessed.
+ + Once the entity class is defined, instances of this class allow you to manipulate individual records + from the corresponding table. This could involve + creating a new record, + retrieving a row based on its primary key, + updating values, or + deleting records. +
+id
column tables
Apart from the core
- To define multiple columns as part of the primary key and id, use
To define a custom column type as the primary key and id, use a typed
- In this example, the Table
class, Exposed provides the base
@@ -67,41 +68,49 @@
CompositeIdTable
and mark each
- composite column using entityId()
.
+ To define multiple columns as part of the primary key and id, use
+ CompositeIdTable
+ and mark each composite column using entityId()
.
Each component column will be available for CRUD operations either individually (as for any standard column)
or all together as part of the id
column:
IdTable
directly and
- override the id
column:
+ override the id
column, as shown in the following example:
id
field is defined as type Column<EntityID<String>>
,
- to hold String
values with a length of up to 32 characters. Using the
+ In the definition of DirectorsCustomTable
, the id
field is of type Column<EntityID<String>>
,
+ which will hold String
values with a length of up to 32 characters. Using the
override
keyword indicates that this id
column is overriding the default
id
column provided by IdTable
.
override
keyword once again.
- Representing database tables as Kotlin objects ensures type safety and allows you to work with database - records just like regular Kotlin objects, taking full advantage of Kotlin's language features. -
-
- Any IdTable
needs to be associated with an Entity
, because every database record
- in this table needs to be mapped to an Entity
instance, identified by its primary key.
-
- An entity instance is defined as a class.
- For example, given the above table definition of StarWarsFilmsTable
,
- the corresponding entity class can be defined as follows:
-
StarWarsFilmsTable
is an IntIdTable
, the StarWarsFilmsEntity
class extends from IntEntity
,
- which indicates that the id
and primary key of StarWarsFilmsTable
is of type Int
.
- companion object
block defines an EntityClass
which is responsible for maintaining
- the relation between the StarWarsFilmsEntity
class and the actual table object, StarWarsFilmsTable
.
- by
keyword
- ensures the data is fetched or updated from the corresponding column when accessed.
- - Once the entity class is defined, instances of this class allow you to manipulate individual records - from the corresponding table. This could involve - creating a new record, - retrieving a row based on its primary key, - updating values, or - deleting records. -
-You can update the value of a property just as you would with any property in a Kotlin class:
-Entity
, it just stores it on the inner map.
"Flushing" values to the database occurs at the end of the transaction, or before the next SELECT *
from the database.
@@ -150,10 +148,10 @@
searchQuery()
. The results of the function can then be accessed through a property of the entity class:
diff --git a/documentation-website/Writerside/topics/DAO-Table-Types.topic b/documentation-website/Writerside/topics/DAO-Table-Types.topic index 7aeb97363c..d68274e409 100644 --- a/documentation-website/Writerside/topics/DAO-Table-Types.topic +++ b/documentation-website/Writerside/topics/DAO-Table-Types.topic @@ -102,10 +102,10 @@
From 992f61809b3442e8004f8d9d8c6eea8af86c4453 Mon Sep 17 00:00:00 2001
From: Viktoriya Nikolova id
column of its associated CompositeIdTable
:
The SQL query would result in something like the following:
-You can update the value of a property just as you would with any property in a Kotlin class:
-Entity
, it just stores it on the inner map.
"Flushing" values to the database occurs at the end of the transaction, or before the next SELECT *
from the database.
diff --git a/documentation-website/Writerside/topics/DAO-Entity-definition.topic b/documentation-website/Writerside/topics/DAO-Entity-definition.topic
index a73c8bc491..0f699044c7 100644
--- a/documentation-website/Writerside/topics/DAO-Entity-definition.topic
+++ b/documentation-website/Writerside/topics/DAO-Entity-definition.topic
@@ -19,10 +19,10 @@
The following example represents a table with custom columns sequel_id
, name
,
and director
:
IntIdTable
class automatically generates an auto-incrementing integer id
@@ -60,7 +61,7 @@
When the table is created, it corresponds to the following
SQL query:
For more information on defining and configuring tables in Exposed, see .
From 5b9890a392b7febb11fcb701632bd037bfa082e5 Mon Sep 17 00:00:00 2001 From: Viktoriya NikolovaThe SQL query would result in something like the following:
-
To delete a record, use the delete()
function:
EntityClass
. However, to achieve this functionality, you only need to override
searchQuery()
. The results of the function can then be accessed through a property of the entity class: