Gathering detailed insights and metrics for @leifershag/knex-schema-inspector-aurora
Gathering detailed insights and metrics for @leifershag/knex-schema-inspector-aurora
Gathering detailed insights and metrics for @leifershag/knex-schema-inspector-aurora
Gathering detailed insights and metrics for @leifershag/knex-schema-inspector-aurora
Utility for extracting information about existing DB schema
npm install @leifershag/knex-schema-inspector-aurora
Typescript
Module System
Node Version
NPM Version
76
Supply Chain
99.5
Quality
74.8
Maintenance
100
Vulnerability
99.6
License
TypeScript (98.05%)
PLSQL (0.87%)
Shell (0.57%)
TSQL (0.51%)
Total Downloads
285
Last Day
1
Last Week
1
Last Month
3
Last Year
48
223 Commits
2 Branches
1 Contributors
Latest Version
1.6.4
Package Id
@leifershag/knex-schema-inspector-aurora@1.6.4
Unpacked Size
308.52 kB
Size
36.62 kB
File Count
61
NPM Version
6.14.12
Node Version
14.16.1
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
0%
1
Compared to previous week
Last month
0%
3
Compared to previous month
Last year
-52.9%
48
Compared to previous year
Utility for extracting information about existing DB schema
This library currently supports Postgres, MySQL, MS SQL, SQLite, and OracleDB. We aim to have support for the same databases as the main knex project.
Forked to provide support for knex-data-api-client.
Install the package through NPM or Yarn:
npm install knex-schema-inspector
yarn knex-schema-inspector
The package is initialized by passing it an instance of Knex:
1import Knex from 'knex'; 2import schemaInspector from 'knex-schema-inspector'; 3 4const database = knex({ 5 client: 'mysql', 6 connection: { 7 host: '127.0.0.1', 8 user: 'your_database_user', 9 password: 'your_database_password', 10 database: 'myapp_test', 11 charset: 'utf8', 12 }, 13}); 14 15const inspector = schemaInspector(database); 16 17export default inspector;
1import inspector from './inspector'; 2 3async function logTables() { 4 const tables = await inspector.tables(); 5 console.log(tables); 6}
Note: MySQL doesn't support the schema
parameter, as schema and database are ambiguous in MySQL.
Note 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.
Note 3: MSSQL doesn't support comment for either tables or columns
tables(): Promise<string[]>
Retrieve all tables in the current database.
1await inspector.tables(); 2// => ['articles', 'images', 'reviews']
tableInfo(table?: string): Promise<Table | Table[]>
Retrieve the table info for the given table, or all tables if no table is specified
1await inspector.tableInfo('articles'); 2// => { 3// name: 'articles', 4// schema: 'project', 5// comment: 'Informational blog posts' 6// } 7 8await inspector.tableInfo(); 9// => [ 10// { 11// name: 'articles', 12// schema: 'project', 13// comment: 'Informational blog posts' 14// }, 15// { ... }, 16// { ... } 17// ]
hasTable(table: string): Promise<boolean>
Check if a table exists in the current database.
1await inspector.hasTable('articles'); 2// => true
columns(table?: string): Promise<{ table: string, column: string }[]>
Retrieve all columns in a given table, or all columns if no table is specified
1await inspector.columns(); 2// => [ 3// { 4// "table": "articles", 5// "column": "id" 6// }, 7// { 8// "table": "articles", 9// "column": "title" 10// }, 11// { 12// "table": "images", 13// "column": "id" 14// } 15// ] 16 17await inspector.columns('articles'); 18// => [ 19// { 20// "table": "articles", 21// "column": "id" 22// }, 23// { 24// "table": "articles", 25// "column": "title" 26// } 27// ]
columnInfo(table?: string, column?: string): Promise<Column[] | Column>
Retrieve all columns from a given table. Returns all columns if table
parameter is undefined.
1await inspector.columnInfo('articles'); 2// => [ 3// { 4// name: "id", 5// table: "articles", 6// data_type: "VARCHAR", 7// default_value: null, 8// max_length: null, 9// numeric_precision: null, 10// numeric_scale: null, 11// is_nullable: false, 12// is_unique: false, 13// is_primary_key: true, 14// has_auto_increment: true, 15// foreign_key_column: null, 16// foreign_key_table: null, 17// comment: "Primary key for the articles collection" 18// }, 19// { ... }, 20// { ... } 21// ] 22 23await inspector.columnInfo('articles', 'id'); 24// => { 25// name: "id", 26// table: "articles", 27// data_type: "VARCHAR", 28// default_value: null, 29// max_length: null, 30// numeric_precision: null, 31// numeric_scale: null, 32// is_nullable: false, 33// is_unique: false, 34// is_primary_key: true, 35// has_auto_increment: true, 36// foreign_key_column: null, 37// foreign_key_table: null, 38// comment: "Primary key for the articles collection" 39// }
primary(table: string): Promise<string>
Retrieve the primary key column for a given table
1await inspector.primary('articles'); 2// => "id"
Retrieve all configured foreign key constraints.
1await inspector.foreignKeys(); 2// => [ 3// { 4// table: 'directus_files', 5// column: 'folder', 6// foreign_key_table: 'directus_folders', 7// foreign_key_column: 'id', 8// constraint_name: 'directus_files_folder_foreign', 9// on_update: 'CASCADE', 10// on_delete: 'SET NULL' 11// }, 12// { 13// table: 'directus_files', 14// column: 'modified_by', 15// foreign_key_table: 'directus_users', 16// foreign_key_column: 'id', 17// constraint_name: 'directus_files_modified_by_foreign', 18// on_update: 'CASCADE', 19// on_delete: 'SET NULL' 20// } 21// ]
withSchema(schema: string): void
Not supported in MySQL
Set the schema to use. Note: this is set on the inspector instance and only has to be done once:
1inspector.withSchema('my-schema');
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
First start docker containers:
1$ docker-compose up -d
Then run tests:
1$ npm test
Standard mocha filter (grep) can be used:
1$ npm test -- -g '.tableInfo'
No vulnerabilities found.
No security vulnerabilities found.