{"id":13672839,"url":"https://github.com/nettofarah/mysql-schema-ts","last_synced_at":"2025-08-21T08:30:46.799Z","repository":{"id":36571968,"uuid":"228594637","full_name":"nettofarah/mysql-schema-ts","owner":"nettofarah","description":"✨convert mysql schemas into TypeScript interfaces","archived":false,"fork":false,"pushed_at":"2024-04-08T18:05:36.000Z","size":494,"stargazers_count":42,"open_issues_count":9,"forks_count":15,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-08T13:40:14.940Z","etag":null,"topics":[],"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/nettofarah.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":"2019-12-17T10:45:11.000Z","updated_at":"2024-10-24T15:33:17.000Z","dependencies_parsed_at":"2024-06-18T21:27:04.712Z","dependency_job_id":"49417b4b-37d0-4764-ad42-5b5cfaeff4d4","html_url":"https://github.com/nettofarah/mysql-schema-ts","commit_stats":{"total_commits":53,"total_committers":11,"mean_commits":4.818181818181818,"dds":"0.30188679245283023","last_synced_commit":"0a8d229eee86258371863420defaeda3d7aa8309"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nettofarah%2Fmysql-schema-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nettofarah%2Fmysql-schema-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nettofarah%2Fmysql-schema-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nettofarah%2Fmysql-schema-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nettofarah","download_url":"https://codeload.github.com/nettofarah/mysql-schema-ts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230501172,"owners_count":18236061,"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-08-02T09:01:51.113Z","updated_at":"2024-12-19T21:09:48.734Z","avatar_url":"https://github.com/nettofarah.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# mysql-schema-ts\n\n\u003e Convert MySQL schemas into TypeScript interfaces\n\nPostgres implementation: http://github.com/nettofarah/postgres-schema-ts\n\n# Usage\n\n```bash\n# to infer an entire schema\n$ npx mysql-schema-ts mysql://root@localhost:3306/database\n\n# to infer a specific table\n$ npx mysql-schema-ts mysql://root@localhost:3306/database --table table_name\n\n# add optional prefix to table names\n$ npx mysql-schema-ts mysql://root@localhost:3306/database --prefix SQL\n```\n\ntip: You can pipe the output of mysql-schema-ts into a file with `npx mysql-schema-ts \u003cargs\u003e \u003e schema.ts`\n\n## Demo\n\nFor the following SQL schema: (from the musicbrainz database)\n\n```sql\nCREATE TABLE IF NOT EXISTS artist ( -- replicate (verbose)\n    id                  SERIAL,\n    gid                 CHAR(36) NOT NULL,\n    name                VARCHAR(255) NOT NULL,\n    sort_name           VARCHAR(255) NOT NULL,\n    begin_date_year     SMALLINT,\n    begin_date_month    SMALLINT,\n    begin_date_day      SMALLINT,\n    end_date_year       SMALLINT,\n    end_date_month      SMALLINT,\n    end_date_day        SMALLINT,\n    type                INTEGER, -- references artist_type.id\n    area                INTEGER, -- references area.id\n    gender              INTEGER, -- references gender.id\n    comment             VARCHAR(255) NOT NULL DEFAULT '',\n    edits_pending       INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending \u003e= 0),\n    last_updated        TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n    ended               CHAR(1) NOT NULL DEFAULT FALSE\n);\n\nCREATE TABLE IF NOT EXISTS track ( -- replicate (verbose)\n    id                  SERIAL,\n    gid                 CHAR(36) NOT NULL,\n    recording           INTEGER NOT NULL, -- references recording.id\n    medium              INTEGER NOT NULL, -- references medium.id\n    position            INTEGER NOT NULL,\n    number              TEXT NOT NULL,\n    name                VARCHAR(255) NOT NULL,\n    artist_credit       INTEGER NOT NULL, -- references artist_credit.id\n    length              INTEGER CHECK (length IS NULL OR length \u003e 0),\n    edits_pending       INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending \u003e= 0),\n    last_updated        TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n    is_data_track       CHAR(1) NOT NULL DEFAULT FALSE\n) CHARACTER SET utf8 COLLATE utf8_general_ci;\n```\n\nrun:\n\n```bash\n$ npx mysql-schema-ts mysql://root@localhost:3306/musicbrainz\n```\n\n```typescript\nexport interface artist {\n  id: number\n  gid: string\n  name: string\n  sort_name: string\n  begin_date_year: number | null\n  begin_date_month: number | null\n  begin_date_day: number | null\n  end_date_year: number | null\n  end_date_month: number | null\n  end_date_day: number | null\n  type: number | null\n  area: number | null\n  gender: number | null\n  comment: string\n  edits_pending: number\n  last_updated: Date\n  ended: string\n}\nexport interface track {\n  id: number\n  gid: string\n  recording: number\n  medium: number\n  position: number\n  number_: string\n  name: string\n  artist_credit: number\n  length: number | null\n  edits_pending: number\n  last_updated: Date\n  is_data_track: string\n}\n```\n\n## Using `mysql-schema-ts` programatically\n\n```typescript\nimport { inferSchema, inferTable } from 'mysql-schema-ts'\n\nawait inferSchema(connectionString)\nawait inferTable(connectionString, tableName)\n```\n\n## Design\n\nmysql-schema-ts is inpired by the awesome [schemats](https://github.com/SweetIQ/schemats) library.\nBut takes a simpler, more blunt, and configuration free approach:\n\n- Simpler defaults\n- MySQL support only\n- Inline enums\n- No support for namespaces\n\n## License (MIT)\n\n```\nWWWWWW||WWWWWW\n W W W||W W W\n      ||\n    ( OO )__________\n     /  |           \\\n    /o o|    MIT     \\\n    \\___/||_||__||_|| *\n         || ||  || ||\n        _||_|| _||_||\n       (__|__|(__|__|\n```\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnettofarah%2Fmysql-schema-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnettofarah%2Fmysql-schema-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnettofarah%2Fmysql-schema-ts/lists"}