Socket
Socket
Sign inDemoInstall

typeormgen

Package Overview
Dependencies
215
Maintainers
4
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.11.3 to 0.12.0

79

cli.js

@@ -16,2 +16,10 @@ #!/usr/bin/env node

},
client: {
alias: 'c',
describe: 'The database client: mysql or sqlite3'
},
filename: {
alias: 'f',
describe: 'Path to a sqlite database file'
},
host: {

@@ -109,3 +117,3 @@ alias: 'h',

} else {
dotenv.config({ path: path.resolve(__dirname, '..', '..', '.env') });
dotenv.config({ path: path.resolve(process.cwd(), '.env') });
}

@@ -142,3 +150,3 @@

file: 'typeormgen.json',
dir: __dirname,
dir: process.cwd(),
search: true

@@ -149,2 +157,3 @@ });

nconf.defaults({
client: 'mysql',
tabSize: 4

@@ -164,5 +173,7 @@ });

const client = nconf.get('client');
const knex = Knex({
client: 'mysql',
client,
connection: {
filename: nconf.get('filename'),
host: nconf.get('host'),

@@ -176,22 +187,46 @@ port: nconf.get('port'),

knex.raw(`DESCRIBE ${nconf.get('table')}`).then(([rows]) => {
const info = {};
rows.forEach(row => {
const openIndex = row.Type.indexOf('(');
info[row.Field] = {
type: openIndex > -1 ? row.Type.slice(0, openIndex - row.Type.length): row.Type,
length: parseInt(row.Type.slice(openIndex + 1, -1), 10),
nullable: row.Null === 'YES'
};
if (info[row.Field].type === 'decimal') {
info[row.Field].length += 1;
if (client === 'mysql') {
knex.raw(`DESCRIBE ${nconf.get('table')}`).then(([rows]) => {
const info = {};
rows.forEach(row => {
const openIndex = row.Type.indexOf('(');
info[row.Field] = {
type: openIndex > -1 ? row.Type.slice(0, openIndex - row.Type.length): row.Type,
length: parseInt(row.Type.slice(openIndex + 1, -1), 10),
nullable: row.Null === 'YES'
};
if (info[row.Field].type === 'decimal') {
info[row.Field].length += 1;
}
});
try {
writeModel(info, nconf);
} catch (err) {
console.error(err);
process.exit(1);
}
process.exit();
});
try {
writeModel(info, nconf);
} catch (err) {
console.error(err);
process.exit(1);
}
process.exit();
});
} else {
knex(nconf.get('table')).columnInfo().then(columns => {
const info = {};
Object.keys(columns).forEach(name => {
const column = columns[name];
info[name] = {
type: column.type,
length: parseInt(column.maxLength, 10),
nullable: column.nullable
};
if (info[name].type === 'decimal') {
info[name].length += 1;
}
});
try {
writeModel(info, nconf);
} catch (err) {
console.error(err);
process.exit(1);
}
process.exit();
});
}
{
"name": "typeormgen",
"version": "0.11.3",
"version": "0.12.0",
"description": "Generate typeorm models from your database tables",

@@ -31,4 +31,5 @@ "main": "index.js",

"mysql": "^2.15.0",
"nconf": "^0.10.0"
"nconf": "^0.10.0",
"sqlite3": "^4.0.6"
}
}

@@ -5,4 +5,19 @@ const { boolTypes, dateTypes } = require('./constants');

let content = `${tab}assign(props?: GenPartial<${conf.get('model')}>) {
${tab}${tab}super.assign(props);
`;
if (conf.get('base')) {
content += `${tab}${tab}super.assign(props);
`;
} else {
content += `${tab}${tab}if (props) {
`;
if (conf.get('toJSON')) {
content += `${tab}${tab}${tab}Object.assign(this, props.toJSON ? props.toJSON() : props);
`;
} else {
content += `${tab}${tab}${tab}Object.assign(this, props);
`;
}
content += `${tab}${tab}}
`;
}

@@ -45,3 +60,3 @@ let transformers = '';

content += `${tab}}
`;

@@ -48,0 +63,0 @@

module.exports = function(info, tab, conf) {
let content = `${tab}constructor(props?: GenPartial<${conf.get('model')}>) {
${tab}${tab}super(props);
${tab}}
}
`;
if (conf.get('base')) {
content += `${tab}${tab}super(props);
`;
} else {
content += `${tab}${tab}this.assign(props);
`;
}
content += `${tab}}
}`;
return content;
};
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc