{"id":25090633,"url":"https://github.com/yasserf/schemats","last_synced_at":"2026-02-22T17:35:16.642Z","repository":{"id":40303423,"uuid":"378638808","full_name":"yasserf/schemats","owner":"yasserf","description":"A postgres \u0026 mysql -\u003e typescript interface generator","archived":false,"fork":false,"pushed_at":"2024-03-20T15:14:18.000Z","size":94,"stargazers_count":229,"open_issues_count":4,"forks_count":10,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-09-21T07:53:40.876Z","etag":null,"topics":["mysql","postgres","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/yasserf.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2021-06-20T12:22:05.000Z","updated_at":"2025-07-30T15:53:59.000Z","dependencies_parsed_at":"2024-08-02T13:23:27.274Z","dependency_job_id":"62548ae9-61c3-48d0-b4a0-050ebfb33a88","html_url":"https://github.com/yasserf/schemats","commit_stats":null,"previous_names":["yasserf/schemats","vramework/schemats"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/yasserf/schemats","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yasserf%2Fschemats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yasserf%2Fschemats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yasserf%2Fschemats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yasserf%2Fschemats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yasserf","download_url":"https://codeload.github.com/yasserf/schemats/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yasserf%2Fschemats/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29720569,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-22T15:10:41.462Z","status":"ssl_error","status_checked_at":"2026-02-22T15:10:04.636Z","response_time":110,"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":["mysql","postgres","typescript"],"created_at":"2025-02-07T12:01:46.136Z","updated_at":"2026-02-22T17:35:16.628Z","avatar_url":"https://github.com/yasserf.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Schemats\n\nBefore anything, I would like to give a massive thank you to [sweetiq](https://www.npmjs.com/package/schemats) and their contributors for giving me a huge head start.\n\nThe reason I have created a new repo instead of a fork is because I don't support mysql and have some breaking changes due to how this library is consumed by [postgres-typed](https://github.com/vramework/postgres-typed) and [vramework](https://vramework.io/).\n\nI have kept the name and based off their MIT license as means of attribution and thanks.\n\n## Why Schemats\n\nBecause being able to make a change to your database structure and have it:\n\n- validate through your node backend APIs\n- get verified against automatically generate JSON schemas\n- raise errors in your frontend application \n\nIs just a great developer experience in my opinion.\n\nThis allows us to some pretty amazing things when it comes to refactoring and maintaining codebases, and\nalso provide the meta-data to help with libraries like [postgres-typed](https://github.com/vramework/postgres-typed). \n\n## Quickstart\n\n### Installing\n\n```bash\nyarn add -d @vramework/schemats || npm install -d @vramework/schemats\n```\n\n### Generating the type definition from schema\n\nAssuming you have the following schema (this is a bit of a random one):\n\n```sql\nCREATE SCHEMA \"pet_store\";\n\nCREATE TYPE \"pet_store\".\"animal\" AS enum (\n  'cat',\n  'dog'\n);\n\nCREATE TABLE \"pet_store\".\"user\" (\n  \"uuid\" uuid PRIMARY KEY default gen_random_uuid(),\n  \"name\" text NOT NULL\n);\n\nCREATE TABLE \"pet_store\".\"pet\" (\n  \"uuid\" uuid PRIMARY KEY default gen_random_uuid(),\n  \"owner\" uuid REFERENCES \"pet_store\".\"user\",\n  \"type\" pet_store.animal NOT NULL,\n  \"name\" text NOT NULL,\n  \"birthdate\" date,\n  \"last_seen_location\" point,\n  \"random_facts\" jsonb,\n  \"pet_search_document\" tsvector\n);\nCOMMENT ON COLUMN pet_store.pet.random_facts is '@type {RandomPetFacts}';\n```\n\nYou can now generate a bunch of different schema definitions.\n\nMy personal favourite is the following:\n\n```bash\nschemats postgres postgres://postgres@localhost/database -f ./db-custom-types.ts -s pet_store -c -e -o db-types.ts\n```\n\nWhile will result in the following typescript file: \n\n```typescript\n\n/**\n * AUTO-GENERATED FILE @ Fri, 27 Aug 2021 08:26:50 GMT - DO NOT EDIT!\n *\n * This file was automatically generated by schemats v.0.0.8\n * $ schemats generate postgres://username:password@localhost:5432/schemats -C -s pet_store\n *\n */\n\nimport { RandomPetFacts } from './db-custom-types'\n\nexport enum Animal {\n\t'Cat' = 'cat',\n\t'Dog' = 'dog' \n}\n\nexport interface User { \n\tuuid: string\n\tname: string \n}\n\nexport interface Pet { \n\tuuid: string\n\towner?: string | null\n\ttype: Animal\n\tname: string\n\tbirthdate?: Date | null\n\tlastSeenLocation?: { x: number, y: number } | null\n\trandomFacts?: RandomPetFacts | null\n\tmoreRandomFacts?: unknown | null \n\tpetSearchDocument?: string | null\n}\n\nexport interface Tables {\n    user: User,\n\tpet: Pet\n}\n\nexport type CustomTypes = RandomPetFacts\n```\n\nBut you have quite a bit of flexbility:\n\n```bash\nUsage: schemats mysql [options] [connection]\n\nGenerate a typescript schema from mysql\n\nArguments:\n  connection                   The connection string to use, if left empty will use env variables\n\nOptions:\n  -s, --schema \u003cschema\u003e        the schema to use (default: \"public\")\n  -t, --tables \u003ctables...\u003e     the tables within the schema\n  -f, --typesFile \u003ctypesFile\u003e  the file where jsonb types can be imported from\n  -c, --camelCase              use camel case for enums, table names, and column names\n  -C, --camelCaseTypes         use camel case only for TS names - not modifying the column names\n  -e, --enums                  use enums instead of types\n  -o, --output \u003coutput\u003e        where to save the generated file relative to the current working directory\n  --no-header                  don't generate a header\n  -h, --help                   display help for command\n```\n\n```bash\nGenerate a typescript schema from mysql\n\nArguments:\n  connection                   The connection string to use, if left empty will use env variables\n\nOptions:\n  -s, --schema \u003cschema\u003e        the schema to use (default: \"public\")\n  -t, --tables \u003ctables...\u003e     the tables within the schema\n  -f, --typesFile \u003ctypesFile\u003e  the file where jsonb types can be imported from\n  -c, --camelCase              use camel case for enums, table names, and column names\n  -C, --camelCaseTypes         use camel case only for TS names - not modifying the column names\n  -e, --enums                  use enums instead of types\n  -o, --output \u003coutput\u003e        where to save the generated file relative to the current working directory\n  --no-header                  don't generate a header\n  -h, --help                   display help for command\n```\n\n## Features\n\n### Camel Case `-c --camelCase, -C --camelCaseTypes`\n\nThis automatically turns all your tables and Enums / Types and column names to camelcase, which is the default\nexperience for javascript and is more consistent to use\n\nYou can use Camel Case Types to just camel case the TS entities - leaving the strings representing \nthe SQL columns alone.\n\n### Enums `-e --enums`\n\nUsing enums turns all postgres enums into Enums instead of normal types, which is just a\npreference aspect for developers since renaming enum values or order will change the Enum\nkey and value.\n\n### Types File `-f --typesFile \u003ctypesFile\u003e`\n\nThis is a VERY useful feature for jsonb fields. Normally a jsonb field type is unknown, \nhowever if you provide a types json file this will get the type out of the comment \nof a field and assign it to the value.\n\nThe structure of a custom type file could either be from another file:\n\n```typescript\nexport type { RandomPetFacts }  from './somewhere-else'\n```\n\nor it could just be defined straight in the file.\n\n```typescript\nexport type RandomPetFacts = Record\u003cstring, string\u003e\n```\n\n### Tables | Custom Types `-t --tables \u003ctables...\u003e`\n\nThese types are automatically generated to power typed-postgres\n\n## Using in typescript\n\nYou can import all your interfaces / enums from the file:\n\n```typescript\nimport * as DB from './db-types'\n\n// And then you can start picking how you want your APIs to be used:\ntype updatePetLocation = Pick\u003cDB.Pet, 'lastSeenAt'\u003e\n```\n\n## Tests\n\nSo where are the tests? The original schemats library has an amazing 100% coverage and this one has 0.\n\nTo be honest, I'm using this library in a few of my current projects and any error in it throws dozens \nin the entire codebase, so it sort of tests itself. That being said I will be looking to add some in again,\nbut in terms of priorties not my highest.\n\nHowever for manual testing and experimenting you can easily replicate this project by:\n\n```bash\n# Clone the repo\ngit clone git@github.com:vramework/schemats.git\n# Enter repo\ncd schemats\n# Install dependencies\nyarn install\n# Run the example, which will run create the schemats library and generate the db-types library\nyarn run example:postgres\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyasserf%2Fschemats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyasserf%2Fschemats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyasserf%2Fschemats/lists"}