{"id":19348030,"url":"https://github.com/korlibs/kminiorm","last_synced_at":"2025-04-23T05:32:57.879Z","repository":{"id":57727141,"uuid":"211091810","full_name":"korlibs/kminiorm","owner":"korlibs","description":"ORM for Kotlin supporting JDBC and MongoDB","archived":false,"fork":false,"pushed_at":"2022-02-12T06:14:55.000Z","size":418,"stargazers_count":9,"open_issues_count":1,"forks_count":1,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-05-02T02:09:52.536Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://bintray.com/soywiz/soywiz/kminiorm","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/korlibs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"soywiz","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2019-09-26T13:09:11.000Z","updated_at":"2024-01-31T04:36:12.000Z","dependencies_parsed_at":"2022-09-26T21:51:15.974Z","dependency_job_id":null,"html_url":"https://github.com/korlibs/kminiorm","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/korlibs%2Fkminiorm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/korlibs%2Fkminiorm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/korlibs%2Fkminiorm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/korlibs%2Fkminiorm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/korlibs","download_url":"https://codeload.github.com/korlibs/kminiorm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223910568,"owners_count":17223711,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T04:18:50.128Z","updated_at":"2024-11-10T04:18:50.633Z","avatar_url":"https://github.com/korlibs.png","language":"Kotlin","funding_links":["https://github.com/sponsors/soywiz"],"categories":[],"sub_categories":[],"readme":"# kminiorm\n\n\u003c!-- BADGES --\u003e\n\u003cp align=\"center\"\u003e\n\t\u003ca href=\"https://github.com/korlibs/kminiorm/actions\"\u003e\u003cimg alt=\"Build Status\" src=\"https://github.com/korlibs/kminiorm/workflows/CI/badge.svg\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://search.maven.org/artifact/com.soywiz.korlibs.kminiorm/kminiorm\"\u003e\u003cimg alt=\"Maven Central\" src=\"https://img.shields.io/maven-central/v/com.soywiz.korlibs.kminiorm/kminiorm\"\u003e\u003c/a\u003e\n\t\u003ca href=\"https://discord.korge.org/\"\u003e\u003cimg alt=\"Discord\" src=\"https://img.shields.io/discord/728582275884908604?logo=discord\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003c!-- /BADGES --\u003e\n\nORM for Kotlin supporting JDBC and MongoDB\n\n### Full Documentation: \u003chttps://docs.korge.org/old/kminiorm/\u003e\n\n## Gradle:\n\n```kotlin\ndef kminiOrmVersion = \"...\" // Find latest version on this README\n\nrepositories {\n    // ...\n    mavenCentral()\n}\ndependencies {\n    // Core:\n    implementation(\"com.soywiz.korlibs.kminiorm:kminiorm-jvm:$kminiOrmVersion\")\n    // JDBC:\n    implementation(\"com.soywiz.korlibs.kminiorm:kminiorm-jdbc-jvm:$kminiOrmVersion\")\n    implementation(\"org.xerial:sqlite-jdbc:3.30.1\")\n    implementation(\"com.h2database:h2:1.4.200\")\n    // Mongo:\n    implementation(\"com.soywiz.korlibs.kminiorm:kminiorm-mongo-jvm:$kminiOrmVersion\")\n}\n```\n\n## Sample:\n\nYou can run `./sample.main.kts` to get it working.\n\n```kotlin\nimport com.soywiz.kminiorm.*\nimport com.soywiz.kminiorm.dialect.*\nimport com.soywiz.kminiorm.where.*\nimport kotlinx.coroutines.flow.*\nimport kotlinx.coroutines.*\nimport java.io.*\n\nfun main() = runBlocking {\n    data class MyTable(\n        @DbPrimary val key: String,\n        @DbIndex val value: Long\n    ) : DbBaseModel\n\n    val sqliteFile = File(\"sample.sq3\")\n    val db = JdbcDb(\n        \"jdbc:sqlite:${sqliteFile.absoluteFile.toURI()}\",\n        debugSQL = System.getenv(\"DEBUG_SQL\") == \"true\",\n        dialect = SqliteDialect,\n        async = true\n    )\n\n    val table = db.table\u003cMyTable\u003e()\n    table.insert(\n        MyTable(\"hello\", 10L),\n        MyTable(\"world\", 20L),\n        MyTable(\"this\", 30L),\n        MyTable(\"is\", 40L),\n        MyTable(\"a\", 50L),\n        MyTable(\"test\", 60L),\n        onConflict = DbOnConflict.IGNORE\n    )\n\n    table.where { it::value ge 20L }.limit(10).collect {\n        println(it)\n    }\n    Unit\n}\n```\n\n## Defining Tables\n\nYou can use normal Kotlin fields\n\n```kotlin\ndata class MyTable(\n    @DbPrimary val key: String,\n    @DbIndex val value: Long\n) : DbBaseModel\n```\n\n### Multi-column indices\n\n```kotlin\ndata class MyTable(\n    @DbUnique(\"a_b\") val a: String,\n    @DbUnique(\"a_b\") val b: String\n) : DbBaseModel\n```\n\n## Creating a Repository\n\n## Migrations\n\nIf you change a table adding a new field to it,\nyou can register a DbMigration that will be executed\nwhen the ALTER TABLE is automatically performed.\n\n```kotlin\ndata class MyTable(\n    val a: String,\n    @DbPerformMigration(MyAddColumnMigration::class) val newlyAddedField: String // \n) : DbBaseModel {\n    class MyAddColumnMigration : DbMigration\u003cMyTable\u003e {\n        override suspend fun migrate(table: DbTable\u003cMyTable\u003e, action: DbMigration.Action, column: ColumnDef\u003cMyTable\u003e?) {\n            table.where.collect { item -\u003e \n                // Update item here ...\n            }\n        }\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkorlibs%2Fkminiorm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkorlibs%2Fkminiorm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkorlibs%2Fkminiorm/lists"}