Skip to content

Commit

Permalink
doc: Readme updated & more logs added.
Browse files Browse the repository at this point in the history
  • Loading branch information
Saeid Ostad committed Jan 13, 2021
1 parent 21f91b1 commit 2b6565b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion dist/cli.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ <h1>A simple command line tool to generate typescript CRUD operations</h1>
<h2>How to use</h2>
</a>
<p><code>npx sql-ts-knex-generator -c ./config.json</code></p>
<p>It will create a folder and generate a file for each table containing CRUD (create, read, update, delete) functions based on DB schema.</p>
<p>It respects nullable and required fields.</p>
<a href="#config-file-options" id="config-file-options" style="color: inherit; text-decoration: none;">
<h2>Config file options</h2>
</a>
Expand Down
2 changes: 1 addition & 1 deletion docs/interfaces/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> create<wbr>Index<wbr>
<div class="tsd-signature tsd-kind-icon">create<wbr>Index<wbr>File<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">undefined</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">boolean</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/saostad/sql-ts-knex-generator/blob/660547a/src/index.ts#L10">src/index.ts:10</a></li>
<li>Defined in <a href="https://github.com/saostad/sql-ts-knex-generator/blob/21f91b1/src/index.ts#L10">src/index.ts:10</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -43,7 +43,9 @@
"typescript",
"interface",
"generator",
"CRUD"
"CRUD",
"sql",
"schema"
],
"nodemonConfig": {
"ignore": [
Expand Down
10 changes: 9 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,29 @@ 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);
}
}

(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,
Expand All @@ -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'"`);
})();

0 comments on commit 2b6565b

Please sign in to comment.