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(
|
||||
|
||||
Reference in New Issue
Block a user