Leoš Přikryl
leos.prikryl@commity.cz
@leos_prikryl
SELECT last_name, first_name
FROM "user"
WHERE role = 'admin'
ORDER BY last_name, first_name
dsl.select(USER.LAST_NAME, USER.FIRST_NAME)
.from(USER)
.where(USER.ROLE.eq("admin"))
.orderBy(USER.LAST_NAME, USER.FIRST_NAME)
Použití špatného datového typu pro sloupec ROLE
dsl.select(USER.LAST_NAME, USER.FIRST_NAME)
.from(USER)
.where(USER.ROLE.eq(1))
Po přejmenování LAST_NAME na SURNAME a přegenerování kódu
dsl.select(USER.LAST_NAME, USER.FIRST_NAME)
.from(USER)
.where(USER.ROLE.eq("admin"))
dsl.select(USER.LAST_NAME, USER.FIRST_NAME)
.from(USER)
.where(USER.ROLE.eq("admin"))
.orderBy(USER.LAST_NAME, USER.FIRST_NAME)
dsl.select(field("last_name"), field("first_name"))
.from(table("user"))
.where(field("role").eq("admin"))
.orderBy(field("last_name"), field("first_name"))
SELECT author.first_name, author.last_name, count(*)
FROM author
JOIN book ON book.author_id = author.id
JOIN language ON book.language_id = language.id
WHERE language.code = 'CZ'
AND book.published_in > DATE '2020-01-01'
GROUP BY author.first_name, author.last_name
HAVING COUNT(*) > 5
ORDER BY author.last_name ASC NULLS FIRST
LIMIT 5
OFFSET 10
ctx.select(AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME, count())
.from(AUTHOR)
.join(BOOK).onKey()
.join(LANGUAGE).onKey()
.where(LANGUAGE.CODE.eq("CZ")
.and(BOOK.PUBLISHED_IN.gt(LocalDate.of(2020, 1, 1))))
.groupBy(AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME)
.having(count().gt(5))
.orderBy(AUTHOR.LAST_NAME.asc().nullsFirst())
.limit(5)
.offset(10)
data class Book(
val id: Int,
val title: String?
)
ctx.select(BOOK.ID, BOOK.TITLE)
.from(BOOK)
.fetchInto(Book::class.java)
ctx.insertInto(AUTHOR, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME)
.values("Jack", "London")
.execute();
val author = ctx.newRecord(AUTHOR).apply {
firstName = "Jack"
lastName = "London"
}
author.store()
val author = Author().apply {
firstName = "Jack"
lastName = "London"
}
authorDao.insert(author)
{
"id": 1,
"name": {
"first": "George",
"last": "Orwell"
},
"books": [
{
"id": 1,
"title": "1984"
},
{
"id": 2,
"title": "Animal Farm"
}
]
}
data class Author(
val id: Int,
val name: Name,
val books: Array<Book>
)
data class Name(
val first: String,
val last: String
)
data class Book(
val id: Int,
val title: String
)
ctx.select(
AUTHOR.ID,
row(AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME).`as`("name"),
multiset(
select(row(BOOK.ID, BOOK.TITLE))
.from(BOOK)
.where(BOOK.AUTHOR_ID.eq(AUTHOR.ID))
).`as`("books")
)
.from(AUTHOR)
.fetchInto(Author::class.java)