Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

relational-schema

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

relational-schema - npm Package Compare versions

Comparing version 0.3.1 to 0.4.0

build/src/lib/logger.d.ts

151

build/src/cli/entry.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc