标签: kotlin-exposed

Kotlin Exposed:如何创建准备好的语句或避免 SQL 注入?

我使用 Kotlin Exposed 创建查询。但是当我必须使用从客户端收到的参数时遇到了一个问题:

private fun accountInfo(msg: AccountInfoMsg) {
        transaction {
            val accountInfo = UserAccount.wrapRow(Account.innerJoin(Account_Banned).select {
                Account.email.eq(msg.login.toLowerCase()) and (Account.id eq Account_Banned.accountId)
            }.single())
        }
    }
Run Code Online (Sandbox Code Playgroud)

那么如何创建一个准备好的语句或者如何通过可能的 SQL 注入传递参数呢?

kotlin kotlin-exposed

1
推荐指数
1
解决办法
2860
查看次数

使用 Exposed 不区分大小写的 PSQL 搜索

我们如何在 postgres sql 数据库上使用 Exposed(Kotlin) 进行不区分大小写的搜索?

SELECT users.id, users.name, users.created_at, users.updated_at FROM users 
WHERE users.name iLIKE '%aaa%'
Run Code Online (Sandbox Code Playgroud)

like接线员。我没有看到ilike接线员。我应该在查询字段上使用小写吗?

postgresql kotlin kotlin-exposed

1
推荐指数
1
解决办法
1014
查看次数

如何序列化kotlin暴露的sql dao

我在我的项目中使用kotlin公开的sql我为我的表创建了kotlin对象我也创建了DAO,因为在示例中所有工作都应该如此,但是当我想要返回我的DAO对象列表时,我得到:

com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: org.domcek.dto.Page["columns"]->java.util.ArrayList[0]->org.jetbrains.exposed.sql.Column["table"]->org.domcek.dto.Page["columns"]->java.util.ArrayList[0]->org.jetbrains.exposed.sql.Column["table"]->org.domcek.dto.Page["columns"]->java.util.ArrayList[0]->org.jetbrains.exposed.sql.Column["table"]->org.domcek.dto.Page["columns"]->java.util.ArrayList[0]->org.jetbrains.exposed.sql.Column["table"]->org.domcek.dto.Page["columns"]->java.util.ArrayList[0]->org.jetbrains.exposed.sql.Column["table"]->org.domcek.dto.Page["columns"]->java.util.ArrayList[0]->org.jetbrains.exposed.sql.Column["table"]->org.domcek.dto.Page["columns"]....
Run Code Online (Sandbox Code Playgroud)

我在我的KTOR应用程序中使用jackson

myDao:

class PageDao(id: EntityID<Int>) : IntEntity(id) {
    companion object : IntEntityClass<PageDao>(Page)

    var title by Page.title
    var body by Page.body
    var parentId by Page.parentId
    var active by Page.active
    var order by Page.order
    var slug by Page.slug

    var children: List<PageDao>? = null

    fun isMyParent(pageId: Int): Boolean {
        return pageId == this.parentId
    }
}
Run Code Online (Sandbox Code Playgroud)

将myHandler:

suspend fun findAll(call: ApplicationCall) {
        val pages = pageRepository.getMainPages()

        call.respond(pages)
    }
Run Code Online (Sandbox Code Playgroud)

库:

fun getMainPages(): …
Run Code Online (Sandbox Code Playgroud)

kotlin kotlin-exposed ktor

1
推荐指数
1
解决办法
701
查看次数

Kotlin需要具有Gradle构建的库

我正在尝试将Exposed库添加到我的项目中.所以,它引导我到bintray页面,它说它要使用compile 'org.jetbrains.exposed:exposed:0.8.5'.我打开我的文件build.gradle并将该文件放入dependencies段中:

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
    compile 'org.jetbrains.exposed:exposed:0.8.5'
}
Run Code Online (Sandbox Code Playgroud)

IntelliJ auto构建它,我收到以下错误

警告:根项目'DB-Table-To-Orm':无法构建Kotlin项目配置详细信息:java.lang.reflect.InvocationTargetException:null由以下原因引起:org.gradle.api.artifacts.ResolveException:无法解析所有依赖项配置':compileClasspath'.引起:org.gradle.internal.resolve.ModuleVersionNotFoundException:找不到org.jetbrains.exposed:expposed:0.8.5.在以下位置搜索:https : //repo1.maven.org/maven2/org/jetbrains/exposed/exposed/0.8.5/exposed-0.8.5.pom https://repo1.maven.org/maven2/org /jetbrains/exposed/exposed/0.8.5/exposed-0.8.5.jar 必需:project:

所以,我期待在回购并没有超出路径jetbrainsexposed目录.

如何使用Gradle安装Exposed库?他们的路径写得不正确吗?我应该在项目中添加错误报告吗?或者我只是把compile声明放在错误的位置?

很抱歉,如果这似乎是一个愚蠢的要求,我是新来的JavalandKotlinIntelliJ.走向.NET世界.

更新

这是build.gradle完整的:

group 'com.awebsite.db-table-to-orm'
version '1.0-SNAPSHOT'

buildscript {
    ext.kotlin_version = '1.1.4-2'

    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

apply plugin: 'kotlin'

repositories {
    mavenCentral()
    jcenter()
} …
Run Code Online (Sandbox Code Playgroud)

gradle kotlin kotlin-exposed

0
推荐指数
1
解决办法
875
查看次数

Kotlin-Exposed在其Wiki上的示例不起作用

此代码直接从Kotlin公开的Wiki中提取,但不起作用。奇怪而令人沮丧的是,我无法实现它,因为我有一个很棒的项目,需要使用RDBMS。我想念什么?坏了吗

import org.jetbrains.exposed.sql.StdOutSqlLogger
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.Table
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.selectAll

fun main(args: Array<String>) {
    Database.connect("jdbc:h2:mem:test", driver = "org.h2.Driver")

    transaction {
        logger.addLogger(StdOutSqlLogger)

        val stPeteId = Cities.insert {
            it[name] = "St. Petersburg"
        } get Cities.id

        println("Cities: ${Cities.selectAll()}")
    }
}

// Table definition
object Cities : Table() {
    val id = integer("id").autoIncrement().primaryKey()
    val name = varchar("name", 50)
}
// Entity definition
data class City(
        val id: Int,
        val name: String
)
Run Code Online (Sandbox Code Playgroud)

在Intellij中运行时,我收到以下错误消息:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". …
Run Code Online (Sandbox Code Playgroud)

intellij-idea h2 kotlin kotlin-exposed

0
推荐指数
1
解决办法
1547
查看次数

Kotlin 根据条件公开总和 (CaseWhenElse)

我有一个数据结构如下的表:

id    type   cityName   regDate
1249     0   City1      2019-10-01
Run Code Online (Sandbox Code Playgroud)

我想要获得唯一城市的结果输出以及每月的注册数量,作为以下数据类对象的列表

data class NewClientsNumberCityMonth(
    val cityName: String = "",
    val januaryNewClientsNumber :Int = 0,
    val februaryNewClientsNumber :Int = 0,
    val marchNewClientsNumber :Int = 0,
    val aprilNewClientsNumber :Int = 0,
    val mayNewClientsNumber :Int = 0,
    val juneNewClientsNumber :Int = 0,
    val julyNewClientsNumber :Int = 0,
    val augustNewClientsNumber :Int = 0,
    val septemberNewClientsNumber :Int = 0,
    val octoberNewClientsNumber :Int = 0,
    val novemberNewClientsNumber :Int = 0,
    val decemberNewClientsNumber :Int = 0
    val total …
Run Code Online (Sandbox Code Playgroud)

kotlin kotlin-exposed

0
推荐指数
1
解决办法
1623
查看次数

Kotlin 暴露未解决的参考:referencedOn

我正在尝试使用框架开发 REST API Ktor,在阅读了一些教程和官方文档后,我刚刚实现了一个示例代码。我也在使用 Kotlin Exposed,我只是想创建一些数据库表并连接它们。所以我做了两个类UsersRepo并且RolesRepo都扩展了IntIdTable. 我只想在这两个表之间建立一对一的关系,所以我做了这样的事情:

object UsersRepo : IntIdTable("userId") {
    val displayName = varchar("display_name", 256)
    val role = reference("role", RolesRepo)
}
Run Code Online (Sandbox Code Playgroud)

然后,我只想为用户实现实体类,而 IDE 无法识别该referencedOn关键字。在此输入图像描述

我不知道我在这里缺少什么。我正在使用 Ktor 和 Kotlin1.4.0以及 Kotlin Exposed 版本0.25.1

    implementation "org.jetbrains.exposed:exposed-core:$exposed_version"
    implementation "org.jetbrains.exposed:exposed-dao:$exposed_version"
    implementation "org.jetbrains.exposed:exposed-jdbc:$exposed_version"
Run Code Online (Sandbox Code Playgroud)

kotlin kotlin-exposed ktor

0
推荐指数
1
解决办法
1785
查看次数

标签 统计

kotlin ×7

kotlin-exposed ×7

ktor ×2

gradle ×1

h2 ×1

intellij-idea ×1

postgresql ×1