-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen-mysql.js
More file actions
executable file
·37 lines (34 loc) · 1.4 KB
/
gen-mysql.js
File metadata and controls
executable file
·37 lines (34 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/node
const fs = require('fs')
const path = require('path')
const program = require('commander')
const MySqlDatabaseConnection = require('./lib/databaseConnections/MySqlDatabaseConnection')
const Generator = require('./lib/Generator')
program
.option('-c, --config <path>', 'path to db config file')
.option('-t, --table <name>', 'table name (otherwise all)')
.option('-d, --destination <path>', 'path where files should be created', '.')
program.parse(process.argv)
if (!program.config) {
program.help()
}
const dbConfigPathAbsolute = path.resolve(program.config)
const dbConfigPathRelative = path.relative(program.destination, dbConfigPathAbsolute)
const dbConfig = require(dbConfigPathAbsolute)
let tableNames = []
if (program.table) {
tableNames = [program.table]
}
async function run (tableNames, dbConfigPath, targetPath) {
const testDbConnection = new MySqlDatabaseConnection(dbConfig)
if (tableNames.length === 0) {
tableNames = await testDbConnection.getTableNames()
}
for (const tableName of tableNames) {
const tableShema = await testDbConnection.getTableShema(tableName)
const generator = new Generator()
const classContent = generator.createClass(tableShema, dbConfigPath, 'MySqlDatabaseConnection')
fs.writeFileSync(path.join(targetPath, generator.createClassName(tableName)) + '.js', classContent)
}
}
run(tableNames, dbConfigPathRelative, program.destination)