{"id":51413937,"url":"https://github.com/mazinsw/cogen","last_synced_at":"2026-07-04T17:03:08.118Z","repository":{"id":18987739,"uuid":"22209311","full_name":"mazinsw/cogen","owner":"mazinsw","description":"A code generator from SQL to any language","archived":false,"fork":false,"pushed_at":"2025-09-06T21:58:59.000Z","size":25215,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-01-14T20:38:36.196Z","etag":null,"topics":["cli","code","code-generation","code-generator","command-line","console","entity","generator","modeling","parser","sql","template","terminal"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/mazinsw.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2014-07-24T10:41:34.000Z","updated_at":"2025-09-06T21:59:03.000Z","dependencies_parsed_at":"2024-07-27T17:23:13.664Z","dependency_job_id":"b4a2a177-096c-44b1-b9d0-f1c1b0d66cd3","html_url":"https://github.com/mazinsw/cogen","commit_stats":null,"previous_names":["mazinsw/codeg","mazinsw/sqltoclass"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mazinsw/cogen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazinsw%2Fcogen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazinsw%2Fcogen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazinsw%2Fcogen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazinsw%2Fcogen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mazinsw","download_url":"https://codeload.github.com/mazinsw/cogen/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazinsw%2Fcogen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35129192,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-04T02:00:05.987Z","response_time":113,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["cli","code","code-generation","code-generator","command-line","console","entity","generator","modeling","parser","sql","template","terminal"],"created_at":"2026-07-04T17:03:07.357Z","updated_at":"2026-07-04T17:03:08.105Z","avatar_url":"https://github.com/mazinsw.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Cogen - `Co`de `gen`erator\n=\n\nA code generator from SQL to any language\n\n## Example\n\n### Convert SQL table to typescript class\n\n#### Model\n```sql\nCREATE TABLE MyTable (\n  name TEXT COMMENT 'Field comment[S]',\n  age BOOL NOT NULL DEFAULT 0 COMMENT 'Field comment[F:false]'\n) COMMENT = 'Table comment[N:My Table|My tables]';\n```\n\n#### Template filename: `src/models/$[table.unix].ts`\n```typescript\n/** $[table.comment] */\nexport class $[Table.norm] {\n$[field.each]\n  /** $[field.comment] */\n  public $[field.norm]: $[field.if(boolean)]boolean$[field.else]string$[field.end];\n$[field.end]\n}\n```\n\n#### Result filename: `src/models/my_table.ts`\n```typescript\n/** Table comment */\nexport class MyTable {\n  /** Field comment */\n  public name: string;\n  /** Field comment */\n  public age: boolean;\n}\n```\n\n## Modeling\n\n### Append these command to end of each comment of each field or table\n### format: `[command:options]`\n- example: `'Any comment[N:name|names]'`\n\n### Commands:\n- `[D]` Default field, with this flag, the field must not be filled by the user\n- `[E:Apple|Orange|Banana]` Informs enum beautiful names\n- `[F:false]` describe the field or table\n- `[G:a]` or `[G:o]` name gender\n- `[H:table name]` Define inheritance\n- `[I:64x64|user|default.png]` Treats that field as image url, options sets the image dimension, base directory and default image name\n- `[K:package.io|package/io/]` define a package name and its directory\n- `[L:form-control|extra style]` field style and extra style\n- `[M:999-9999]` set field as masked by option\n- `[N:name|names]` set the beautiful name and/or plural name\n- `[P]` Treats that field as password field\n- `[R]` mark enum field as a radio\n- `[S]` as searchable descriptor or `[S:S]` as searchable only\n- `[T]` mark field to be filled as textarea element\n- `[U:unixname|unixnames]` set the unix name and/or plural unix name\n- `[ID:identifier]` set some identifier to field or table\n\n## Template\n### format: `$[source.attribute]` or  `$[source.function(expression)]`\n#### expression operators: `~` = not, `|` = or, `\u0026` = and, `(` `)` priority\n#### parent access: `.`\n- example: `class $[Table..norm] {}`\n- output: `class MyParentTable {}`\n\n\ncommands:\n- `$[table]` database table name\n  - `$[table.unix]` Table name in unix format\n  - `$[table.unix.replace(s$)]` Remove plural from table name after convert to unix format\n  - `$[table.unix.plural]` database table name on plural\n  - `$[table.norm]` Table name normalized and despluralized\n  - `$[table.norm.default]` Table name normalized without despluralize\n  - `$[table.name]` Beautiful name of table\n  - `$[table.name.plural]` Beautiful name of table on plural\n  - `$[table.style]` css style of table\n  - `$[table.style.extra]` css extra style of table\n  - `$[table.info]` Describe the table functionality\n  - `$[table.comment]` Comment of table or each comment line wrapped when in loop\n  - `$[table.gender]` table gender\n  - `$[table.chars]` all word first characters of table name\n  - `$[table.letter]` first char of table name\n  - `$[table.package]`  defined package for table\n  - `$[table.inherited]`  defined package for table\n  - `$[table.path]`  defined path for class file\n  - `$[table.order]` left zero padded table order\n  - `$[table.if(attribute)]` table condition, attributes:\n    - comment\n    - depends: check if current table depends on its parent\n    - index\n    - inherited\n    - package\n    - path\n    - pluralizable\n    - unique\n    - unpluralizable\n  - `$[table.exists(type|attribute)]` check if the table contains a field with matching type or attribute\n    example: `$[table.~exists(comment)]` check if table doesn't have a commentary\n  - `$[table..match(regex)]` test if regex match parent table name\n  - `$[table.finds(column_name)]` check if the table contains a field called column_name\n    example: `$[table.finds(.*_at)]` check if table has field name as date\n  - `$[table.each]` for each all tables\n    example: table.each(index), for each all index\n    example: table.each(unique), for each unique index including primary\n    example: table.each(primary), for each primary key index\n    example: table.each(constraint), for each all constraint including primary and unique index\n    example: table.each(foreign), for each all foreign key\n    example: table.each(comment), for each comment line wrapped\n  - `$[table.end]` end table exists condition or each loop\n\n- `$[index]` index field name\n  - `$[index.name]` index name\n  - `$[index.each(type|attribute)]` for each field of index\n  - `$[index.if(attribute)]` few_fields, fulltext\n\n- `$[unique]` unique field name\n  - `$[unique.name]` unique index name\n  - `$[unique.each(type|attribute)]` for each field of unique index\n\n- `$[primarykey]` primary key field name\n  - `$[primarykey.name]` primary key index name\n\n- `$[primary.each(type|attribute)]` for each field of primary key index\n\n- `$[constraint]` first constraint field name\n  - `$[constraint.name]` constraint name\n  - `$[constraint.each(type|attribute)]` for each field of constraint\n\n- `$[foreign]` first foreign field name\n  - `$[foreign.name]` foreign key name\n  - `$[foreign.each(type|attribute)]` for each field of foreign key\n\n- `$[inherited]`  inherited table\n\n- `$[primary]` primary key field have all field properties, when primary key have only one field\n\n- `$[descriptor]` main field of table, have all field properties\n\n- `$[comment.each]` each line of comment\n- `$[comment]` single line of comment break by 72 chars\n\n- `$[description.each]` each line of comment with ' escaped\n- `$[description]` single line of comment with ' escaped break by 72 chars\n\n- `$[reference]` referenced table by field or constraint, have all table commands\n  - `$[reference.match(regex)]` test if regex match referenced table name\n  - `$[reference.finds(column_name)]` check if the referenced table contains a field called column_name\n    example: `$[reference.finds(.*_at)]` check if referenced table has field name as date pattern\n  - `$[reference.reverse_each]` reverse for each field process content\n  - `$[reference.each(type|attribute\u0026all)]` for each field of referenced constraint table\n\n- `$[field]` name of table field\n  - `$[field.replace(_url,_file)]` replace field name from ie. image_url to image_file\n  - `$[field.unix]` name of field in unix format\n  - `$[field.norm]` name of field normalized\n  - `$[field.norm.singular]` Table name normalized on singular\n  - `$[field.name]` Beautiful name of table field\n  - `$[field.info]` Describe the field functionality\n  - `$[field.comment]` Comment of the field or each comment line wrapped when in loop\n  - `$[field.content]` fill with each field template generated\n  - `$[field.mask]` mask informed on model for the field\n  - `$[field.style]` css style of field\n  - `$[field.gender]` field gender\n  - `$[field.chars]` all word first characters of field name\n  - `$[field.letter]` first char of field name\n  - `$[field.array.count]` number of common fields, i.e, same name with different number\n  - `$[field.array.index]` current index of common field, start from 0\n  - `$[field.array.number]` current number of common field, start from 1\n  - `$[field.size]` Size of the field in bytes\n  - `$[field.length]` Length of the string field\n  - `$[field.each]` for each table field or each field of source on legacy\n    - legacy example: `$[field.each(primary)]` for each primary key fields\n    - example: `$[field.each(reference \u0026 required)]`\n    - legacy example: `$[field.each(comment)]`,for each comment line wrapped\n    - example: `$[field.each(search)]`\n    - legacy example: `$[field.each(option)]`,for each option of field(enum items)\n    - example: `$[field.each(all)]` for each all table field\n  - `$[field.end]` end each loop\n  - `$[field.if(type|attribute\u0026~(type|~attribute))]` test if field is type or has attributes, example: `$[field.if(reference)]` attributes:\n    - array\n    - bigint\n    - blob\n    - boolean\n    - comment\n    - currency\n    - date\n    - datetime\n    - default\n    - depends: check if field references its parent table\n    - description\n    - descriptor\n    - double\n    - enum\n    - feminine\n    - few_fields\n    - first\n    - float\n    - image\n    - info\n    - integer\n    - many\n    - masculine\n    - masked\n    - non_first\n    - non_null\n    - not_null\n    - null\n    - optional\n    - pluralizable\n    - primary\n    - radio\n    - reference\n    - repeated\n    - required\n    - searchable\n    - self_reference\n    - single\n    - string\n    - text\n    - time\n    - unique\n    - unpluralizable\n    - unsigned\n  - `$[field.else]` when if condition is false (must be the last before field.end)\n  - `$[field.else.if(type|attribute)]` when if condition is false and make a test if field type or has attributes\n  - `$[field.end]` end if\n  - `$[field.match(regex)]` test if regex match field SQL name\n  - `$[field.end]` end match\n  - `$[field.contains(text)]` test if field SQL name contains \"text\"\n  - `$[field.end]` end contains\n\n- `$[option]` or `$[field.option]` enum item value\n  - `$[option.unix]` enum item value as unix name\n  - `$[option.norm]` enum item value normalized\n  - `$[option.low]` first enum item index, start from 0\n  - `$[option.high]` last enum item index, start from 0\n  - `$[option.index]` current index of option, start from 0\n  - `$[option.number]` current number of option, start from 1\n  - `$[option.count]` count of enum items\n\n- `$[image]` or `$[field.image]` first image field of table `[I]`\n  - `$[image.width]` recommended image width\n  - `$[image.height]` recommended image height\n  - `$[image.folder]` image folder to upload\n  - `$[image.default]` default image url\n\n### Tip: all command allow case formatting\n- example: for table name `category`, `$[Table.name]` outputs: `Category`\n- example: for table name `Category`, `$[table.name]` outputs: `category`\n- example: for table name `category`, `$[TABLE.name]` outputs: `CATEGORY`\n- example: for table name `CaTeGoRy`, `$[tAble.name]` outputs: `CaTeGoRy`\n\n## Command line\n\n### Usage: `cogen [options] input.sql`\n#### Options:\n - (`-d` | `--despluralize`) `\"match1|match2/slice_end/[replacement[/min_length]];ms|ls/1/s/4\"`: set the despluralization database rules\n - (`-f` | `--file` | `-i` | `--input`) `input.sql`: set the input sql file\n - (`-h` | `--help`): show this help\n - (`-l` | `--legacy`): use legacy loops instead of as filter\n - (`-o` | `--output`) `storage/generated`: set the output directory\n - (`-p` | `--project`) `cogen.properties`: read a project from file\n - (`-s` | `--silent`): run without print anything\n - (`-t` | `--template`) `scripts/template/`: set the template input directory\n - (`-u` | `--uppercase`) `\"|USA|W3C|\"`: set the uppercase database names\n - (`-w` | `--write`) `cogen.properties`: save configuration to file when finishes\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmazinsw%2Fcogen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmazinsw%2Fcogen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmazinsw%2Fcogen/lists"}