|
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. |
3 | 4 |
|
4 |
| -[](https://app.codacy.com/app/vincentlauvlwj/KtOrm?utm_source=github.com&utm_medium=referral&utm_content=vincentlauvlwj/KtOrm&utm_campaign=Badge_Grade_Dashboard) |
5 | 5 | [](https://www.travis-ci.org/vincentlauvlwj/KtOrm)
|
6 | 6 | [](https://search.maven.org/search?q=g:%22me.liuwj.ktorm%22)
|
7 | 7 | [](https://bintray.com/vincentlauvlwj/maven)
|
8 | 8 | [](LICENSE)
|
9 |
| -[](https://www.liuwj.me) |
| 9 | +[](https://app.codacy.com/app/vincentlauvlwj/KtOrm?utm_source=github.com&utm_medium=referral&utm_content=vincentlauvlwj/KtOrm&utm_campaign=Badge_Grade_Dashboard) |
| 10 | +[](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 | + |
0 commit comments