diff --git a/README.md b/README.md index b09e216..1091285 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,10 @@ Supports the following databases: MySQL, Microsoft SQL Server, SQLite and Postgr `npx sql-ts-knex-generator -c ./config.json` +It will create a folder and generate a file for each table containing CRUD (create, read, update, delete) functions based on DB schema. + +It respects nullable and required fields. + ## Config file options [Config file options](https://saostad.github.io/sql-ts-knex-generator/interfaces/config.html) diff --git a/dist/cli.js b/dist/cli.js index 3c95182..30fcd3d 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -52,6 +52,7 @@ if (typeof config.template !== "string") { /** Create out directory if not exist */ try { fs.mkdirSync(outDirPath); + console.log(`${outDirPath} folder has been created.`); } catch (error) { if (error.code !== "EEXIST") { @@ -59,11 +60,14 @@ catch (error) { } } (async () => { + console.log(`Connecting to db...`); const decoratedDatabase = await index_1.toObject(config); const { tables } = decoratedDatabase; + console.log(`Analyzing table's schema...`); const eachTable = tables.map((el) => // TODO: add enums instead of ignoring it index_1.DatabaseTasks.stringifyDatabase({ tables: [el], enums: [] }, config)); + console.log(`Creating TS files...`); eachTable.forEach((el, index) => { const filePath = path.join(outDirPath, `${decoratedDatabase.tables[index].name}.ts`); fs.writeFileSync(filePath, el); @@ -76,6 +80,7 @@ export * from "./{{table.name}}"; const filePath = path.join(outDirPath, `index.ts`); fs.writeFileSync(filePath, indexContent); } - console.log(`files written in directory ${outDirPath}`); + console.log(`Files written in directory ${outDirPath}`); + console.log(`You can use "import {} form 'index.ts'"`); })(); //# sourceMappingURL=cli.js.map \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index b13c421..f22b4b1 100644 --- a/docs/index.html +++ b/docs/index.html @@ -67,6 +67,8 @@

A simple command line tool to generate typescript CRUD operations

How to use

npx sql-ts-knex-generator -c ./config.json

+

It will create a folder and generate a file for each table containing CRUD (create, read, update, delete) functions based on DB schema.

+

It respects nullable and required fields.

Config file options

diff --git a/docs/interfaces/config.html b/docs/interfaces/config.html index 88c587a..ac49d59 100644 --- a/docs/interfaces/config.html +++ b/docs/interfaces/config.html @@ -196,7 +196,7 @@

Optional createIndex
createIndexFile: undefined | boolean
diff --git a/package.json b/package.json index 9d33c67..61601be 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sql-ts-knex-generator", - "version": "1.5.1", + "version": "1.5.2", "main": "./dist/index.js", "description": "A simple command line tool to generate typescript CRUD operations from database schemas.", "bin": "./bin/sql-ts-knex-generator", @@ -43,7 +43,9 @@ "typescript", "interface", "generator", - "CRUD" + "CRUD", + "sql", + "schema" ], "nodemonConfig": { "ignore": [ diff --git a/src/cli.ts b/src/cli.ts index 0c091c2..74ab192 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -40,6 +40,7 @@ if (typeof config.template !== "string") { /** Create out directory if not exist */ try { fs.mkdirSync(outDirPath); + console.log(`${outDirPath} folder has been created.`); } catch (error) { if (error.code !== "EEXIST") { console.log(error); @@ -47,15 +48,21 @@ try { } (async () => { + console.log(`Connecting to db...`); + const decoratedDatabase = await toObject(config); const { tables } = decoratedDatabase; + console.log(`Analyzing table's schema...`); + const eachTable = tables.map((el) => // TODO: add enums instead of ignoring it DatabaseTasks.stringifyDatabase({ tables: [el], enums: [] }, config), ); + console.log(`Creating TS files...`); + eachTable.forEach((el, index) => { const filePath = path.join( outDirPath, @@ -74,5 +81,6 @@ export * from "./{{table.name}}"; const filePath = path.join(outDirPath, `index.ts`); fs.writeFileSync(filePath, indexContent); } - console.log(`files written in directory ${outDirPath}`); + console.log(`Files written in directory ${outDirPath}`); + console.log(`You can use "import {} form 'index.ts'"`); })();