Skip to content

Commit d42e57e

Browse files
committed
Adding readme code snippets to testing suits.
1 parent d100f10 commit d42e57e

File tree

5 files changed

+416
-36
lines changed

5 files changed

+416
-36
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Docs for db-messiah-extra
2+
3+
on:
4+
push:
5+
6+
permissions:
7+
contents: write
8+
9+
jobs:
10+
publish:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
persist-credentials: false
16+
17+
- name: Set up JDK 19
18+
uses: actions/setup-java@v4
19+
with:
20+
java-version: 19
21+
distribution: 'adopt'
22+
23+
- name: Build documentation
24+
run: ./gradlew dokkaHtml
25+
26+
- name: Publish documentation
27+
uses: JamesIves/github-pages-deploy-action@releases/v4
28+
with:
29+
BRANCH: gh-pages
30+
FOLDER: build/dokka/html

README.md

Lines changed: 111 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
<h1 align="center">db-messiah-extra</h1>
22
<h3 align="center">Extra Utils for Db Messiah, kotlin lib. for enterprise database development</h3>
3+
<p align="center">
4+
readme code snippets are
5+
<a href="https://github.com/urosjarc/db-messiah/blob/master/src/tutorials/kotlin/Test_README.md">autogenerated</a>
6+
and
7+
<a href="https://github.com/urosjarc/db-messiah/blob/master/src/tutorials/kotlin/Test_README.kt">tested</a><br>
8+
+<b>15</b> <a href="https://github.com/urosjarc/db-messiah/blob/master/src/e2e">e2e</a> tests with <b>100%</b> instruction coverage
9+
</p>
310
<br>
411
<br>
512
<table width="100%" border="0">
613
<tr>
7-
<td width="50%">
14+
<td width="33%">
815
<h3 align="center"><a href="https://github.com/urosjarc/db-messiah">db-messiah</a></h3>
916
<p align="center">Kotlin lib. for enterprise database development</p>
1017
</td>
11-
<td width="50%">
18+
<td width="33%" align="center">
19+
<p><a href="#get-started">Get started</a></p>
20+
<p><a href="#specifications">Specifications</a></p>
21+
<p><a href="#arhitecture">Arhitecture</a></p>
22+
<p><a href="https://urosjarc.github.io/db-messiah-extra/">Documentation</a></p>
23+
</td>
24+
<td width="33%">
1225
<h3 align="center"><a href="https://github.com/urosjarc/db-analyser">db-analyser</a></h3>
1326
<p align="center">GUI for db analysis, to help you create complex JOIN statements for SQL or db-messiah.
1427
</td>
@@ -20,66 +33,129 @@
2033
<h2 align="center">Get started</h2>
2134

2235
```kotlin
23-
implementation("com.urosjarc:db-messiah-extra:0.0.1")
36+
implementation("com.urosjarc:db-messiah-extra-extra:0.0.1")
2437
```
2538

26-
<br><h3 align="center">DB Serializers</h3>
39+
<br><h3 align="center">Domain</h3>
2740

2841
```kotlin
29-
/** SQLITE */
30-
31-
val sqliteSerializer = SqliteSerializer(
32-
globalSerializers = BasicTS.sqlite + KotlinxTimeTS.sqlite,
33-
...
42+
@Serializable
43+
data class MyTable(
44+
@Contextual
45+
val pk: UUID = UUID.randomUUID(),
46+
val instant: kotlinx.datetime.Instant,
47+
val localDate: kotlinx.datetime.LocalDate,
48+
val localTime: kotlinx.datetime.LocalTime,
3449
)
3550

36-
/** POSTGRESQL */
51+
```
3752

53+
<br><h3 align="center">DB Serializers</h3>
54+
55+
```kotlin
3856
val sqliteSerializer = SqliteSerializer(
3957
globalSerializers = BasicTS.sqlite + KotlinxTimeTS.sqlite,
40-
...
58+
tables = listOf(Table(MyTable::pk)),
4159
)
4260
```
4361

4462
<br><h3 align="center">JSON Serializers</h3>
4563

46-
4764
```kotlin
4865
/** JSON */
4966

5067
val json = Json {
51-
serializersModule = SerializersModule {
68+
serializersModule = SerializersModule {
5269
contextual(InstantJS)
5370
contextual(LocalDateJS)
5471
contextual(LocalTimeJS)
5572
contextual(UUIDJS)
5673
}
5774
}
5875

59-
val jsonStr = json.encodeToString(...)
60-
val obj = json.decodeFromString<...>(...)
61-
62-
/** KTOR */
6376

64-
install(ContentNegotiation) {
65-
json(Json {
66-
serializersModule = SerializersModule {
67-
contextual(InstantJS)
68-
contextual(LocalDateJS)
69-
contextual(LocalTimeJS)
70-
contextual(UUIDJS)
71-
}
72-
})
77+
val dtNow = Clock.System.now().toLocalDateTime(timeZone = TimeZone.UTC)
78+
val myTable = MyTable(
79+
instant = Clock.System.now(),
80+
localDate = dtNow.date,
81+
localTime = dtNow.time
82+
)
83+
84+
val jsonStr = json.encodeToString(myTable)
85+
val obj = json.decodeFromString<MyTable>(jsonStr)
86+
assert(obj == myTable)
87+
88+
/** KTOR */
89+
embeddedServer(Netty, port = 8080, host = "0.0.0.0") {
90+
install(ContentNegotiation) {
91+
json(Json {
92+
serializersModule = SerializersModule {
93+
contextual(InstantJS)
94+
contextual(LocalDateJS)
95+
contextual(LocalTimeJS)
96+
contextual(UUIDJS)
97+
}
98+
})
99+
}
73100
}
74101
```
75102

76-
<br><h3 align="center">Features</h3>
103+
<br><br><h2 align="center">Specifications</h3>
104+
105+
| Class | COLUMN | Databases | db-messiah-extra | JSON |
106+
|:-------------:|:------------:|:------------------------------------:|:---------------------------:|:-----------:|
107+
| Instant | DATETIME | Sqlite, Mysql, MSSql, Maria, H2, DB2 | KotlinxInstantTS. DATETIME | InstantJS |
108+
| Instant | TIMESTAMP | Derby, Postgres, Oracle | KotlinxInstantTS. TIMESTAMP | InstantJS |
109+
| LocalDateTime | :x: | :x: | :x: | :x: |
110+
| LocalDate | DATE | :white_check_mark: | KotlinxLocalDateTS. DATE | LocalDateJS |
111+
| LocalTime | TIME | :white_check_mark: but Oracle | KotlinxTimeTS.TIME | LocalDateJS |
112+
| LocalTime | NUMBER(8, 0) | Oracle | KotlinxTimeTS. NUMBER8 | LocalTimeJS |
113+
| UUID | db-messiah | db-messiah | db-messiah | UUIDJS |
77114

78-
| Class | COLUMN | Databases | db-messiah-extra | JSON |
79-
|:---------:|:------------:|:------------------------------------:|:---------------------------:|:-----------:|
80-
| Instant | DATETIME | Sqlite, Mysql, MSSql, Maria, H2, DB2 | KotlinxInstantTS. DATETIME | InstantJS |
81-
| Instant | TIMESTAMP | Derby, Postgres, Oracle | KotlinxInstantTS. TIMESTAMP | InstantJS |
82-
| LocalDate | DATE | :white_check_mark: | KotlinxLocalDateTS. DATE | LocalDateJS |
83-
| LocalTime | TIME | :white_check_mark: but Oracle | KotlinxTimeTS.TIME | LocalDateJS |
84-
| LocalTime | NUMBER(8, 0) | Oracle | KotlinxTimeTS. NUMBER8 | LocalTimeJS |>
85-
| UUID | db-messiah | db-messiah | db-messiah | UUIDJS |>
115+
<br><br><h2 align="center">Arhitecture</h3>
116+
117+
```text
118+
src/main/kotlin/com/urosjarc/dbmessiah/extra/
119+
|-- kotlinx
120+
| |-- InstantJS.kt............| java.time.Instant serializer for kotlinx.serialization
121+
| |-- LocalDateJS.kt..........| java.time.LocalDate serializer for kotlinx.serialization
122+
| |-- LocalTimeJS.kt..........| java.time.LocalTime serializer for kotlinx.serialization
123+
| `-- UUIDJS.kt...............| java.utils.UUID serializer for kotlinx.serialization
124+
`-- serializers
125+
|-- KotlinxInstantTS.kt.....| kotlinx.datetime.Instant type serializer for db-messiah
126+
|-- KotlinxLocalDateTS.kt...| kotlinx.datetime.LocalDate type serializer for db-messiah
127+
|-- KotlinxLocalTimeTS.kt...| kotlinx.datetime.LocalTime type serializer for db-messiah
128+
`-- KotlinxTimeTS.kt........| kotlinx.datetime.Time type serializer for db-messiah
129+
```
130+
131+
<br><br><h2 align="center">Sources</h2>
132+
133+
```text
134+
src/
135+
|-- main...............................| Already described in architecture.
136+
`-- test
137+
|-- kotlin
138+
| |-- impl
139+
| | |-- Test_Contract.kt.......| Testing interface for all db tests.
140+
| | |-- Test_Db2.kt
141+
| | |-- Test_Derby.kt
142+
| | |-- Test_H2.kt
143+
| | |-- Test_Maria.kt
144+
| | |-- Test_Mssql.kt
145+
| | |-- Test_Mysql.kt
146+
| | |-- Test_Oracle.kt
147+
| | |-- Test_Postgresql.kt
148+
| | `-- Test_Sqlite.kt
149+
| |-- Test_InstantJS.kt
150+
| |-- Test_LocalDateJS.kt
151+
| |-- Test_LocalTimeJS.kt
152+
| |-- Test_README.kt.............| Code from where README.md is generated.
153+
| |-- Test_README.md.............| Template from where README.md is generated.
154+
| |-- Test_UUIDJS.kt
155+
| `-- utils
156+
| |-- domain.kt
157+
| |-- Schemas.kt
158+
| `-- Serializers.kt
159+
`-- resources
160+
`-- log4j2.xml
161+
```

build.gradle.kts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import org.jetbrains.dokka.DokkaConfiguration.Visibility
22
import java.lang.Thread.sleep
3-
import java.net.URI
43

54
val GPG_PRIVATE_KEY = System.getenv("GPG_PRIVATE_KEY")
65
val GPG_PRIVATE_PASSWORD = System.getenv("GPG_PRIVATE_PASSWORD")
@@ -111,6 +110,12 @@ dependencies {
111110
testImplementation("org.apache.logging.log4j:log4j-slf4j2-impl:2.20.0")
112111
testImplementation("org.jetbrains.kotlin:kotlin-test")
113112
testImplementation("com.urosjarc:db-messiah:$dbMessiah")
113+
114+
val ktor_version = "2.3.8"
115+
testImplementation("io.ktor:ktor-server-core-jvm:$ktor_version")
116+
testImplementation("io.ktor:ktor-server-netty-jvm:$ktor_version")
117+
testImplementation("io.ktor:ktor-server-content-negotiation:$ktor_version")
118+
testImplementation("io.ktor:ktor-serialization-kotlinx-json:$ktor_version")
114119
}
115120

116121
tasks.test {
@@ -166,3 +171,43 @@ publishing {
166171
}
167172

168173
}
174+
175+
tasks.register<GradleBuild>("readme") {
176+
group = "verification"
177+
description = "Create README.md tests."
178+
this.tasks = listOf("test")
179+
180+
doLast {
181+
val templateLines = File("./src/test/kotlin/Test_README.kt").readLines()
182+
var readme = File("./src/test/kotlin/Test_README.md").readText()
183+
184+
val dependencies = mutableListOf(
185+
"implementation(\"${project.group}:${project.name}-extra:$version\")",
186+
)
187+
188+
val readmeMap: MutableList<Pair<String, MutableList<String>>> = mutableListOf(
189+
"// START 'Dependencies'" to dependencies,
190+
)
191+
192+
193+
var active = false
194+
var indent = ""
195+
templateLines.forEach {
196+
if (it.contains("// START '")) {
197+
indent = it.split("//").first()
198+
active = true
199+
readmeMap.add(it.replaceFirst(indent, "") to mutableListOf())
200+
} else if (it.contains("// STOP")) {
201+
active = false
202+
} else if (active) {
203+
readmeMap.last().second.add(it.replaceFirst(indent, ""))
204+
}
205+
}
206+
207+
readmeMap.forEach { (key, value) ->
208+
readme = readme.replace(oldValue = key, newValue = value.joinToString("\n"))
209+
}
210+
211+
File("README.md").writeText(readme)
212+
}
213+
}

0 commit comments

Comments
 (0)