relational-schema
Advanced tools
Comparing version 0.3.1 to 0.4.0
@@ -21,66 +21,101 @@ #! /usr/bin/env node | ||
const path_1 = __importDefault(require("path")); | ||
const yargs_1 = require("yargs"); | ||
const logger_1 = require("../lib/logger"); | ||
const yargs_1 = __importDefault(require("yargs")); | ||
const { hideBin } = require('yargs/helpers'); | ||
const index_1 = require("../index"); | ||
const types_1 = require("../types"); | ||
const print_relations_1 = require("../schema-tools/print-relations"); | ||
const clients = ['mysql', 'pg']; | ||
const formats = ["json" /* json */, "cjs" /* commonJS */, "es6" /* es6 */, "ts" /* typescript */]; | ||
const logLevels = [types_1.LogLevel.debug, types_1.LogLevel.info]; | ||
const args = yargs_1.usage('Usage: $0 <command> [options]') | ||
.options({ | ||
host: { type: 'string', default: '127.0.0.1' }, | ||
port: { type: 'number', default: 3306 }, | ||
client: { choices: clients, default: clients[0] }, | ||
user: { type: 'string', default: 'root' }, | ||
password: { type: 'string', default: '' }, | ||
database: { type: 'string', default: 'public' }, | ||
outdir: { type: 'string', default: './gen' }, | ||
format: { choices: formats, default: "json" /* json */ }, | ||
prettierConfig: { type: 'string' }, | ||
logLevel: { choices: logLevels, default: types_1.LogLevel.info }, | ||
transitiveRelations: { type: 'boolean', default: true }, | ||
}) | ||
.global('config') | ||
.default('config', 'introspect-config.json') | ||
.config('config', 'Configure using a json file') | ||
.command('introspect', 'Generate schema from database') | ||
.example('$0 introspect', 'generate the schema using a introspect-config.json file in the current directory') // .demand('o') | ||
yargs_1.default(hideBin(process.argv)) | ||
.usage('Usage: $0 <command> [options]') | ||
.command('introspect', 'Generate schema from database', (yargs) => { | ||
yargs | ||
.options({ | ||
host: { type: 'string', default: '127.0.0.1' }, | ||
port: { type: 'number', default: 3306 }, | ||
client: { choices: clients, default: clients[0] }, | ||
user: { type: 'string', default: 'root' }, | ||
password: { type: 'string', default: '' }, | ||
database: { type: 'string', default: 'public' }, | ||
outdir: { type: 'string', default: './gen' }, | ||
format: { choices: formats, default: "json" /* json */ }, | ||
prettierConfig: { type: 'string', description: 'Path to a prettierrc file' }, | ||
logLevel: { choices: logLevels, default: types_1.LogLevel.info }, | ||
transitiveRelations: { | ||
type: 'boolean', | ||
default: true, | ||
description: 'Include transitive (many-to-many) relations', | ||
}, | ||
}) | ||
.global('config') | ||
.default('config', 'relation-config.json') | ||
.config('config', 'Configure using a json file') | ||
.example('$0 introspect', 'generate the schema using a introspect-config.json file in the current directory'); | ||
}, (argv) => __awaiter(void 0, void 0, void 0, function* () { | ||
yield introspect(argv); | ||
})) | ||
.command('tree', 'Print a relation tree from a table', (yargs) => { | ||
yargs | ||
.options({ | ||
table: { type: 'string' }, | ||
schemaFile: { | ||
type: 'string', | ||
description: 'The location of the relations schema file', | ||
}, | ||
showBackwardRelations: { | ||
type: 'boolean', | ||
default: false, | ||
description: 'Show incoming foreign keys as well as outgoing', | ||
}, | ||
maxDepth: { | ||
type: 'number', | ||
default: 5, | ||
description: 'The maximum tree depth', | ||
}, | ||
}) | ||
.demandOption('table') | ||
.demandOption('schemaFile') | ||
.example('$0 tree users', 'Print a relation tree from the users table'); | ||
}, (argv) => __awaiter(void 0, void 0, void 0, function* () { | ||
yield print_relations_1.printRelationTree({ | ||
root: argv.table, | ||
schemaPath: argv.schemaFile, | ||
maxDepth: argv.maxDepth, | ||
showBackwardRelations: argv.showBackwardRelations, | ||
}); | ||
})) | ||
.alias('h', 'help').argv; | ||
const run = () => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
const conn = { | ||
client: args.client, | ||
connection: { | ||
host: args.host, | ||
port: args.port, | ||
user: args.user, | ||
password: args.password, | ||
database: args.database, | ||
}, | ||
}; | ||
const options = { | ||
transitiveRelations: args.transitiveRelations, | ||
}; | ||
const outdir = args.outdir; | ||
const format = args.format; | ||
const prettierConfig = args.prettierConfig; | ||
const logs = args.logLevel; | ||
const CURRENT = process.cwd(); | ||
const GENERATED_DIR = path_1.default.join(CURRENT, outdir); | ||
yield index_1.generate({ conn, outdir: GENERATED_DIR, format, prettierConfig, logLevel: logs, options }); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
console.log('Use: "relation -h" to see help'); | ||
process.exit(1); | ||
} | ||
}); | ||
run() | ||
.then(() => { | ||
process.exit(); | ||
}) | ||
.catch((e) => { | ||
console.warn(e.message); | ||
console.log('Use: "relation -h" to see help'); | ||
process.exit(1); | ||
}); | ||
function introspect(args) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const conn = { | ||
client: args.client, | ||
connection: { | ||
host: args.host, | ||
port: args.port, | ||
user: args.user, | ||
password: args.password, | ||
database: args.database, | ||
}, | ||
}; | ||
const options = { | ||
transitiveRelations: args.transitiveRelations, | ||
}; | ||
const outdir = args.outdir; | ||
const format = args.format; | ||
const prettierConfig = args.prettierConfig; | ||
const logs = args.logLevel; | ||
const CURRENT = process.cwd(); | ||
const GENERATED_DIR = path_1.default.join(CURRENT, outdir); | ||
yield index_1.generate({ conn, outdir: GENERATED_DIR, format, prettierConfig, logLevel: logs, options }); | ||
} | ||
catch (e) { | ||
logger_1.logger.error(e); | ||
logger_1.logger.info('Use: "relation -h" to see help'); | ||
process.exit(1); | ||
} | ||
}); | ||
} | ||
//# sourceMappingURL=entry.js.map |
@@ -15,2 +15,3 @@ "use strict"; | ||
const printer_1 = require("./printer"); | ||
const logger_1 = require("./lib/logger"); | ||
// ************************** | ||
@@ -26,3 +27,3 @@ // generate schema | ||
const { conn, outdir, format, prettierConfig, logLevel, options } = args; | ||
console.log(`Generating for db: ${conn.client} - ${conn.connection.database}`); | ||
logger_1.logger.info(`Generating for db: ${conn.client} - ${conn.connection.database}`); | ||
const schema = yield introspect_1.introspectSchema({ conn, logLevel, options }); | ||
@@ -72,3 +73,3 @@ switch (format) { | ||
} | ||
console.log(`Generated for ${Object.keys(schema.tables).length} tables in ${outdir}`); | ||
logger_1.logger.info(`Generated for ${Object.keys(schema.tables).length} tables in ${outdir}`); | ||
return conn; | ||
@@ -75,0 +76,0 @@ }); |
@@ -17,2 +17,3 @@ "use strict"; | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const logger_1 = require("../lib/logger"); | ||
const types_1 = require("../types"); | ||
@@ -28,3 +29,3 @@ class Introspection { | ||
if (this.logLevel === types_1.LogLevel.debug) { | ||
console.log('Executing query: ', query.toSQL()); | ||
logger_1.logger.debug('Executing query: ', query.toSQL()); | ||
} | ||
@@ -31,0 +32,0 @@ return yield query; |
@@ -19,2 +19,3 @@ "use strict"; | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const logger_1 = require("../lib/logger"); | ||
class MySQLIntrospection extends introspection_1.Introspection { | ||
@@ -84,3 +85,3 @@ constructor(params) { | ||
else { | ||
console.log(`Type [${columnName}] has been mapped to [any] because no specific type has been found.`); | ||
logger_1.logger.warn(`Type [${columnName}] has been mapped to [any] because no specific type has been found.`); | ||
return types_1.NonComparable.any; | ||
@@ -87,0 +88,0 @@ } |
@@ -19,2 +19,3 @@ "use strict"; | ||
const introspection_1 = require("./introspection"); | ||
const logger_1 = require("../lib/logger"); | ||
class PostgresIntrospection extends introspection_1.Introspection { | ||
@@ -90,3 +91,3 @@ constructor(params) { | ||
else { | ||
console.log(`Type [${columnName}] has been mapped to [any] because no specific type has been found.`); | ||
logger_1.logger.warn(`Type [${columnName}] has been mapped to [any] because no specific type has been found.`); | ||
return types_1.NonComparable.any; | ||
@@ -93,0 +94,0 @@ } |
@@ -20,2 +20,3 @@ "use strict"; | ||
const path_1 = require("path"); | ||
const logger_1 = require("../lib/logger"); | ||
const prettierDefault = { | ||
@@ -49,6 +50,6 @@ semi: true, | ||
if (config) { | ||
console.log('Using custom prettier config from file ', file); | ||
logger_1.logger.info('Using custom prettier config from file ', file); | ||
return config; | ||
} | ||
console.log('Using default prettier config'); | ||
logger_1.logger.info('Using default prettier config'); | ||
return prettierDefault; | ||
@@ -55,0 +56,0 @@ } |
@@ -0,1 +1,8 @@ | ||
# [0.4.0](https://github.com/MattGson/relational-schema/compare/v0.3.1...v0.4.0) (2021-05-11) | ||
### Features | ||
* **cli:** print a relation tree from a table ([f73d689](https://github.com/MattGson/relational-schema/commit/f73d689cb1849427518f319e88c253e40b296682)), closes [#13](https://github.com/MattGson/relational-schema/issues/13) | ||
## [0.3.1](https://github.com/MattGson/relational-schema/compare/v0.3.0...v0.3.1) (2021-05-10) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "relational-schema", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "Generate a js schema for a relational database", | ||
@@ -68,2 +68,3 @@ "keywords": [ | ||
"dependencies": { | ||
"chalk": "^4.1.1", | ||
"fs-extra": "^9.0.1", | ||
@@ -76,3 +77,3 @@ "knex": "^0.21.2", | ||
"promise-mysql": "^4.1.3", | ||
"yargs": "^15.4.1" | ||
"yargs": "^17.0.1" | ||
}, | ||
@@ -79,0 +80,0 @@ "config": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
147087
61
1848
9
3
+ Addedchalk@^4.1.1
+ Addedchalk@4.1.2(transitive)
+ Addedcliui@8.0.1(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedwrap-ansi@7.0.0(transitive)
+ Addedy18n@5.0.8(transitive)
+ Addedyargs@17.7.2(transitive)
+ Addedyargs-parser@21.1.1(transitive)
- Removedcamelcase@5.3.1(transitive)
- Removedcliui@6.0.0(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removedfind-up@4.1.0(transitive)
- Removedlocate-path@5.0.0(transitive)
- Removedp-limit@2.3.0(transitive)
- Removedp-locate@4.1.0(transitive)
- Removedp-try@2.2.0(transitive)
- Removedpath-exists@4.0.0(transitive)
- Removedrequire-main-filename@2.0.0(transitive)
- Removedset-blocking@2.0.0(transitive)
- Removedwhich-module@2.0.1(transitive)
- Removedwrap-ansi@6.2.0(transitive)
- Removedy18n@4.0.3(transitive)
- Removedyargs@15.4.1(transitive)
- Removedyargs-parser@18.1.3(transitive)
Updatedyargs@^17.0.1