Update documentation

This commit is contained in:
2021-09-28 01:39:21 +02:00
parent ac2afbcf93
commit 4e4816eb77
5 changed files with 124 additions and 8 deletions

BIN
docs/call function.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

52
docs/call function.puml Normal file
View File

@@ -0,0 +1,52 @@
@startuml
participant Gradle
participant App
control Migration
control Repository
control Requester
control Function
control Connection
database Database
== Migration ==
[-> Gradle++ : run gradle
Gradle -> Migration** : Init Migration
Migration -> Migration : Read Schemas
Migration -> Migration : Read SQL Function
Gradle -> Migration++ : Run Migrations
Migration -> Migration : Run Migrations
return
Gradle -> Migration!!
return
== Application ==
[-> App : run app
App -> Connection** : Create Connection
Connection -> Database : Connect to the database
App -> Requester** : Create Requester
Requester -> Requester: Read all Function file
Requester -> Function** : Create Function object
Function -> Function : Parse function
Function -> Function : Store parameters and function name
App -> Repository** : Create Repository
... wait request ...
[-> Repository++ : call repository with args
Repository -> Repository : Define function name
Repository -> Requester++ : get function
Requester -> Function++ : select()
Function -> Function : Compile args
Function -> Function : Compile SQL
Function -> Connection++ : select()
Connection -> Database++ : Send Prepared Statement
return
Connection -> Connection : Convert json to Entity
return entity
return entity
return entity
return entity
@enduml

9
docs/checklist.md Normal file
View File

@@ -0,0 +1,9 @@
# Checklist
- [ ] Define schemas with migrations files (*.up.sql & *.down.sql)
- [ ] Define query with sql function (*.sql)
- [ ] Create Entity (*.kt)
- [ ] Create repository (*.kt)
- [ ] Configure migrations in gradle
- [ ] Execute migrations functions
- [ ] Call Repository

View File

@@ -24,9 +24,11 @@ val connection: Connection = TODO()
data class Inventor(
val id: UUID = UUID.randomUUID(),
val name: String
val name: String,
val roles: List<String> = listOf(),
): Serializable
// Select one entity
val result: Inventor? = connection.selectOne(
"""
SELECT json_build_object(
@@ -37,9 +39,47 @@ val result: Inventor? = connection.selectOne(
mapOf("name" to "Nikola Tesla")
)
val inventor = connection.selectOne<Inventor>("SELECT * FROM mytable WHERE id = :id")
// Select multiple entities
val result = connection.select<List<Inventor>>(
"""
SELECT json_build_array(
json_build_object(
'id', '9e65de49-712e-47ce-8bf2-dfffae53a82e',
'name', :name
),
json_build_object(
'id', '32f67ed3-af6d-403b-a3b9-5fe3540c3412',
'name', :name2
)
)
""",
mapOf(
"name" to "Nikola Tesla",
"name2" to "Albert Einstein",
)
)
val inventors: List<Inventor> = connection.select("SELECT * FROM mytable WHERE status = 'done'")
// Select multiple with real query
val result: List<Inventor> = connection.select(
"""
select json_agg(i)
from inventor i
where roles @> ARRAY[:role];
""",
mapOf("role" to "ADMIN")
)
// Select multiple with only some rows
val result: List<Inventor> = connection.select(
"""
select json_agg(i)
from (
select id, name
from inventor
) i;
"""
)
```