Skip to content

Commit 9dac7b0

Browse files
update readme
1 parent 00abda0 commit 9dac7b0

File tree

2 files changed

+79
-4
lines changed

2 files changed

+79
-4
lines changed

README.md

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,65 @@
1-
# KtOrm
2-
A lightweight ORM Framework for Kotlin with strong typed SQL DSL. https://ktorm.liuwj.me
1+
# What's KtOrm?
2+
3+
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 duplication of effort. All the SQLs are generated automaticlly, of course.
34

4-
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/2cf0d4b81c3546809ad2f83a795c34c2)](https://app.codacy.com/app/vincentlauvlwj/KtOrm?utm_source=github.com&utm_medium=referral&utm_content=vincentlauvlwj/KtOrm&utm_campaign=Badge_Grade_Dashboard)
55
[![Build Status](https://www.travis-ci.org/vincentlauvlwj/KtOrm.svg?branch=master)](https://www.travis-ci.org/vincentlauvlwj/KtOrm)
66
[![Maven Central](https://img.shields.io/maven-central/v/me.liuwj.ktorm/ktorm-core.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22me.liuwj.ktorm%22)
77
[![Download](https://api.bintray.com/packages/vincentlauvlwj/maven/ktorm-core/images/download.svg)](https://bintray.com/vincentlauvlwj/maven)
88
[![Apache License 2](https://img.shields.io/badge/license-Apache%202-blue.svg?maxAge=2592000)](LICENSE)
9-
[![Author](https://img.shields.io/badge/author-vince-yellowgreen.svg)](https://www.liuwj.me)
9+
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/2cf0d4b81c3546809ad2f83a795c34c2)](https://app.codacy.com/app/vincentlauvlwj/KtOrm?utm_source=github.com&utm_medium=referral&utm_content=vincentlauvlwj/KtOrm&utm_campaign=Badge_Grade_Dashboard)
10+
[![Author](https://img.shields.io/badge/author-vince-yellowgreen.svg)](https://www.liuwj.me)
11+
12+
# Features
13+
14+
- No configuration files, no xml, lightweight, easy to use.
15+
- Strong typed SQL DSL, exposing low-level bugs at compile time.
16+
- Flexiable query, exactly control the generated SQLs as you wish.
17+
- Extensible design, write your own extensions to support more data types, SQL functions, etc.
18+
- Dialects supported, MySQL, Oracle, PostgreSQL, or you can write your own dialect by implementing the `SqlDialect` interface.
19+
20+
# Quick Start
21+
22+
KtOrm was deployed to maven central and jcenter, so you just need to a dependency to your `pom.xml` file if you are using maven:
23+
24+
````xml
25+
<dependency>
26+
<groupId>me.liuwj.ktorm</groupId>
27+
<artifactId>ktorm-core</artifactId>
28+
<version>${ktorm.version}</version>
29+
</dependency>
30+
````
31+
32+
Or Gradle:
33+
34+
````groovy
35+
compile "me.liuwj.ktorm:ktorm-core:${ktorm.version}"
36+
````
37+
38+
Then create a kotlin object to describe your table schema:
39+
40+
````kotlin
41+
object Employees : Table<Nothing>("t_employee") {
42+
val id by int("id").primaryKey()
43+
val name by varchar("name")
44+
val job by varchar("job")
45+
val managerId by int("manager_id")
46+
val hireDate by date("hire_date")
47+
val salary by long("salary")
48+
val departmentId by int("department_id")
49+
}
50+
````
51+
52+
Now connect to your database and write a simple query:
53+
54+
````kotlin
55+
fun main() {
56+
Database.connect("jdbc:mysql://localhost:3306/ktorm", driver = "com.mysql.jdbc.Driver")
57+
58+
for (row in Employees.select()) {
59+
println(row[Employees.name])
60+
}
61+
}
62+
````
63+
64+
When you run this program, KtOrm will generate a SQL `select * from t_employee`, selecting all employees in the table and printing their names.
65+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package me.liuwj.ktorm
2+
3+
import me.liuwj.ktorm.schema.*
4+
5+
object Departments : Table<Nothing>("t_departments") {
6+
val id by int("id").primaryKey()
7+
val name by varchar("name")
8+
val location by varchar("location")
9+
}
10+
11+
object Employees : Table<Nothing>("t_employee") {
12+
val id by int("id").primaryKey()
13+
val name by varchar("name")
14+
val job by varchar("job")
15+
val managerId by int("manager_id")
16+
val hireDate by date("hire_date")
17+
val salary by long("salary")
18+
val departmentId by int("department_id")
19+
}

0 commit comments

Comments
 (0)