-
Notifications
You must be signed in to change notification settings - Fork 751
docs: EXPOSED-747 Add a get started tutorial for Exposed DAO #2556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cc7f40d
docs: add a new snippets project and tutorial for getting started wit…
vnikolova 629c947
fix text, code snippets and create a new toc-element
vnikolova 679bbb4
fix: detekt issues
vnikolova 0b22a96
include get-started-with-exposed to the snippets project and update refs
vnikolova 35e3c4b
update code examples to resolve comments
vnikolova e977eba
fix code blocks and tutorial link
vnikolova 562abed
fix formatting
vnikolova 4b53060
address comments
vnikolova 2f65e83
update downloadable gradle project
vnikolova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+527 Bytes
(100%)
documentation-website/Writerside/resources/init-kotlin-gradle-app.zip
Binary file not shown.
1 change: 1 addition & 0 deletions
1
...nippets/exposed-migrations/src/main/kotlin/org/example/migrations/V2__Add_primary_key.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ALTER TABLE USERS ADD PRIMARY KEY (ID); |
21 changes: 21 additions & 0 deletions
21
documentation-website/Writerside/snippets/get-started-with-exposed-dao/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Get started with Exposed DAO tutorial project | ||
|
|
||
| A sample Gradle/Kotlin project built by following the steps explained in | ||
| the [Get started with Exposed DAO](https://www.jetbrains.com/help/exposed/get-started-with-exposed-dao.html) | ||
| tutorial. | ||
|
|
||
| ## Build | ||
|
|
||
| To build the application, navigate to the `snippets` folder and run the following command: | ||
|
|
||
| ```shell | ||
| ./gradlew :get-started-with-exposed-dao:build | ||
| ``` | ||
|
|
||
| ## Run | ||
|
|
||
| To run the application, execute the following command: | ||
|
|
||
| ```bash | ||
| ./gradlew :get-started-with-exposed-dao:run | ||
| ``` |
53 changes: 53 additions & 0 deletions
53
documentation-website/Writerside/snippets/get-started-with-exposed-dao/build.gradle.kts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * This file was generated by the Gradle 'init' task. | ||
| * | ||
| * This generated file contains a sample Kotlin application project to get you started. | ||
| * For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.8/userguide/building_java_projects.html in the Gradle documentation. | ||
| */ | ||
|
|
||
| plugins { | ||
| // Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin. | ||
| alias(libs.plugins.jvm) | ||
|
|
||
| // Apply the application plugin to add support for building a CLI application in Java. | ||
| application | ||
| } | ||
|
|
||
| repositories { | ||
| // Use Maven Central for resolving dependencies. | ||
| mavenCentral() | ||
| } | ||
|
|
||
| dependencies { | ||
| // Use the Kotlin JUnit 5 integration. | ||
| testImplementation("org.jetbrains.kotlin:kotlin-test-junit5") | ||
|
|
||
| // Use the JUnit 5 integration. | ||
| testImplementation(libs.junit.jupiter.engine) | ||
|
|
||
| testRuntimeOnly("org.junit.platform:junit-platform-launcher") | ||
|
|
||
| // This dependency is used by the application. | ||
| implementation(libs.guava) | ||
| implementation(libs.exposed.core) | ||
| implementation(libs.exposed.dao) | ||
| implementation(libs.exposed.jdbc) | ||
| implementation(libs.h2) | ||
| } | ||
|
|
||
| // Apply a specific Java toolchain to ease working on different environments. | ||
| java { | ||
| toolchain { | ||
| languageVersion = JavaLanguageVersion.of(21) | ||
| } | ||
| } | ||
|
|
||
| application { | ||
| // Define the main class for the application. | ||
| mainClass = "org.example.AppKt" | ||
| } | ||
|
|
||
| tasks.named<Test>("test") { | ||
| // Use JUnit Platform for unit tests. | ||
| useJUnitPlatform() | ||
| } | ||
43 changes: 43 additions & 0 deletions
43
...bsite/Writerside/snippets/get-started-with-exposed-dao/src/main/kotlin/org/example/App.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package org.example | ||
|
|
||
| import org.jetbrains.exposed.v1.core.StdOutSqlLogger | ||
| import org.jetbrains.exposed.v1.jdbc.Database | ||
| import org.jetbrains.exposed.v1.jdbc.SchemaUtils | ||
| import org.jetbrains.exposed.v1.jdbc.transactions.transaction | ||
|
|
||
| fun main() { | ||
| Database.connect("jdbc:h2:mem:test", driver = "org.h2.Driver") | ||
|
|
||
| transaction { | ||
| addLogger(StdOutSqlLogger) | ||
|
|
||
| // ... | ||
|
|
||
| SchemaUtils.create(Tasks) | ||
|
|
||
| val task1 = Task.new { | ||
| title = "Learn Exposed DAO" | ||
| description = "Follow the DAO tutorial" | ||
| } | ||
|
|
||
| val task2 = Task.new { | ||
| title = "Read The Hobbit" | ||
| description = "Read chapter one" | ||
| isCompleted = true | ||
| } | ||
|
|
||
| println("Created new tasks with ids ${task1.id} and ${task2.id}") | ||
|
|
||
| val completed = Task.find { Tasks.isCompleted eq true }.toList() | ||
| println("Completed tasks: ${completed.count()}") | ||
|
|
||
| // Update | ||
| task1.title = "Try Exposed DAO" | ||
| task1.isCompleted = true | ||
| println("Updated task1: $task1") | ||
|
|
||
| // Delete | ||
| task2.delete() | ||
| println("Remaining tasks: ${Task.all().toList()}") | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
...site/Writerside/snippets/get-started-with-exposed-dao/src/main/kotlin/org/example/Task.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package org.example | ||
|
|
||
| // ... | ||
| import org.jetbrains.exposed.v1.core.dao.id.EntityID | ||
| import org.jetbrains.exposed.v1.core.dao.id.IntIdTable | ||
| import org.jetbrains.exposed.v1.dao.IntEntity | ||
| import org.jetbrains.exposed.v1.dao.IntEntityClass | ||
|
|
||
| @Suppress("MagicNumber") | ||
| object Tasks : IntIdTable("tasks") { | ||
| val title = varchar("name", 128) | ||
| val description = varchar("description", 128) | ||
| val isCompleted = bool("completed").default(false) | ||
| } | ||
|
|
||
| // ... | ||
|
|
||
| class Task(id: EntityID<Int>) : IntEntity(id) { | ||
| companion object : IntEntityClass<Task>(Tasks) | ||
|
|
||
| var title by Tasks.title | ||
| var description by Tasks.description | ||
| var isCompleted by Tasks.isCompleted | ||
|
|
||
| override fun toString(): String { | ||
| return "Task(id=$id, title=$title, completed=$isCompleted)" | ||
| } | ||
| } |
9 changes: 0 additions & 9 deletions
9
documentation-website/Writerside/snippets/get-started-with-exposed/.gitattributes
This file was deleted.
Oops, something went wrong.
12 changes: 10 additions & 2 deletions
12
documentation-website/Writerside/snippets/get-started-with-exposed/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,20 @@ | ||
| # Get started with Exposed tutorial project | ||
|
|
||
| A sample Gradle/Kotlin project built by following the steps explained in | ||
| the [Get started with Exposed](https://jetbrains.github.io/Exposed/getting-started-with-exposed.html) tutorial. | ||
| the [Get started with Exposed](https://www.jetbrains.com/help/exposed/get-started-with-exposed.html) tutorial. | ||
|
|
||
| ## Build | ||
|
|
||
| To build the application, navigate to the `snippets` folder and run the following command: | ||
|
|
||
| ```shell | ||
| ./gradlew :get-started-with-exposed:build | ||
| ``` | ||
|
|
||
| ## Run | ||
|
|
||
| To run the application, execute the following command in the repository's root directory: | ||
|
|
||
| ```bash | ||
| ./gradlew run | ||
| ./gradlew :get-started-with-exposed:run | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
documentation-website/Writerside/snippets/get-started-with-exposed/gradle/libs.versions.toml
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-42.4 KB
...on-website/Writerside/snippets/get-started-with-exposed/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 0 additions & 7 deletions
7
...ite/Writerside/snippets/get-started-with-exposed/gradle/wrapper/gradle-wrapper.properties
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.