{"id":22874373,"url":"https://github.com/thesurlydev/kotlin-minimal-rdms","last_synced_at":"2025-03-31T12:43:11.261Z","repository":{"id":252565827,"uuid":"840805900","full_name":"thesurlydev/kotlin-minimal-rdms","owner":"thesurlydev","description":"Add-on to kotin-minimal-server for relational db support","archived":false,"fork":false,"pushed_at":"2024-08-11T15:55:14.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-06T18:52:24.731Z","etag":null,"topics":[],"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/thesurlydev.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-10T18:30:12.000Z","updated_at":"2024-08-11T15:55:17.000Z","dependencies_parsed_at":"2024-12-13T14:35:54.585Z","dependency_job_id":null,"html_url":"https://github.com/thesurlydev/kotlin-minimal-rdms","commit_stats":null,"previous_names":["thesurlydev/kotlin-minimal-rdms"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thesurlydev%2Fkotlin-minimal-rdms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thesurlydev%2Fkotlin-minimal-rdms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thesurlydev%2Fkotlin-minimal-rdms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thesurlydev%2Fkotlin-minimal-rdms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thesurlydev","download_url":"https://codeload.github.com/thesurlydev/kotlin-minimal-rdms/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246472580,"owners_count":20783225,"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-12-13T14:35:48.944Z","updated_at":"2025-03-31T12:43:11.242Z","avatar_url":"https://github.com/thesurlydev.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kotlin-minimal-rdms\n\nAdd-on to [kotlin-minimal-server](https://github.com/thesurlydev/kotlin-minimal-server) for relational database support.\n\n## Usage\n\n### Configuration\n```kotlin\nval dbConfig = DatabaseConfig(\n  jdbcUrl = \"jdbc:postgresql://${getEnv(\"POSTGRES_HOST\")}:5433/${getEnv(\"POSTGRES_DB\")}\",\n  username = getEnv(\"POSTGRES_USER\")!!,\n  password = getEnv(\"POSTGRES_PASSWORD\")!!\n)\nval databaseManager = DatabaseManager(dbConfig)\nval personRepository = PersonRepository(databaseManager)\n```\n\n### Schema\n\n```sql\ncreate table if not exists people\n(\n    id       uuid primary key default gen_random_uuid(),\n    name     varchar(255) not null,\n    age      int          not null\n);\n```\n\n### Repository\n```kotlin\nclass PersonRepository(private val databaseManager: DatabaseManager) : Repository\u003cUUID, Person\u003e {\n  override fun findAll(): List\u003cPerson\u003e {\n    val sql = \"SELECT * FROM people\"\n    return Querier.executeQuery(databaseManager, sql, ::person)\n  }\n\n  override fun findById(id: UUID): Person? {\n    val sql = \"SELECT * FROM people WHERE id = :id\"\n    val params = mapOf(\"id\" to id)\n    return Querier.queryWithParams(databaseManager, sql, params, ::maybePerson)\n  }\n\n  override fun delete(id: UUID): Boolean {\n    val sql = \"DELETE FROM people WHERE id = :id\"\n    val params = mapOf(\"id\" to id)\n    return Querier.updateObject(databaseManager, sql, params) \u003e 0\n  }\n\n  private fun maybePerson(resultSet: ResultSet): Person? = when {\n    resultSet.next() -\u003e person(resultSet)\n    else -\u003e null\n  }\n\n  private fun person(resultSet: ResultSet) = Person(\n    resultSet.getString(\"id\"),\n    resultSet.getString(\"name\"),\n    resultSet.getInt(\"age\")\n  )\n}\n```\n\n### Gradle (Kotlin DSL)\n\n```kotlin\nimplementation(\"dev.surly:kotlin-minimal-rdms:0.1.0\")\n```\n\n### Gradle (Groovy DSL)\n\n```groovy\nimplementation 'dev.surly:kotlin-minimal-rdms:0.1.0'\n```\n\n### Maven\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003edev.surly\u003c/groupId\u003e\n    \u003cartifactId\u003ekotlin-minimal-rdms\u003c/artifactId\u003e\n    \u003cversion\u003e0.1.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthesurlydev%2Fkotlin-minimal-rdms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthesurlydev%2Fkotlin-minimal-rdms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthesurlydev%2Fkotlin-minimal-rdms/lists"}