Gathering detailed insights and metrics for sequelize-typescript-model-auto
Gathering detailed insights and metrics for sequelize-typescript-model-auto
Gathering detailed insights and metrics for sequelize-typescript-model-auto
Gathering detailed insights and metrics for sequelize-typescript-model-auto
Generate your sequelize-typescript models codes from a postgres or mysql database
npm install sequelize-typescript-model-auto
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (78.17%)
JavaScript (19.14%)
Handlebars (2.7%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
11 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Oct 10, 2024
Latest Version
1.0.4
Package Id
sequelize-typescript-model-auto@1.0.4
Unpacked Size
87.88 kB
Size
20.46 kB
File Count
44
NPM Version
10.5.0
Node Version
20.12.0
Published on
Oct 10, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Automatically generate your codes based on any database: postgres, mysql, mssql or sqlite. Through a relational database you can automatically generate the development files:
Node Js v10 or higher installation required
Globally install the package:
1npm install ferreiro -g
Run the command below to verify the installation:
1ferreiro --help
The command should display the list of options:
1ferreiro --help 2Usage: ferreiro [options] 3 4Options: 5 --genenv Generate env file in root path 6 --dialect Select dialect postgres, mysql or mssql 7 --database <name> Name of database 8 --schema <schema name> schema 9 --host <host> Host of database 10 --port <port> Port number 11 --user <host> User of database 12 --pw Password of database 13 --env <path> User of database 14 --tables <table1, table2, ...> tables of db 15 --skipTables <table1, table2, ...> skip tables of db 16 --template <path> path of template generate files 17 --overwriteFile <true|false (default false)> overwrite file in out dir 18 --dbug <true|false> Show dbug logs 19 --outDir <path> path of generated files 20 -h, --help output usage information
Run the command below to create the environment configuration file:
1ferreiro --createenv
Configure o arquivo .env-gen.
1#FERREIRO ENV VARIABLES 2dialect = [postgres, mysql, mssql or sqlite] 3database = [...name of database] 4host = 127.0.0.1 5pass = [..pass] 6port = [..set a port] 7schema = [..schema only in pg] 8user = [..set user]
Ferreiro is divided into two parts:
All logic of the template is written using the tool handlebarsjs, for more information see the documentation of this tool.
Rest assured, you will understand everything through practical examples.
Create a folder with the name of your choice, this folder will contain all files related to the template. In our case the folder name will be: new-template Inside the folder create a folder with the name of example01: In examble01/ create file named example01/index.hbs content:
{{#each this.tableData}}
#begin_file
{{fileName '' (camelcase this.tablename true) '.txt'}}
Name of table {{this.tablename}}
Fields:
{{#each this.fields}}
Name: {{this.name}}
type: {{this.type}}
allowNull: {{this.allowNull}}
defaultValue: {{this.defaultValue}}
comment: {{this.comment}}
primaryKey: {{this.primaryKey}}
isIdentity: {{this.isIdentity}}
identity: {{this.identity}}
isPrimaryKey: {{this.isPrimaryKey}}
isUniqueKey: {{this.isUniqueKey}}
isSerialKey: {{this.isSerialKey}} (only pg)
isForeignKey: {{this.isForeignKey}}
{{#if this.isForeignKey}}
Fk Information:
constraint_name: {{this.foreignKey.constraint_name}}
source_schema: {{this.foreignKey.source_schema}}
source_table: {{this.foreignKey.source_table}}
source_column: {{this.foreignKey.source_column}}
target_schema: {{this.foreignKey.target_schema}}
target_table: {{this.foreignKey.target_table}}
target_column: {{this.foreignKey.target_column}}
contype: {{this.foreignKey.contype}}
extra: {{this.foreignKey.extra}}
{{/if}}
---------------------
{{/each}}
{{/each}}
Generate the example template and see the output that will be sent to the directory informed in "outDir"
1ferreiro --template ./ --outDir ./build-gen --env .env-gen --overwriteFile true
Loaded 93 tables of db TEST
Loaded undefined config file
Loaded 0 script file(s)
Find 1 file(s) in /home/user/new-example template.
Generated 93 file(s) in /new-example/build-gen.
The command will generate the files based on your database, inside the build-gen folder.
Create another example ./example02/index.hbs containing:
#begin_file
{{fileName 'lists.txt'}}
{{#each this.tableData}}
{{this.tablename}}
Fields: {{#each this.fields}}{{this.name}},{{/each}}
{{/each}}
1ferreiro --template ./ --outDir ./build-gen --env .env-gen --overwriteFile true
To send extra information you need to create a .json file from the root of the template, see the example:
create file ./example03/config.json
containing:
1{ 2 "data": { 3 "extra-str": "Hello extra info", 4 "extra-obj": { 5 "name": "Leonardo", 6 "age": "26" 7 }, 8 "extra-array": [{ 9 "name": "Teste" 10 }, { 11 "name": "Teste2" 12 }] 13 } 14}
create file ./example03/index.hbs containing:
#begin_file
{{fileName 'test-extra.txt'}}
Extra string: {{this.data.extra-str}}
Extra obj:
name: {{this.data.extra-obj.name}}
age: {{this.data.extra-obj.age}}
Extra array:
{{#each this.data.extra-array}}
name: {{this.name}}
{{/each}}
1ferreiro --template ./ --outDir ./build-gen --env .env-gen --overwriteFile true
Create another example ./example04/helper.js containing:
1module.exports = (Handlebars) => { 2 Handlebars.registerHelper('sum', function (val1, val2) { 3 return Number(val1) + Number(val2); 4 }); 5 6 Handlebars.registerHelper('concat', function (val1, val2) { 7 return val1 + val2; 8 }); 9 10 Handlebars.registerHelper('autor', function (val1, val2) { 11 return "Ferreiro"; 12 }); 13}
Create hbs file ./example04/index.js containing:
#begin_file
{{fileName 'test-helper.txt'}}
Sum 1: {{sum 40 20}}
Sum 2: {{sum 15 15}}
Name: {{concat 'Ferreiro' '-v1'}}
by {{autor}}
Build:
1ferreiro --template ./ --outDir ./build-gen --env .env-gen --overwriteFile true
after template build:
Sum 1: 60
Sum 2: 30
Name: Ferreiro-v1
by Ferreiro
See more about helpers at Handlebars Helpers
upper case of text
lower case of text
return true if val !== undefined && val !== null
use to template contains {{ see:
{{{{raw-helper}}}}
{{goku!}}
{{{{/raw-helper}}}}
build to
{{goku!}}
return Object.keys(obj)
camelcase lib see: Camelcase
return new Date();
return !arg;
return comp1 === comp2;
return arr.findIndex(el => el === value) !== -1;
set a file name ...
create template variable
example:
#begin_file
{{fileName 'test.txt'}}
{{set 'age' '26'}}
{{set 'name' 'Leonardo'}}
Name: {{get 'name'}}
Age: {{get 'age'}}
build to:
Name: Leonardo
Age: 26
No vulnerabilities found.
No security vulnerabilities found.