Skip to content
View kotoframework's full-sized avatar

Highlights

  • Pro

Block or report kotoframework

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Please don't include any personal information such as legal names or email addresses. Maximum 100 characters, markdown supported. This note will be visible to only you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
kotoframework/docs/README.md

Koto SQL Framework for Kotlin

🎉Kronos ORM (Koto v2.0) has been open sourced and is constantly being improved. It is based on the compiler plug-in developed for Kotlin K2, and its performance and ease of use have been greatly improved. Welcome to follow

📖 Offical Website and Document

=============================

build Maven central Sonatype Nexus (Snapshots) License Coverage Status

koto

English🇬🇧 | 中文🇨🇳

official website: https://kotoframework.com

❓What is "koto"?

An easy-to-use, flexible, lightweight data persistence layer ORM framework designed for kotlin.

Koto has designed concise operation entities and APIs. In most cases, only one line is needed to complete complex logical functions on database tables:

val list = select<User>().queryForList() // list: List<User>

The actual SQL statement executed:

select `user_name`                                     as `userName`,
       `nickname`,
       `id`,
       `active`,
       DATE_FORMAT(`create_time`, '%Y-%m-%d %H:%i:%s') as `createTime`,
       DATE_FORMAT(`update_time`, '%Y-%m-%d %H:%i:%s') as `updateTime`
from user

You can also use the query function to return a List<Map<String, Any>>:

val list = select<User>().query() // list: List<Map<String, Any>>

The actual SQL statement executed:

select `user_name`                                     as `userName`,
       `nickname`,
       `id`,
       `active`,
       DATE_FORMAT(`create_time`, '%Y-%m-%d %H:%i:%s') as `createTime`,
       DATE_FORMAT(`update_time`, '%Y-%m-%d %H:%i:%s') as `updateTime`
from user

❓Why use "koto"?

  1. Lightweight, only 200KB in size, hardly need any additional dependencies
  2. Simple configuration, almost no configuration required
  3. Supports object-relational mapping, which can be easily used to map between relational databases and business entity objects.
  4. The writing method is simple and flexible, using chain calls, default parameters, extension functions and other writing methods, which are perfectly combined with Kotlin syntax.
  5. It is easy to debug and has powerful and perfect log function.
  6. Support multiple data sources, dynamic data sources, transactions with multiple data sources, and distributed transactions with multiple data sources.
  7. Provide supporting code generator and ide plugin

❓How to use "koto"?

1. Add dependency

1.0.4-SNAPSHOT is the latest version, which is compatible with all versions of Kotlin.

maven
<dependency>
    <groupId>com.kotoframework</groupId>
    <artifactId>koto-core</artifactId>
    <version>1.0.3</version>
</dependency>
gradle
compile "com.kotoframework:koto-core:1.0.3"
complie("com.kotoframework:koto-core:1.0.3")

if use the latest snapshot version, use 1.0.4-SNAPSHOT

maven
<repository>
   <id>sonatype-nexus-snapshots</id>
   <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
   <releases>
       <enabled>false</enabled>
   </releases>
   <snapshots>
       <enabled>true</enabled>
       <updatePolicy>daily</updatePolicy>
       <checksumPolicy>fail</checksumPolicy>
   </snapshots>
</repository>

<dependency>
    <groupId>com.kotoframework</groupId>
    <artifactId>koto-core</artifactId>
    <version>1.0.4-SNAPSHOT</version>
</dependency>
gradle
implementation("com.kotoframework:koto-core:1.0.4-SNAPSHOT")
kotlin
implementation("com.kotoframework:koto-core:1.0.4-SNAPSHOT")

2. Configuration

koto-config.md

⌨️ Write your first query function using Koto!

🎉Congratulations you have completed the configuration of Koto, now you can start to operate data easily and simply!

Below we will write our first function using Koto:

koto does automatic mapping via type inference, which makes our queries very concise!

fun getUserInfoById(id): User {
    return select(User(1)).where().queryForObject()

    // another way of writing
    //select(User(1)).by("id").queryForObject()
}
// Koto actually supports more intuitive writing methods, see the specific Api documentation for details
// select(User(1)).by("id").queryForObject()
// select(User(1)).by(User::id).queryForObject()
// select(User(1)).where { it::id.eq }.queryForObject()
// select<User>().where { it::id.eq(1) }.queryForObject()
// select(User(1)).by("id").queryForObject()
// from<User> {  it.select(it).by(it::id to 1) }.queryForObject()

You can also use Where to build more complex query conditions, such as:

fun getUserBySomeCondition(user: User): UserInfo? { // query for object or null
    return select(user).where{
        it::id.eq and
        it::userName.notNull and
        it::active.eq(true) and
        it::age.lt() // < user.age
   }.queryForObjectOrNull()
}

fun getUser(user: User): Pair<List<User>, Int>{ // query for list and count
    return select(user).where{
        it::id.eq and
        it::userName.eq and
        it::active.eq and
        it::age.eq
    }
      .orderBy(it::id.desc)
      .page(1, 10)
      .withTotal{
          it.queryForList()
      }
   //can be simplified to return select(user).where().orderBy... 
}

quickly create or delete a record by passing in an KPojo data class:

create(user).execute()

remove(user).byId().execute()

📚Koto Api Documentation

https://api.kotoframework.com

📚Koto Code Generator

https://kotoframework.com/#/code-generator

📚Koto Ide Plugin

https://kotoframework.com/#/ide-plugin

📚Koto Official Website

https://kotoframework.com

📚Koto Official Blog

https://blog.kotoframework.com

📚Koto Official Document

https://koto.fun

Pinned Loading

  1. kotoframework kotoframework Public

    An easy-to-use, flexible, lightweight data persistence layer ORM framework designed for kotlin.

    Kotlin 5