diff --git a/README.md b/README.md index 2b11555..02221aa 100644 --- a/README.md +++ b/README.md @@ -30,18 +30,19 @@ Usage: typeorm-model-generator -h -d -p [port] -u -x Options: --help Show help [boolean] --version Show version number [boolean] - -h, --host IP adress/Hostname for database server. [required] - -d, --database Database name. [required] - -u, --user Username for database server. [required] - -x, --pass Password for database server. [default: ""] - -p, --port Port number for database server. - -e, --engine Database engine. + -h, --host IP adress/Hostname for database server + [default: "127.0.0.1"] + -d, --database Database name(or path for sqlite) [required] + -u, --user Username for database server + -x, --pass Password for database server [default: ""] + -p, --port Port number for database server + -e, --engine Database engine [choices: "mssql", "postgres", "mysql", "mariadb", "oracle", "sqlite"] [default: "mssql"] - -o, --output Where to place generated models. + -o, --output Where to place generated models [default: "Z:\Repos\typeorm-model-generator\output"] -s, --schema Schema name to create model from. Only for mssql and - postgres. + postgres --ssl [boolean] [default: false] --noConfig Doesn't create tsconfig.json and ormconfig.json [boolean] [default: false] @@ -51,7 +52,9 @@ Options: [choices: "pascal", "camel", "none"] [default: "none"] --cp, --case-property Convert property names to specified case [choices: "pascal", "camel", "none"] [default: "none"] - --lazy Generate lazy relations [boolean] [default: false] + --lazy Generate lazy relations [boolean] [default: false] + --generateConstructor Generate constructor allowing partial initialization + [boolean] [default: false] ``` ### Examples @@ -73,3 +76,12 @@ Options: ``` npx typeorm-model-generator -h localhost -d postgres -u postgres -x !Passw0rd -e postgres -o . -s public --ssl ```` +* Creating model from SQLite database + * Global module + ``` + typeorm-model-generator -d "Z:\sqlite.db" -e sqlite -o . + ```` + * Npx Way + ``` + npx typeorm-model-generator -d "Z:\sqlite.db" -e sqlite -o . + ```` diff --git a/src/index.ts b/src/index.ts index 8e79a44..967fd3f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,43 +15,42 @@ var argv = Yargs.usage( ) .option("h", { alias: "host", - describe: "IP adress/Hostname for database server.", - demand: true + describe: "IP adress/Hostname for database server", + default: "127.0.0.1" }) .option("d", { alias: "database", - describe: "Database name.", + describe: "Database name(or path for sqlite)", demand: true }) .option("u", { alias: "user", - describe: "Username for database server.", - demand: true + describe: "Username for database server" }) .option("x", { alias: "pass", - describe: "Password for database server.", + describe: "Password for database server", default: "" }) .option("p", { alias: "port", - describe: "Port number for database server." + describe: "Port number for database server" }) .option("e", { alias: "engine", - describe: "Database engine.", + describe: "Database engine", choices: ["mssql", "postgres", "mysql", "mariadb", "oracle", "sqlite"], default: "mssql" }) .option("o", { alias: "output", - describe: "Where to place generated models.", + describe: "Where to place generated models", default: path.resolve(process.cwd(), "output") }) .option("s", { alias: "schema", describe: - "Schema name to create model from. Only for mssql and postgres." + "Schema name to create model from. Only for mssql and postgres" }) .option("ssl", { boolean: true, @@ -91,31 +90,37 @@ var argv = Yargs.usage( default: false }).argv; -var driver: AbstractDriver; -var standardPort: number; -var standardSchema: string = ""; +let driver: AbstractDriver; +let standardPort: number; +let standardSchema: string = ""; +let standardUser: string = ""; switch (argv.e) { case "mssql": driver = new MssqlDriver(); standardPort = 1433; standardSchema = "dbo"; + standardUser = "sa"; break; case "postgres": driver = new PostgresDriver(); standardPort = 5432; standardSchema = "public"; + standardUser = "postgres"; break; case "mysql": driver = new MysqlDriver(); standardPort = 3306; + standardUser = "root"; break; case "mariadb": driver = new MysqlDriver(); standardPort = 3306; + standardUser = "root"; break; case "oracle": driver = new OracleDriver(); standardPort = 1521; + standardUser = "SYS"; break; case "sqlite": driver = new SqliteDriver(); @@ -130,7 +135,7 @@ let engine = new Engine(driver, { host: argv.h, port: parseInt(argv.p) || standardPort, databaseName: argv.d ? argv.d.toString() : null, - user: argv.u ? argv.u.toString() : null, + user: argv.u ? argv.u.toString() : standardUser, password: argv.x ? argv.x.toString() : null, databaseType: argv.e, resultsPath: argv.o ? argv.o.toString() : null,