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

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;
"""
)
```