{"id":23722396,"url":"https://github.com/tkcrm/pgxgen","last_synced_at":"2026-04-14T08:02:57.203Z","repository":{"id":38028168,"uuid":"444722062","full_name":"tkcrm/pgxgen","owner":"tkcrm","description":"Code generation tool for PostgreSQL, MySQL, and SQLite. Generates CRUD SQL, Go models, and sqlc query code from a single config file.","archived":false,"fork":false,"pushed_at":"2026-03-24T17:10:01.000Z","size":1561,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-03-25T20:25:13.190Z","etag":null,"topics":["ddl","generator","mysql","pgxgen","postgres","sql","sqlc","sqlformatter","sqlite"],"latest_commit_sha":null,"homepage":"","language":"Go","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/tkcrm.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-01-05T08:23:35.000Z","updated_at":"2026-03-24T17:09:23.000Z","dependencies_parsed_at":"2023-10-03T16:58:00.565Z","dependency_job_id":"5f375a30-67b0-4a1b-8d93-3be38fa7be9e","html_url":"https://github.com/tkcrm/pgxgen","commit_stats":null,"previous_names":[],"tags_count":54,"template":false,"template_full_name":null,"purl":"pkg:github/tkcrm/pgxgen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkcrm%2Fpgxgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkcrm%2Fpgxgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkcrm%2Fpgxgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkcrm%2Fpgxgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tkcrm","download_url":"https://codeload.github.com/tkcrm/pgxgen/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkcrm%2Fpgxgen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31290980,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-01T13:12:26.723Z","status":"ssl_error","status_checked_at":"2026-04-01T13:12:25.102Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["ddl","generator","mysql","pgxgen","postgres","sql","sqlc","sqlformatter","sqlite"],"created_at":"2024-12-30T23:51:55.775Z","updated_at":"2026-04-01T18:56:37.189Z","avatar_url":"https://github.com/tkcrm.png","language":"Go","readme":"# pgxgen\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/tkcrm/pgxgen.svg)](https://pkg.go.dev/github.com/tkcrm/pgxgen)\n[![Go Version](https://img.shields.io/badge/go-1.26-blue)](https://go.dev/)\n[![Go Report Card](https://goreportcard.com/badge/github.com/tkcrm/pgxgen)](https://goreportcard.com/report/github.com/tkcrm/pgxgen)\n[![License](https://img.shields.io/github/license/tkcrm/pgxgen)](LICENSE)\n\nCode generation tool for PostgreSQL, MySQL, and SQLite. Generates CRUD SQL, Go models, and [sqlc](https://github.com/sqlc-dev/sqlc) query code from a single config file.\n\n## Features\n\n- **One config** — `pgxgen.yaml` replaces both `pgxgen.yaml` and `sqlc.yaml`\n- **CRUD generation** — template-based SQL with soft delete, batch insert support\n- **Go models** — structs with json/db tags, custom tags, type overrides, enum generation\n- **sqlc integration** — auto-generates `sqlc.yaml` and runs sqlc\n- **Multi-engine** — PostgreSQL + MySQL + SQLite in one project\n- **Per-table repos** or **single repo** layout\n- **Schema dump** — consolidated DDL output from migrations (no config needed)\n- **SQL formatting** — format SQL files with dialect support (PostgreSQL, MySQL, SQLite)\n- **Watch mode**, **dry-run**, **validation**, **interactive init**\n\n## AI Agent Skills\n\nThis repository includes [AI agent skills](https://github.com/sxwebdev/skills) with documentation and usage examples for all packages. Install them with the [skills](https://github.com/sxwebdev/skills) CLI:\n\n```bash\ngo install github.com/sxwebdev/skills/cmd/skills@latest\nskills init\nskills repo add tkcrm/pgxgen -all\n```\n\n## Install\n\n```bash\ngo install github.com/tkcrm/pgxgen/cmd/pgxgen@latest\n```\n\nOr from source:\n\n```bash\ngit clone https://github.com/tkcrm/pgxgen.git\ncd pgxgen \u0026\u0026 go build -o pgxgen ./cmd/pgxgen\n```\n\n## Quick start\n\n```bash\n# Create config interactively\npgxgen init\n\n# Or generate an example config\npgxgen example \u003e pgxgen.yaml\n\n# Generate everything\npgxgen generate\n\n# Preview without writing\npgxgen generate --dry-run\n```\n\n## Configuration\n\n```yaml\nversion: \"2\"\n\nschemas:\n  - name: main\n    engine: postgresql\n    schema_dir: sql/migrations\n\n    models:\n      output_dir: internal/models\n      output_file_name: models_gen.go\n      package_name: models\n      package_path: github.com/your-org/project/internal/models\n      emit_json_tags: true\n      emit_db_tags: true\n      # include_struct_comments: true  # Add // @name StructName for Swagger\n\n    sqlc:\n      defaults:\n        sql_package: pgx/v5\n        emit_interface: true\n        emit_json_tags: true\n        emit_db_tags: true\n        emit_empty_slices: true\n        emit_result_struct_pointers: true\n        emit_enum_valid_method: true\n        emit_all_enum_values: true\n      overrides:\n        rename: { d: Params }\n        types:\n          - db_type: uuid\n            go_type: \"github.com/google/uuid.UUID\"\n          - db_type: uuid\n            nullable: true\n            go_type: \"github.com/google/uuid.NullUUID\"\n        columns:\n          - column: users.email\n            go_struct_tag: 'validate:\"required,email\"'\n\n    defaults:\n      queries_dir_prefix: sql/queries\n      output_dir_prefix: internal/store/repos\n      crud:\n        auto_clean: true\n        exclude_table_name: true\n        methods:\n          create:\n            skip_columns: [id, updated_at]\n            returning: \"*\"\n            column_values: { created_at: \"now()\" }\n      constants:\n        include_column_names: true\n\n    tables:\n      users:\n        primary_column: id\n        # soft_delete:\n        #   column: deleted_at\n        crud:\n          methods:\n            create:\n              skip_columns: [id, updated_at]\n              column_values: { created_at: \"now()\" }\n              returning: \"*\"\n            update:\n              skip_columns: [id, created_at]\n              column_values: { updated_at: \"now()\" }\n              returning: \"*\"\n            get: { name: GetByID }\n            delete: {}\n            find:\n              order: { by: created_at, direction: DESC }\n              limit: true\n            total: {}\n            exists:\n              where: { email: {} }\n```\n\n### Path patterns\n\n**Per-table repos** (each table gets its own directory):\n\n```yaml\ndefaults:\n  queries_dir_prefix: sql/queries # → sql/queries/{table}\n  output_dir_prefix: internal/store/repos # → internal/store/repos/{table}\n```\n\n**Single repo** (all tables in one directory):\n\n```yaml\ndefaults:\n  queries_dir: sql/queries\n  output_dir: internal/store\n```\n\n### CRUD methods\n\n| Method         | SQL                                | sqlc type                          |\n| -------------- | ---------------------------------- | ---------------------------------- |\n| `create`       | INSERT                             | `:one` (with returning) or `:exec` |\n| `update`       | UPDATE                             | `:one` (with returning) or `:exec` |\n| `delete`       | DELETE (or UPDATE for soft delete) | `:exec`                            |\n| `get`          | SELECT ... LIMIT 1                 | `:one`                             |\n| `find`         | SELECT with WHERE, ORDER, LIMIT    | `:many`                            |\n| `total`        | SELECT count(1)                    | `:one`                             |\n| `exists`       | SELECT EXISTS                      | `:one`                             |\n| `batch_create` | INSERT (copyfrom/multi-values)     | `:copyfrom`                        |\n\n### Soft delete\n\n```yaml\ntables:\n  posts:\n    soft_delete:\n      column: deleted_at\n    crud:\n      methods:\n        delete: {} # → UPDATE SET deleted_at = now() WHERE id = $1\n        get: {} # → auto adds WHERE deleted_at IS NULL\n        find: {} # → auto adds WHERE deleted_at IS NULL\n```\n\n## Commands\n\n| Command                     | Description                                            |\n| --------------------------- | ------------------------------------------------------ |\n| `pgxgen generate`           | Generate everything (crud + models + sqlc + constants) |\n| `pgxgen generate crud`      | Generate CRUD SQL only                                 |\n| `pgxgen generate models`    | Generate Go models only                                |\n| `pgxgen generate --dry-run` | Preview changes without writing                        |\n| `pgxgen schema \u003cpath\u003e`      | Output consolidated DDL from migrations                |\n| `pgxgen fmt \u003cpath\u003e`         | Format SQL files (with confirmation)                   |\n| `pgxgen fmt \u003cpath\u003e --check` | Check SQL formatting (for CI, exit 1 if unformatted)   |\n| `pgxgen validate`           | Validate config and schema (for CI)                    |\n| `pgxgen watch`              | Watch schema files, regenerate on changes              |\n| `pgxgen init`               | Create config interactively                            |\n| `pgxgen example`            | Print example config with all features                 |\n| `pgxgen migrate`            | Migrate v1 config to v2                                |\n| `pgxgen update`             | Self-update to latest version                          |\n\n## Schema dump\n\nOutput the final consolidated DDL from all migration files — as if all migrations were applied and the schema was dumped. This command is standalone and does not require a `pgxgen.yaml` config.\n\n```bash\npgxgen schema sql/migrations/postgres                  # PostgreSQL (default)\npgxgen schema sql/migrations/sqlite -e sqlite          # SQLite\npgxgen schema sql/migrations/postgres \u003e schema.sql     # Save to file\npgxgen schema sql/migrations/001_init.up.sql           # Single file\n```\n\nCaptures tables, columns with defaults, PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK constraints, indexes (including partial), extensions, enums, and comments. Tables are ordered by foreign key dependencies.\n\n## SQL formatting\n\nFormat SQL files with dialect-aware formatting. Shows files to format and asks for confirmation before writing. This command is standalone and does not require a `pgxgen.yaml` config.\n\n```bash\npgxgen fmt .                                    # Format all .sql files recursively\npgxgen fmt sql/migrations                       # Format directory\npgxgen fmt sql/migrations/001_init.up.sql       # Format single file\npgxgen fmt . --check                            # Check only (for CI)\npgxgen fmt . --dry-run                          # Process without saving (test)\npgxgen fmt . --yes                              # Skip confirmation\npgxgen fmt . -e mysql                           # MySQL dialect\n```\n\nSupports PostgreSQL (default), MySQL, and SQLite dialects. Preserves comments, handles dollar-quoting (PostgreSQL), backtick identifiers (MySQL).\n\n## Migration from v1\n\n```bash\npgxgen migrate --in-place --sqlc-config sqlc.yaml\nrm sqlc.yaml\npgxgen generate\n```\n\n## JSON Schema\n\nIDE autocompletion is available via [schemas/pgxgen-schema.json](schemas/pgxgen-schema.json):\n\n```yaml\n# yaml-language-server: $schema=https://raw.githubusercontent.com/tkcrm/pgxgen/master/schemas/pgxgen-schema.json\nversion: \"2\"\n```\n\n## License\n\n[MIT](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftkcrm%2Fpgxgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftkcrm%2Fpgxgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftkcrm%2Fpgxgen/lists"}