+
Skip to content

kotlin-orm/ktorm

Repository files navigation

What's KtOrm?

KtOrm is a lightweight and efficient ORM Framework for Kotlin directly based on pure JDBC. It provides strong typed and flexiable SQL DSL and many convenient extension functions to reduce our duplicated effort on database operations. All the SQLs are generated automaticlly, of course. For more documentation, go to our site: https://ktorm.liuwj.me.

🇺🇸 English | 🇨🇳 简体中文

Build Status Maven Central Download Apache License 2 Codacy Badge Author

Features

  • No configuration files, no xml, lightweight, easy to use.
  • Strong typed SQL DSL, exposing low-level bugs at compile time.
  • Flexiable query, exactly control the generated SQLs as you wish.
  • Extensible design, write your own extensions to support more data types, SQL functions, etc.
  • Dialects supports, MySQL, Oracle, PostgreSQL, or you can write your own dialect support by implementing the SqlDialect interface.

Quick Start

KtOrm was deployed to maven central and jcenter, so you just need to add a dependency to your pom.xml file if you are using maven:

<dependency>
    <groupId>me.liuwj.ktorm</groupId>
    <artifactId>ktorm-core</artifactId>
    <version>${ktorm.version}</version>
</dependency>

Or Gradle:

compile "me.liuwj.ktorm:ktorm-core:${ktorm.version}"

Then create a Kotlin object to describe your table schema:

object Employees : Table<Nothing>("t_employee") {
    val id by int("id").primaryKey()
    val name by varchar("name")
    val job by varchar("job")
    val managerId by int("manager_id")
    val hireDate by date("hire_date")
    val salary by long("salary")
    val departmentId by int("department_id")
}

Now connect to your database and write a simple query:

fun main() {
    Database.connect("jdbc:mysql://localhost:3306/ktorm", driver = "com.mysql.jdbc.Driver")

    for (row in Employees.select()) {
        println(row[Employees.name])
    }
}

When you run this program, KtOrm will generate a SQL select * from t_employee, selecting all employees in the table and printing their names.

About

A lightweight ORM framework for Kotlin with strong-typed SQL DSL and sequence APIs.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

Contributors 31

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载