{"id":23080916,"url":"https://github.com/klahap/pgen","last_synced_at":"2025-04-03T13:48:25.068Z","repository":{"id":264606311,"uuid":"893825189","full_name":"klahap/pgen","owner":"klahap","description":"Generate Kotlin Exposed tables from a PostgreSQL database schema","archived":false,"fork":false,"pushed_at":"2025-03-31T09:34:53.000Z","size":132,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T09:36:10.262Z","etag":null,"topics":["database-integration","generate-code","gradle-plugin","kotlin-exposed"],"latest_commit_sha":null,"homepage":"","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/klahap.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-11-25T09:24:46.000Z","updated_at":"2025-03-31T09:34:38.000Z","dependencies_parsed_at":"2025-01-07T17:43:17.741Z","dependency_job_id":"5114d0d9-ccd5-4054-810f-e0f70ceb2ba9","html_url":"https://github.com/klahap/pgen","commit_stats":null,"previous_names":["klahap/pgen"],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klahap%2Fpgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klahap%2Fpgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klahap%2Fpgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klahap%2Fpgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/klahap","download_url":"https://codeload.github.com/klahap/pgen/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247014515,"owners_count":20869376,"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":["database-integration","generate-code","gradle-plugin","kotlin-exposed"],"created_at":"2024-12-16T13:17:13.550Z","updated_at":"2025-04-03T13:48:25.029Z","avatar_url":"https://github.com/klahap.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kotlin Exposed Table Generator Gradle Plugin\n\n## Overview\n\nThe **Kotlin Exposed Table Generator** is a Gradle plugin designed to generate\nKotlin [Exposed](https://github.com/JetBrains/Exposed) table definitions directly from a PostgreSQL database schema.\nSimplify your workflow by automating the creation of table mappings and keeping them in sync with your database.\n\n## Features\n\n- Generate Kotlin Exposed DSL table definitions.\n- Filter tables by schema for precise control.\n- Keep your code synchronized with database schema changes effortlessly.\n\n## Installation\n\nAdd the plugin to your `build.gradle.kts`:\n\n```kotlin\nplugins {\n    id(\"io.github.klahap.pgen\") version \"$VERSION\"\n}\n```\n\n## Configuration\n\nTo configure the plugin, add the `pgen` block to your `build.gradle.kts`:\n\n```kotlin\npgen {\n    dbConnectionConfig(\n        url = System.getenv(\"DB_URL\"),          // Database URL\n        user = System.getenv(\"DB_USER\"),        // Database username\n        password = System.getenv(\"DB_PASSWORD\") // Database password\n    )\n    packageName(\"io.example.db\")                // Target package for generated tables\n    tableFilter {\n        addSchemas(\"public\")                    // Include only specific schemas (e.g., \"public\")\n    }\n    outputPath(\"./output\")                      // Output directory for generated files\n}\n```\n\n### Environment Variables\n\nMake sure to set the following environment variables:\n\n- `DB_URL`: The connection URL for your PostgreSQL database.\n- `DB_USER`: Your database username.\n- `DB_PASSWORD`: Your database password.\n\n## Running the Plugin\n\nOnce configured, generate your Kotlin Exposed table definitions by running:\n\n```bash\n./gradlew pgen\n```\n\nThis will create Kotlin files in the specified `outputPath`.\n\n## Example\n\n### Input: Database Schema\n\nAssume a PostgreSQL schema with the following table:\n\n```sql\nCREATE TYPE status AS ENUM ('ACTIVE', 'INACTIVE');\n\nCREATE TABLE users\n(\n    id     SERIAL PRIMARY KEY,\n    name   TEXT NOT NULL,\n    status status\n);\n```\n\n### Output: Generated Kotlin File\n\nThe plugin will generate a Kotlin Exposed DSL table:\n\n```kotlin\npackage io.example.db\n\nimport org.jetbrains.exposed.sql.Table\n\nenum class Status(\n    override val pgEnumLabel: String,\n) : PgEnum {\n    ACTIVE(pgEnumLabel = \"ACTIVE\"),\n    INACTIVE(pgEnumLabel = \"INACTIVE\");\n\n    override val pgEnumTypeName: String = \"public.status\"\n}\n\nobject Users : Table(\"users\") {\n    val id: Column\u003cInt\u003e = integer(name = \"id\")\n    val name: Column\u003cString\u003e = text(name = \"name\")\n    val status: Column\u003cStatus\u003e = customEnumeration(\n        name = \"status\",\n        sql = \"status\",\n        fromDb = { getPgEnumByLabel(it as String) },\n        toDb = { it.toPgObject() },\n    )\n\n    override val primaryKey: Table.PrimaryKey = PrimaryKey(id, name = \"users_pkey\")\n}\n```\n\n## Contributing\n\nContributions are welcome! Feel free to open issues or submit pull requests to improve the plugin.\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklahap%2Fpgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fklahap%2Fpgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklahap%2Fpgen/lists"}