Skip to content

Commit

Permalink
add missing imports
Browse files Browse the repository at this point in the history
  • Loading branch information
vnikolova committed Oct 1, 2024
1 parent 43cebfb commit 279329f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.example

import org.example.entities.*
import org.example.tables.*
import org.jetbrains.exposed.dao.id.CompositeID
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
Expand Down
38 changes: 19 additions & 19 deletions documentation-website/Writerside/topics/DAO-CRUD-Operations.topic
Original file line number Diff line number Diff line change
Expand Up @@ -18,59 +18,59 @@
<p>
To create a new table row, use the <code>new</code> function on the entity class:
</p>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="24-28"/>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="26-30"/>
<p>
In the above example <code>StarWarsFilm</code> would be the <a href="DAO-Table-Types.topic" anchor="define-entity-instance">entity instance</a> linked to
the <code>StarWarsFilms</code> table.
</p>
<p>
To provide a manual <code>id</code> value to a new entity, pass the value as an argument to the <code>id</code> parameter:
</p>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="31-35"/>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="33-37"/>
<p>
If the entity is a <code>CompositeEntity</code>, the id value can be constructed by creating a component column-to-value association using
<code>CompositeID</code>:
</p>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="87-94"/>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="89-96"/>
</chapter>
<chapter title="Read" id="read">
<p>To read a value from a property, simply access it as you would with any property in a Kotlin class:</p>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="38"/>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="40"/>
<note>
An entity's <code>id</code> property is wrapped as an instance of the <code>EntityID</code> class.
To access the actual wrapped value, for example the stored <code>Int</code> from a <code>StarWarsFilm</code>
entity, use <code>EntityID.value</code>:
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="42"/>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="44"/>
</note>
<p>To retrieve entities, use one of the following methods:</p>
<chapter title="all" id="read-all">
To get all the entity instances associated with this entity class, use the
<a href="https://jetbrains.github.io/Exposed/api/exposed-dao/org.jetbrains.exposed.dao/-entity-class/all.html"><code>all()</code></a>
function:
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="46"/>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="48"/>
</chapter>
<chapter title="find" id="find-all">
To get all the entity instances that conform to the conditional expression, use the
<a href="https://jetbrains.github.io/Exposed/api/exposed-dao/org.jetbrains.exposed.dao/-entity-class/find.html"><code>find()</code></a>
function:
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="58"/>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="60"/>
</chapter>
<chapter title="findById" id="find-by-id">
To get an entity by its id value, use the
<a href="https://jetbrains.github.io/Exposed/api/exposed-dao/org.jetbrains.exposed.dao/-entity-class/find-by-id.html"><code>findById()</code></a>
function:
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="62"/>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="64"/>
</chapter>
<p>
If the entity is a <code>CompositeEntity</code>, its <code>id</code> property can be used to refer to
all composite columns and to get entities,
much like the <code>id</code> column of its associated <code>CompositeIdTable</code>:
</p>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="88-92,104"/>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="90-94,106"/>
<p>
The SQL query would result in something like the following:
</p>
<code-block lang="sql" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="99-102" />
<code-block lang="sql" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="101-104" />
<tip>
For a list of available predicates, see
<a href="DSL-Querying-data.topic" anchor="where-expression">DSL Where expression</a>.
Expand All @@ -79,31 +79,31 @@
<p>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.</p>

<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="113-118"/>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="115-120"/>
<p>
Once the query is defined, you can wrap the result in the <code>User</code> entity using the
<code>wrapRows()</code> function to generate entities from the retrieved data:</p>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="119"/>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="121"/>
</chapter>
<chapter title="Sort results" id="sort-by">
<p>

</p>
<chapter title="sortedBy" id="sortedBy">
<p>To sort results in ascending order, use <code>sortedBy</code>:</p>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="50"/>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="52"/>
</chapter>
<chapter title="sortedByDescending" id="sortedByDescending">
<p>To sort results in descending order, use <code>sortedByDescending</code>:</p>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="54"/>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="56"/>
</chapter>
</chapter>
</chapter>
<chapter title="Update" id="update">
<p>
You can update the value of a property just as you would with any property in a Kotlin class:
</p>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="66"/>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="68"/>
<note>
Exposed doesn't make an immediate update when you set a new value for <code>Entity</code>, it just stores it on the inner map.
"Flushing" values to the database occurs at the end of the transaction, or before the next <code>SELECT *</code> from the database.
Expand All @@ -112,22 +112,22 @@
<p>
To search for an entity by its id and apply an update, use the <code>findByIdAndUpdate()</code> function:
</p>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="69-71"/>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="71-73"/>
</chapter>
<chapter title="findSingleByAndUpdate" id="findSingleByAndUpdate">
<p>
To search for a single entity by a query and apply an update, use the <code>findSingleByAndUpdate()</code>
function:
</p>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="75-77"/>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="77-79"/>
</chapter>

</chapter>
<chapter title="Delete" id="delete">
<p>
To delete a record, use the <code>delete()</code> function:
</p>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="81"/>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="83"/>
</chapter>

<chapter title="Use queries as expressions" id="use-queries-as-expressions">
Expand All @@ -136,7 +136,7 @@
then order the result by that count.To do so, however, you need to convert the <code>Query</code> to an
<code>Expression</code>. This can be done using the <code>wrapAsExpression()</code>
function:</p>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="127-133"/>
<code-block lang="kotlin" src="exposed-dao/src/main/kotlin/org/example/App.kt" include-lines="129-135"/>
</chapter>

<chapter title="Add computed fields to entity class" id="add-computed-fields-to-entity-class">
Expand Down

0 comments on commit 279329f

Please sign in to comment.