{"id":19315260,"url":"https://github.com/sutandojs/schema-inspector","last_synced_at":"2026-02-26T06:47:02.559Z","repository":{"id":252631289,"uuid":"840835080","full_name":"sutandojs/schema-inspector","owner":"sutandojs","description":"Utility for extracting information about existing database schema","archived":false,"fork":false,"pushed_at":"2024-08-11T10:30:16.000Z","size":90,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-14T12:16:03.522Z","etag":null,"topics":["mysql","postgresql","schema","sqlite","sutando"],"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/sutandojs.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-08-10T20:41:04.000Z","updated_at":"2024-08-11T10:30:19.000Z","dependencies_parsed_at":"2024-08-11T11:45:15.692Z","dependency_job_id":null,"html_url":"https://github.com/sutandojs/schema-inspector","commit_stats":null,"previous_names":["sutandojs/schema-inspector"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/sutandojs/schema-inspector","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sutandojs%2Fschema-inspector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sutandojs%2Fschema-inspector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sutandojs%2Fschema-inspector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sutandojs%2Fschema-inspector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sutandojs","download_url":"https://codeload.github.com/sutandojs/schema-inspector/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sutandojs%2Fschema-inspector/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29850782,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-25T22:37:40.667Z","status":"online","status_checked_at":"2026-02-26T02:00:06.774Z","response_time":89,"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":["mysql","postgresql","schema","sqlite","sutando"],"created_at":"2024-11-10T01:05:37.372Z","updated_at":"2026-02-26T06:47:02.536Z","avatar_url":"https://github.com/sutandojs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @sutando/schema-inspector\n\nUtility for extracting information about existing database schema\n\nThis library currently supports Postgres, MySQL, MS SQL, SQLite, and OracleDB. We aim to have support for the same databases as the main sutando project.\n\n## Installation\n\nInstall the package through npm or pnpm:\n\n```\nnpm install @sutando/schema-inspector\n```\n\n```\npnpm add @sutando/schema-inspector\n```\n\n## Usage\n\nThe package is initialized by passing it an instance of sutando QueryBuilder:\n\n```ts\nimport { sutando } from 'sutando';\nimport { schemaInspector, mysqlInspector } from '@sutando/schema-inspector';\n\nsutando.addConnection({\n  client: 'mysql2',\n  connection: {\n    host: '127.0.0.1',\n    user: 'your_database_user',\n    password: 'your_database_password',\n    database: 'myapp_test',\n    charset: 'utf8',\n  },\n});\n\nconst connection = sutando.connection();\n\nconst inspector = schemaInspector(connection, 'mysql');\n// or\nconst inspector = mysqlInspector(connection);\n\nexport default inspector;\n```\n\n## Examples\n\n```ts\nimport inspector from './inspector';\n\nasync function logTables() {\n  const tables = await inspector.tables();\n  console.log(tables);\n}\n```\n\n## API\n\nNote: MySQL doesn't support the `schema` parameter, as schema and database are ambiguous in MySQL.\n\nNote 2: Some database types might return slightly more information than others. See the type files for a specific overview what to expect from driver to driver.\n\nNote 3: MSSQL doesn't support comment for either tables or columns\n\n### Methods\n\n**Table**\n\n- [`tables(): Promise\u003cstring[]\u003e`](#tables-promisestring)\n- [`tableInfo(table?: string): Promise\u003cTable | Table[]\u003e`](#tableinfotable-string-promisetable--table)\n- [`hasTable(table: string): Promise\u003cboolean\u003e`](#hastabletable-string-promiseboolean)\n\n**Columns**\n\n- [`columns(table?: string): Promise\u003c{ table: string, column: string }[]\u003e`](#columnstable-string-promise-table-string-column-string-)\n- [`columnInfo(table?: string, column?: string): Promise\u003cColumn[] | Column\u003e`](#columninfotable-string-column-string-promisecolumn--column)\n- [`primary(table: string): Promise\u003cstring\u003e`](#primarytable-string-promisestring)\n\n**Foreign Keys**\n\n- [`foreignKeys(): Promise\u003cForeignKey\u003e`](#foreign-keys)\n\n**Misc.**\n\n- [`withSchema(schema: string): void`](#withschemaschema-string-void)\n\n### Tables\n\n#### `tables(): Promise\u003cstring[]\u003e`\n\nRetrieve all tables in the current database.\n\n```ts\nawait inspector.tables();\n// =\u003e ['articles', 'images', 'reviews']\n```\n\n#### `tableInfo(table?: string): Promise\u003cTable | Table[]\u003e`\n\nRetrieve the table info for the given table, or all tables if no table is specified\n\n```ts\nawait inspector.tableInfo('articles');\n// =\u003e {\n//   name: 'articles',\n//   schema: 'project',\n//   comment: 'Informational blog posts'\n// }\n\nawait inspector.tableInfo();\n// =\u003e [\n//   {\n//     name: 'articles',\n//     schema: 'project',\n//     comment: 'Informational blog posts'\n//   },\n//   { ... },\n//   { ... }\n// ]\n```\n\n#### `hasTable(table: string): Promise\u003cboolean\u003e`\n\nCheck if a table exists in the current database.\n\n```ts\nawait inspector.hasTable('articles');\n// =\u003e true\n```\n\n### Columns\n\n#### `columns(table?: string): Promise\u003c{ table: string, column: string }[]\u003e`\n\nRetrieve all columns in a given table, or all columns if no table is specified\n\n```ts\nawait inspector.columns();\n// =\u003e [\n//   {\n//     \"table\": \"articles\",\n//     \"column\": \"id\"\n//   },\n//   {\n//     \"table\": \"articles\",\n//     \"column\": \"title\"\n//   },\n//   {\n//     \"table\": \"images\",\n//     \"column\": \"id\"\n//   }\n// ]\n\nawait inspector.columns('articles');\n// =\u003e [\n//   {\n//     \"table\": \"articles\",\n//     \"column\": \"id\"\n//   },\n//   {\n//     \"table\": \"articles\",\n//     \"column\": \"title\"\n//   }\n// ]\n```\n\n#### `columnInfo(table?: string, column?: string): Promise\u003cColumn[] | Column\u003e`\n\nRetrieve all columns from a given table. Returns all columns if `table` parameter is undefined.\n\n```ts\nawait inspector.columnInfo('articles');\n// =\u003e [\n//   {\n//     name: \"id\",\n//     table: \"articles\",\n//     data_type: \"VARCHAR\",\n//     default_value: null,\n//     max_length: null,\n//     numeric_precision: null,\n//     numeric_scale: null,\n//     is_nullable: false,\n//     is_unique: false,\n//     is_primary_key: true,\n//     has_auto_increment: true,\n//     foreign_key_column: null,\n//     foreign_key_table: null,\n//     comment: \"Primary key for the articles collection\"\n//   },\n//   { ... },\n//   { ... }\n// ]\n\nawait inspector.columnInfo('articles', 'id');\n// =\u003e {\n//    name: \"id\",\n//    table: \"articles\",\n//    data_type: \"VARCHAR\",\n//    default_value: null,\n//    max_length: null,\n//    numeric_precision: null,\n//    numeric_scale: null,\n//    is_nullable: false,\n//    is_unique: false,\n//    is_primary_key: true,\n//    has_auto_increment: true,\n//    foreign_key_column: null,\n//    foreign_key_table: null,\n//    comment: \"Primary key for the articles collection\"\n//  }\n```\n\n#### `primary(table: string): Promise\u003cstring\u003e`\n\nRetrieve the primary key column for a given table\n\n```ts\nawait inspector.primary('articles');\n// =\u003e \"id\"\n```\n\n### Foreign Keys\n\nRetrieve all configured foreign key constraints.\n\n```ts\nawait inspector.foreignKeys();\n// =\u003e [\n//   {\n//     table: 'directus_files',\n//     column: 'folder',\n//     foreign_key_table: 'directus_folders',\n//     foreign_key_column: 'id',\n//     constraint_name: 'directus_files_folder_foreign',\n//     on_update: 'CASCADE',\n//     on_delete: 'SET NULL'\n//   },\n//   {\n//     table: 'directus_files',\n//     column: 'modified_by',\n//     foreign_key_table: 'directus_users',\n//     foreign_key_column: 'id',\n//     constraint_name: 'directus_files_modified_by_foreign',\n//     on_update: 'CASCADE',\n//     on_delete: 'SET NULL'\n//   }\n// ]\n```\n\n### Misc.\n\n#### `withSchema(schema: string): void`\n\n_Not supported in MySQL_\n\nSet the schema to use. Note: this is set on the inspector instance and only has to be done once:\n\n```ts\ninspector.withSchema('my-schema');\n```\n\n## Contributing\n\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\n\n## Acknowledgements\n\nThis project is based on the [knex-schema-inspector](https://github.com/knex/knex-schema-inspector) library. We thank the authors of knex-schema-inspector for their work.\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsutandojs%2Fschema-inspector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsutandojs%2Fschema-inspector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsutandojs%2Fschema-inspector/lists"}