{"id":19543135,"url":"https://github.com/tanvd/aorm","last_synced_at":"2025-08-10T16:37:29.569Z","repository":{"id":46150941,"uuid":"109894790","full_name":"TanVD/AORM","owner":"TanVD","description":"Clickhouse Kotlin SQL Framework","archived":false,"fork":false,"pushed_at":"2024-04-08T18:48:05.000Z","size":862,"stargazers_count":42,"open_issues_count":3,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-08T22:11:21.800Z","etag":null,"topics":["analytics","clickhouse","kotlin","orm","sql"],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TanVD.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-11-07T21:47:17.000Z","updated_at":"2024-04-08T22:11:21.800Z","dependencies_parsed_at":"2023-01-19T22:19:24.816Z","dependency_job_id":"3d1399bf-0c15-4859-8088-0faea5dd9e31","html_url":"https://github.com/TanVD/AORM","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TanVD%2FAORM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TanVD%2FAORM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TanVD%2FAORM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TanVD%2FAORM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TanVD","download_url":"https://codeload.github.com/TanVD/AORM/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224040387,"owners_count":17245760,"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":["analytics","clickhouse","kotlin","orm","sql"],"created_at":"2024-11-11T03:17:27.403Z","updated_at":"2024-11-11T03:17:28.825Z","avatar_url":"https://github.com/TanVD.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AORM\n\n[ ![Download](https://api.bintray.com/packages/tanvd/aorm/aorm/images/download.svg) ](https://bintray.com/tanvd/aorm/aorm/_latestVersion)\n\nAORM is analytical SQL framework. Basically, it is a fork of [Exposed SQL framework](https://github.com/JetBrains/Exposed) for ClickHouse database dialect.\n\nAORM supports Exposed-like DSL for standard SQL operations and rich set of ClickHouse dialect features (like state-aggregation functions, different engines, replicated context of execution and so on)\n\n\n## Setup\n\nAORM releases are published to [JCenter](https://bintray.com/tanvd/aorm/aorm).\n\n## How to\n\nFirst of all you'll need to set up Database object. Provide it with DataSource (self-constructed, JNDI -- it doesn't matter, but don't forget to use pooling :) ). In context of Database (`withContext(db)` call) you will perform all operations.\n\n```kotlin\nval database = Database(\"default\",\n        ClickHouseDataSource(\"jdbc:clickhouse://localhost:8123\",\n                ClickHouseProperties().withCredentials(\"default\", \"\"))\n)\n```\n\nIf you have a replicated cluster and want to balance load you may need to set up few Database objects and use ReplicatedConnectionContext.\n\nYou can set up Table objects once database is created. Right now AORM supports a lot of ClickHouse types, but does not support nullability. Instead, null values will fallback to ClickHouse defaults. Support of nullability is considered to be implemented.\n\n```kotlin\nobject TestTable : Table(\"test_table\") {\n     val dateCol = date(\"date_col\")\n     val int8Col = int8(\"int8_col\")\n     val int64Col = int64(\"int64_col\")\n     val stringCol = string(\"string_col\")\n     val arrayStringCol = arrayString(\"arrayString_col\")\n \n     override val engine: Engine = Engine.MergeTree(dateCol, listOf(dateCol))\n}\n ```\n\nPlease note, that table is not linked to specific database. Table object is only declaration of scheme. You can use it in different contexts during work with different databases.\n\nOnce you have created table object, you can align the scheme of your table with you database. Aligning of scheme means, that table will be created if it does not exist, or, if it exists, not existing columns will be added. AORM, by default, not performing any removal operations on aligning of scheme. It will not drop existing tables or columns.\n\n```kotlin\nwithDatabase(database) {\n    TestTable.syncScheme() // this call will align the scheme of TestTable in a database\n}\n```\n\nOnce everything is set up, you can insert some data:\n\n```kotlin\nwithDatabase(database) {\n    TestTable.insert {\n        it[TestTable.dateCol] = SimpleDateFormat(\"yyyy-MM-dd\").parse(\"2000-01-01\")\n        it[TestTable.int8Col] = 1.toByte()\n        it[TestTable.int64Col] = 1L\n        it[TestTable.stringCol] = \"test\"\n        it[TestTable.arrayStringCol] = listOf(\"test1\", \"test2\")\n    }\n}\n```\n\nThen load it:\n\n```kotlin\nwithDatabase(database) {\n    val query = TestTable.select() where (TestTable.int8Col eq 1.toByte())\n    val res = query.toResult()\n}\n```\n\nThere are a lot more query functions, types of columns, and so on. You can take a closer look at all features of AORM at it's tests or at next section\n\n\n## More examples\n\nA lot of examples of AORM production usage are located at [JetAudit library](https://github.com/TanVD/JetAudit). JetAudit is library for reliable and fast saving of business processes events (audit-events) and for reading of such events. It uses ClickHouse as data warehouse and AORM is used as programmatic interface.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanvd%2Faorm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftanvd%2Faorm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanvd%2Faorm/lists"}