Update kotlin libs
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package be.simplenotes.persistence
|
||||
|
||||
import org.flywaydb.core.Flyway
|
||||
import javax.inject.Singleton
|
||||
import jakarta.inject.Singleton
|
||||
import javax.sql.DataSource
|
||||
|
||||
interface DbMigrations {
|
||||
@@ -14,6 +14,7 @@ internal class DbMigrationsImpl(private val dataSource: DataSource) : DbMigratio
|
||||
Flyway.configure()
|
||||
.dataSource(dataSource)
|
||||
.locations("db/migration")
|
||||
.loggers("slf4j")
|
||||
.load()
|
||||
.migrate()
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import io.micronaut.context.annotation.Bean
|
||||
import io.micronaut.context.annotation.Factory
|
||||
import org.ktorm.database.Database
|
||||
import org.ktorm.database.SqlDialect
|
||||
import javax.inject.Singleton
|
||||
import jakarta.inject.Singleton
|
||||
import javax.sql.DataSource
|
||||
|
||||
@Factory
|
||||
@@ -17,10 +17,13 @@ class PersistenceModule {
|
||||
@Singleton
|
||||
internal fun database(migrations: DbMigrations, dataSource: DataSource): Database {
|
||||
migrations.migrate()
|
||||
return Database.connect(dataSource, dialect = object : SqlDialect {
|
||||
override fun createSqlFormatter(database: Database, beautifySql: Boolean, indentSize: Int) =
|
||||
CustomSqlFormatter(database, beautifySql, indentSize)
|
||||
})
|
||||
return Database.connect(
|
||||
dataSource,
|
||||
dialect = object : SqlDialect {
|
||||
override fun createSqlFormatter(database: Database, beautifySql: Boolean, indentSize: Int) =
|
||||
CustomSqlFormatter(database, beautifySql, indentSize)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@Singleton
|
||||
|
||||
@@ -11,8 +11,9 @@ internal class VarcharArraySqlType : SqlType<List<String>>(Types.ARRAY, typeName
|
||||
override fun doGetResult(rs: ResultSet, index: Int): List<String>? {
|
||||
return when (val array = rs.getObject(index)) {
|
||||
null -> null
|
||||
is java.sql.Array -> (array.array as Array<*>).filterNotNull().map { it.toString() }
|
||||
is Array<*> -> array.map { it.toString() }
|
||||
else -> error("")
|
||||
else -> error("Unable to deserialize varchar[]")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +28,7 @@ data class ArrayContainsExpression(
|
||||
val left: ScalarExpression<*>,
|
||||
val right: ScalarExpression<*>,
|
||||
override val sqlType: SqlType<Boolean> = BooleanSqlType,
|
||||
override val isLeafNode: Boolean = false
|
||||
override val isLeafNode: Boolean = false,
|
||||
) : ScalarExpression<Boolean>() {
|
||||
override val extraProperties: Map<String, Any> get() = emptyMap()
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ interface NoteRepository {
|
||||
limit: Int = 20,
|
||||
offset: Int = 0,
|
||||
tag: String? = null,
|
||||
deleted: Boolean = false
|
||||
deleted: Boolean = false,
|
||||
): List<PersistedNoteMetadata>
|
||||
|
||||
fun count(userId: Int, tag: String? = null, deleted: Boolean = false): Int
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.ktorm.dsl.*
|
||||
import org.ktorm.entity.*
|
||||
import java.time.LocalDateTime
|
||||
import java.util.*
|
||||
import javax.inject.Singleton
|
||||
import jakarta.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
internal class NoteRepositoryImpl(
|
||||
@@ -40,14 +40,18 @@ internal class NoteRepositoryImpl(
|
||||
val uuid = UUID.randomUUID()
|
||||
val entity = converter.toEntity(note, uuid, userId, LocalDateTime.now())
|
||||
db.notes.add(entity)
|
||||
db.batchInsert(Tags) {
|
||||
note.tags.forEach { tagName ->
|
||||
item {
|
||||
set(it.noteUuid, uuid)
|
||||
set(it.name, tagName)
|
||||
|
||||
note.tags.takeIf { it.isNotEmpty() }?.run {
|
||||
db.batchInsert(Tags) {
|
||||
forEach { tagName ->
|
||||
item {
|
||||
set(it.noteUuid, uuid)
|
||||
set(it.name, tagName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return find(userId, uuid) ?: error("Note not found")
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.ktorm.dsl.*
|
||||
import org.ktorm.entity.any
|
||||
import org.ktorm.entity.find
|
||||
import java.sql.SQLIntegrityConstraintViolationException
|
||||
import javax.inject.Singleton
|
||||
import jakarta.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
internal class UserRepositoryImpl(
|
||||
|
||||
@@ -11,7 +11,7 @@ import javax.sql.DataSource
|
||||
@ResourceLock("h2")
|
||||
abstract class DbTest {
|
||||
|
||||
val beanContext = ApplicationContext.build().deduceEnvironment(false).environments("test").start()
|
||||
val beanContext = ApplicationContext.builder().deduceEnvironment(false).environments("test").start()
|
||||
|
||||
inline fun <reified T> BeanContext.getBean(): T = getBean(T::class.java)
|
||||
|
||||
@@ -22,6 +22,8 @@ abstract class DbTest {
|
||||
|
||||
Flyway.configure()
|
||||
.dataSource(dataSource)
|
||||
.loggers("slf4j")
|
||||
.cleanDisabled(false)
|
||||
.load()
|
||||
.clean()
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.Nested
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.parallel.ResourceLock
|
||||
import org.ktorm.database.Database
|
||||
import org.ktorm.dsl.eq
|
||||
import org.ktorm.entity.filter
|
||||
@@ -22,7 +21,6 @@ import org.ktorm.entity.mapColumns
|
||||
import org.ktorm.entity.toList
|
||||
import java.sql.SQLIntegrityConstraintViolationException
|
||||
|
||||
|
||||
internal class NoteRepositoryImplTest : DbTest() {
|
||||
|
||||
private lateinit var noteRepo: NoteRepository
|
||||
@@ -86,14 +84,14 @@ internal class NoteRepositoryImplTest : DbTest() {
|
||||
.hasSize(3)
|
||||
.usingElementComparatorIgnoringFields("updatedAt")
|
||||
.containsExactlyInAnyOrderElementsOf(
|
||||
notes1.map { it.toPersistedMeta() }
|
||||
notes1.map { it.toPersistedMeta() },
|
||||
)
|
||||
|
||||
assertThat(noteRepo.findAll(user2.id))
|
||||
.hasSize(1)
|
||||
.usingElementComparatorIgnoringFields("updatedAt")
|
||||
.containsExactlyInAnyOrderElementsOf(
|
||||
notes2.map { it.toPersistedMeta() }
|
||||
notes2.map { it.toPersistedMeta() },
|
||||
)
|
||||
|
||||
assertThat(noteRepo.findAll(1000)).isEmpty()
|
||||
@@ -131,7 +129,9 @@ internal class NoteRepositoryImplTest : DbTest() {
|
||||
|
||||
val note = db.notes.find { Notes.title eq fakeNote.title }!!
|
||||
.let { entity ->
|
||||
val tags = db.tags.filter { be.simplenotes.persistence.Tags.noteUuid eq entity.uuid }.mapColumns { be.simplenotes.persistence.Tags.name } as List<String>
|
||||
val tags = db.tags.filter {
|
||||
be.simplenotes.persistence.Tags.noteUuid eq entity.uuid
|
||||
}.mapColumns { be.simplenotes.persistence.Tags.name } as List<String>
|
||||
PersistedNote(
|
||||
uuid = entity.uuid,
|
||||
title = entity.title,
|
||||
|
||||
Reference in New Issue
Block a user