midway-model-gen 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/codeStyles/Project.xml +57 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/prettier.xml +6 -0
- package/.idea/test.iml +8 -0
- package/.idea/vcs.xml +6 -0
- package/CHANGELOG.md +161 -0
- package/CONTRIBUTING.md +51 -0
- package/DEVELOPER.md +30 -0
- package/LICENSE +21 -0
- package/README.md +94 -0
- package/USECASES.md +53 -0
- package/bin/typeorm-model-generator +6 -0
- package/dist/package.json +106 -0
- package/dist/src/Engine.d.ts +7 -0
- package/dist/src/Engine.js +47 -0
- package/dist/src/IConnectionOptions.d.ts +14 -0
- package/dist/src/IConnectionOptions.js +22 -0
- package/dist/src/IGenerationOptions.d.ts +24 -0
- package/dist/src/IGenerationOptions.js +33 -0
- package/dist/src/ModelCustomization.d.ts +4 -0
- package/dist/src/ModelCustomization.js +256 -0
- package/dist/src/ModelGeneration.d.ts +4 -0
- package/dist/src/ModelGeneration.js +247 -0
- package/dist/src/NamingStrategy.d.ts +10 -0
- package/dist/src/NamingStrategy.js +61 -0
- package/dist/src/Utils.d.ts +6 -0
- package/dist/src/Utils.js +68 -0
- package/dist/src/drivers/AbstractDriver.d.ts +30 -0
- package/dist/src/drivers/AbstractDriver.js +258 -0
- package/dist/src/drivers/MariaDbDriver.d.ts +4 -0
- package/dist/src/drivers/MariaDbDriver.js +11 -0
- package/dist/src/drivers/MssqlDriver.d.ts +25 -0
- package/dist/src/drivers/MssqlDriver.js +408 -0
- package/dist/src/drivers/MysqlDriver.d.ts +27 -0
- package/dist/src/drivers/MysqlDriver.js +439 -0
- package/dist/src/drivers/OracleDriver.d.ts +25 -0
- package/dist/src/drivers/OracleDriver.js +316 -0
- package/dist/src/drivers/PostgresDriver.d.ts +31 -0
- package/dist/src/drivers/PostgresDriver.js +542 -0
- package/dist/src/drivers/SqliteDriver.d.ts +28 -0
- package/dist/src/drivers/SqliteDriver.js +308 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +667 -0
- package/dist/src/library.d.ts +11 -0
- package/dist/src/library.js +14 -0
- package/dist/src/models/Column.d.ts +24 -0
- package/dist/src/models/Column.js +3 -0
- package/dist/src/models/Entity.d.ts +21 -0
- package/dist/src/models/Entity.js +3 -0
- package/dist/src/models/Index.d.ts +9 -0
- package/dist/src/models/Index.js +3 -0
- package/dist/src/models/Relation.d.ts +11 -0
- package/dist/src/models/Relation.js +3 -0
- package/dist/src/models/RelationId.d.ts +5 -0
- package/dist/src/models/RelationId.js +3 -0
- package/dist/src/models/RelationInternal.d.ts +11 -0
- package/dist/src/models/RelationInternal.js +3 -0
- package/dist/src/templates/entity.mst +47 -0
- package/dist/src/templates/index.mst +5 -0
- package/dist/src/templates/ormconfig.mst +17 -0
- package/dist/src/templates/tsconfig.mst +10 -0
- package/npminstall-debug.log +175 -0
- package/package.json +106 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<component name="ProjectCodeStyleConfiguration">
|
|
2
|
+
<code_scheme name="Project" version="173">
|
|
3
|
+
<HTMLCodeStyleSettings>
|
|
4
|
+
<option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
|
|
5
|
+
</HTMLCodeStyleSettings>
|
|
6
|
+
<JSCodeStyleSettings version="0">
|
|
7
|
+
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
|
8
|
+
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
|
9
|
+
<option name="FORCE_QUOTE_STYlE" value="true" />
|
|
10
|
+
<option name="ENFORCE_TRAILING_COMMA" value="Remove" />
|
|
11
|
+
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
|
12
|
+
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
|
13
|
+
</JSCodeStyleSettings>
|
|
14
|
+
<TypeScriptCodeStyleSettings version="0">
|
|
15
|
+
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
|
16
|
+
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
|
17
|
+
<option name="FORCE_QUOTE_STYlE" value="true" />
|
|
18
|
+
<option name="ENFORCE_TRAILING_COMMA" value="Remove" />
|
|
19
|
+
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
|
20
|
+
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
|
21
|
+
</TypeScriptCodeStyleSettings>
|
|
22
|
+
<VueCodeStyleSettings>
|
|
23
|
+
<option name="INTERPOLATION_NEW_LINE_AFTER_START_DELIMITER" value="false" />
|
|
24
|
+
<option name="INTERPOLATION_NEW_LINE_BEFORE_END_DELIMITER" value="false" />
|
|
25
|
+
</VueCodeStyleSettings>
|
|
26
|
+
<codeStyleSettings language="HTML">
|
|
27
|
+
<option name="SOFT_MARGINS" value="80" />
|
|
28
|
+
<indentOptions>
|
|
29
|
+
<option name="INDENT_SIZE" value="2" />
|
|
30
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
31
|
+
<option name="TAB_SIZE" value="2" />
|
|
32
|
+
</indentOptions>
|
|
33
|
+
</codeStyleSettings>
|
|
34
|
+
<codeStyleSettings language="JavaScript">
|
|
35
|
+
<option name="SOFT_MARGINS" value="80" />
|
|
36
|
+
<indentOptions>
|
|
37
|
+
<option name="INDENT_SIZE" value="2" />
|
|
38
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
39
|
+
<option name="TAB_SIZE" value="2" />
|
|
40
|
+
</indentOptions>
|
|
41
|
+
</codeStyleSettings>
|
|
42
|
+
<codeStyleSettings language="TypeScript">
|
|
43
|
+
<option name="SOFT_MARGINS" value="80" />
|
|
44
|
+
<indentOptions>
|
|
45
|
+
<option name="INDENT_SIZE" value="2" />
|
|
46
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
47
|
+
<option name="TAB_SIZE" value="2" />
|
|
48
|
+
</indentOptions>
|
|
49
|
+
</codeStyleSettings>
|
|
50
|
+
<codeStyleSettings language="Vue">
|
|
51
|
+
<option name="SOFT_MARGINS" value="80" />
|
|
52
|
+
<indentOptions>
|
|
53
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
54
|
+
</indentOptions>
|
|
55
|
+
</codeStyleSettings>
|
|
56
|
+
</code_scheme>
|
|
57
|
+
</component>
|
package/.idea/test.iml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="WEB_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager">
|
|
4
|
+
<content url="file://$MODULE_DIR$" />
|
|
5
|
+
<orderEntry type="inheritedJdk" />
|
|
6
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
7
|
+
</component>
|
|
8
|
+
</module>
|
package/.idea/vcs.xml
ADDED
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.4.6
|
|
4
|
+
* Fix typecasting problem when using old version mysql (#326)
|
|
5
|
+
* Update dependencies
|
|
6
|
+
|
|
7
|
+
## 0.4.5
|
|
8
|
+
* **typeorm-model-generator enters maintenance phase (#329)**
|
|
9
|
+
* Fix oracle driver to work with latest version of typeorm (#328)
|
|
10
|
+
|
|
11
|
+
## 0.4.4
|
|
12
|
+
* Add ltree type support for PostgreSQL (#318)
|
|
13
|
+
* Mysql fulltext index base support (#285)
|
|
14
|
+
* Fix @PrimaryGeneratedColumn marked as unique(#239)
|
|
15
|
+
* Proper relationId, ralationName none caseing (#280)
|
|
16
|
+
* Keep old tsconfig and ormconfig files instead of generated ones (#154)
|
|
17
|
+
* MSSQL model generation speed optimization (#312)
|
|
18
|
+
* Mysql8 support (#311)
|
|
19
|
+
* Allow database names with special characters (#273)
|
|
20
|
+
* Naming strategy for entity file names (#236)
|
|
21
|
+
* Support MSSQL named instances (#300)
|
|
22
|
+
|
|
23
|
+
## 0.4.3
|
|
24
|
+
* Add ability to generate models only for specyfic tables (#296)
|
|
25
|
+
* Fix for generating one-to-many RelationId columns (#291)
|
|
26
|
+
* Support for identity in newer postgres databases (#291)
|
|
27
|
+
* Fixed bug with Mssql IsIdentity on tables with non-default schema name (#275)
|
|
28
|
+
* Option to generate properties with snake_case (#295)
|
|
29
|
+
|
|
30
|
+
## 0.4.2
|
|
31
|
+
|
|
32
|
+
* Use statement not available on Azure SQL (#243)
|
|
33
|
+
* Allow models which don't generate properly to be saved (#259)
|
|
34
|
+
* MySQL and MariaDB column comments (#260)
|
|
35
|
+
* JSON default values (#248,#256)
|
|
36
|
+
|
|
37
|
+
## 0.4.1
|
|
38
|
+
|
|
39
|
+
* Fixed model generation on oracle database (#252)
|
|
40
|
+
* New option to define line ending character (#241)
|
|
41
|
+
* Fixed model generation for two table with same name, different schema on mssql (#246)
|
|
42
|
+
* Proper naming strategy typings (#249)
|
|
43
|
+
* Release version without installed db drivers
|
|
44
|
+
|
|
45
|
+
## 0.4.0
|
|
46
|
+
|
|
47
|
+
### BREAKING CHANGES
|
|
48
|
+
|
|
49
|
+
* Custom NamingStrategy is now defined as separate functions instead of a class
|
|
50
|
+
* Rework how parameters are passed to the library:
|
|
51
|
+
- Utilization of partial config files
|
|
52
|
+
- Option to save .tomg-config file without connection options
|
|
53
|
+
* Generation of separate fields for primary columns which are used in relations(old approach won't be compatible with typeorm@0.3.0)
|
|
54
|
+
* Remove timeout parameter - query timeout is now set by default to 1 hr
|
|
55
|
+
* Change default case conversions for generated files (#196)
|
|
56
|
+
|
|
57
|
+
### FIXES
|
|
58
|
+
* Support complex relationships (#117)
|
|
59
|
+
* Proper support for many to many relations
|
|
60
|
+
* Proper pluralization of entity names (#142)
|
|
61
|
+
* Skip generation of imports not used by entity definition files
|
|
62
|
+
* Skip generation of indices generated by PKs or relations
|
|
63
|
+
* Columns with unrecognized sql type are generated with unknown type
|
|
64
|
+
* Generation of proper type for nullable columns
|
|
65
|
+
* Fixed specifying custom naming strategy by relative path (#171)
|
|
66
|
+
* Disallow generation of relationId fields with lazy relations(not supported in typeorm)
|
|
67
|
+
|
|
68
|
+
### ENHANCEMENTS
|
|
69
|
+
* Support for old oracle versions (#195)
|
|
70
|
+
* New options:
|
|
71
|
+
* Disable column name pluralization (#142)
|
|
72
|
+
* Ignore tables parameter (#120)
|
|
73
|
+
* Generation of index file (#174)
|
|
74
|
+
* Default exports on generated models
|
|
75
|
+
* Enum type safety (#205)
|
|
76
|
+
* Mysql set type support (#91)
|
|
77
|
+
* Postgres geography type support (#232)
|
|
78
|
+
* Make generated models compatible with common ESLint rules
|
|
79
|
+
* Ability to use typeorm-model-generator as library in other projects (but no guarantees about api compatibility between different version)
|
|
80
|
+
|
|
81
|
+
## 0.3.5
|
|
82
|
+
|
|
83
|
+
* moved to ts-node - you can now use this library installed directly from github repo
|
|
84
|
+
* support for UNSIGNED columns in MySQL (#179)
|
|
85
|
+
* support for richer derivation of column & entity name (#176)
|
|
86
|
+
* new option to generate code compliant with `strictPropertyInitialization` flag(#136, #182)
|
|
87
|
+
* new option to skip schema and database identifier in generated entities (#177)
|
|
88
|
+
* new option to specify request timeout (#185)
|
|
89
|
+
* added property visibility to RelationId properties (#167)
|
|
90
|
+
* disabled generating complex relationships(until #117 is fixed)
|
|
91
|
+
* fixed issue with setting precision when scale isn't default on numeric types (#184)
|
|
92
|
+
* PostgreSQL enum support (#187)
|
|
93
|
+
* generating access modifier to constructor (#169)
|
|
94
|
+
* fixed RelationId generation with different casing scenarios (#192)
|
|
95
|
+
|
|
96
|
+
## 0.3.4
|
|
97
|
+
|
|
98
|
+
* fixed using property case on uppercase columns(#157)
|
|
99
|
+
|
|
100
|
+
## 0.3.3
|
|
101
|
+
|
|
102
|
+
* added bit type support for mysql/mariadb
|
|
103
|
+
* fixed generation of relations with only onUpdate defined(#139)
|
|
104
|
+
|
|
105
|
+
## 0.3.2
|
|
106
|
+
* added option to generate models based on multiple databases(#144)
|
|
107
|
+
* fixed generation of ManyToMany relations on junction tables with custom names(#151)
|
|
108
|
+
* fixed problems with mysql 8
|
|
109
|
+
* fixed shadowed variables tslint errors(#141)
|
|
110
|
+
* fixed order of generated columns
|
|
111
|
+
* mariadb default value compatibility changes(#153)
|
|
112
|
+
|
|
113
|
+
## 0.3.1
|
|
114
|
+
* Fixed npx usage(#146)
|
|
115
|
+
|
|
116
|
+
# 0.3.0
|
|
117
|
+
* Wizard mode - you can now run model generation without passing any parameters and provide them step by step. It also allows you to save provided informations for future use
|
|
118
|
+
* generated columns no longer contains options which are set by default in typeorm
|
|
119
|
+
* added support for VARBINARY type on MySQL, MariaDb
|
|
120
|
+
* fixed issue with case conversion and @RetlationId fields
|
|
121
|
+
* a lot of internal work
|
|
122
|
+
|
|
123
|
+
## 0.2.25
|
|
124
|
+
* fixed naming strategy changing entity name in db
|
|
125
|
+
* fixed proper relation generation when unique index have more columns
|
|
126
|
+
|
|
127
|
+
## 0.2.24
|
|
128
|
+
* fixed generation of default values
|
|
129
|
+
* fixed generation of duplicate relations for mysql
|
|
130
|
+
* added option for generating entities for AciveRecord pattern
|
|
131
|
+
|
|
132
|
+
## 0.2.23
|
|
133
|
+
* added column type to generated `@PrimaryGeneratedColumn` decorator
|
|
134
|
+
* allow to define property visibility, by using --pv
|
|
135
|
+
* fixed some problems with duplicated relationships on mysql database
|
|
136
|
+
|
|
137
|
+
## 0.2.22
|
|
138
|
+
* fixed naming strategy for guid ended column names
|
|
139
|
+
* fixed column names case conversion in index declarations
|
|
140
|
+
|
|
141
|
+
## 0.2.21
|
|
142
|
+
* primary keys using identity/sequence are now generated with `@PrimaryGeneratedColumn` decorator [#96](https://github.com/Kononnable/typeorm-model-generator/issues/96)
|
|
143
|
+
|
|
144
|
+
## 0.2.20
|
|
145
|
+
* relation onUpdate fixes
|
|
146
|
+
* postgres support for citext, hstore, geometry, array column types
|
|
147
|
+
* upgraded typeorm version
|
|
148
|
+
|
|
149
|
+
## 0.2.19
|
|
150
|
+
* custom naming strategy fixes
|
|
151
|
+
* dependencies update
|
|
152
|
+
|
|
153
|
+
## 0.2.18
|
|
154
|
+
* oracle output format fixed
|
|
155
|
+
|
|
156
|
+
## 0.2.17
|
|
157
|
+
|
|
158
|
+
* added support for relationId fields
|
|
159
|
+
* added support for custom naming entity fields
|
|
160
|
+
* removed oracledb from dependencies
|
|
161
|
+
* generating nullable column types for nullable columns
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Contributing to typeorm-model-generator
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
- [Question or Problem?](#question)
|
|
5
|
+
- [Submission Guidelines](#submit)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## <a name="question"></a> Got a Question or Problem?
|
|
10
|
+
* You can create issue on [github](https://github.com/Kononnable/typeorm-model-generator/issues)
|
|
11
|
+
* While this tool doesn't have separate separate chat room you can use [typeorm slack workspace](https://join.slack.com/t/typeorm/shared_invite/enQtNDQ1MzA3MDA5MTExLTFiNDEyOGUxZGQyYWIwOTA0NDQxODdkOGQ0OTUxNzFjYjUwY2E0ZmFlODc5OTYyYzAzNGM3MGZjYzhjYTBiZTY) since everyone using typeorm-model-generator will also use typeorm.
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## <a name="submit"></a> Submission Guidelines
|
|
16
|
+
|
|
17
|
+
### <a name="submit-issue"></a> Submitting an Issue
|
|
18
|
+
|
|
19
|
+
Before submitting new issue, please check the issue tracker, maybe your problem is already described and the discussion might inform you of available workarounds.
|
|
20
|
+
|
|
21
|
+
Before fixing a bug we need to reproduce and confirm it. In order to reproduce bugs, we will ask you to provide a minimal reproduction. Having a minimal reproducible scenario gives us a wealth of important information without going back & forth to you with additional questions. A minimal reproduction allows us to quickly confirm a bug (or point out a coding problem) as well as confirm that we are fixing the right problem.
|
|
22
|
+
|
|
23
|
+
### <a name="submit-pr"></a> Submitting a Pull Request (PR)
|
|
24
|
+
Before you submit your Pull Request (PR) consider the following guidelines:
|
|
25
|
+
|
|
26
|
+
1. Search [GitHub](https://github.com/Kononnable/typeorm-model-generator/pulls) for an open or closed PR that relates to your submission. You don't want to duplicate effort.
|
|
27
|
+
1. Make your changes in a new git branch:
|
|
28
|
+
|
|
29
|
+
```shell
|
|
30
|
+
git checkout -b my-fix-branch master
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
1. Create your patch.
|
|
34
|
+
1. Run test suite and ensure that all tests pass.
|
|
35
|
+
1. Commit your changes using a descriptive commit message.
|
|
36
|
+
|
|
37
|
+
1. Push your branch to GitHub:
|
|
38
|
+
|
|
39
|
+
```shell
|
|
40
|
+
git push origin my-fix-branch
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
1. In GitHub, send a pull request to `typeorm-model-generator:master`.
|
|
44
|
+
* If we suggest changes then:
|
|
45
|
+
* Make the required updates.
|
|
46
|
+
* Re-run test suites to ensure tests are still passing.
|
|
47
|
+
* Push to your GitHub repository (this will update your Pull Request)
|
|
48
|
+
|
|
49
|
+
Note: if you don't want to run tests on your machine you can rely on tests run on CI (unless you're changing something oracledb specific).
|
|
50
|
+
|
|
51
|
+
That's it! Thank you for your contribution!
|
package/DEVELOPER.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Setting up environment
|
|
2
|
+
## Building
|
|
3
|
+
After cloning the repository you can check your changes made to source code without compiling whole library. Just run `npm start` to run typeorm-model-generator through ts-node. It helps with development speed and avoids problem with setting correct sourcemaps when debugging.
|
|
4
|
+
|
|
5
|
+
However if you want to build typeorm-model-generator you can do this by running:
|
|
6
|
+
```
|
|
7
|
+
npm run build
|
|
8
|
+
```
|
|
9
|
+
It might come handy if you want to build full pipeline workflow with model generator and install it through `npm link`.
|
|
10
|
+
## Running Tests Locally
|
|
11
|
+
To run tests you need to have docker and docker-compose installed. You may also use non-dockerized database servers but it's not recommended - they might use non-default database engine settings.
|
|
12
|
+
### Oracle Database
|
|
13
|
+
If you want to run oracle tests locally you must have [oracle client](https://oracle.github.io/node-oracledb/INSTALL.html#quickstart) configured for your machine and accepted oracle license on [DockerHub](https://hub.docker.com/_/oracle-database-enterprise-edition). Because of oracle client limitations i.e. it's not distributed for 32bit environments you have to install oracledb manually:
|
|
14
|
+
```
|
|
15
|
+
npm install oracledb --no-save
|
|
16
|
+
```
|
|
17
|
+
### Configuration
|
|
18
|
+
Tests use environment values to provide credentials for connecting to multiple database engines. For developer convenience there is prepared env file with default connection settings(for connecting to dockerized db engines). After cloning the repo you just need to rename the env file:
|
|
19
|
+
```
|
|
20
|
+
cp .env.dist .env
|
|
21
|
+
```
|
|
22
|
+
### Database engines
|
|
23
|
+
Next you have to start db engines. If you want to test all of the drivers and have configured oracle correctly you can just:
|
|
24
|
+
```
|
|
25
|
+
docker-compose up -d
|
|
26
|
+
```
|
|
27
|
+
You can also start just specific database engines e.g.:
|
|
28
|
+
```
|
|
29
|
+
docker-compose up -d mysql postgres mariadb
|
|
30
|
+
```
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Kononnable
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# midway-model-generator
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/midway-model-generator)
|
|
4
|
+
[](https://codecov.io/gh/Kononnable/midway-model-generator)
|
|
5
|
+
|
|
6
|
+
***
|
|
7
|
+
## :warning: This project is in a maintenance phase. See [#329](https://github.com/Kononnable/midway-model-generator/issues/329) for details.
|
|
8
|
+
***
|
|
9
|
+
Generates models for TypeORM from existing databases.
|
|
10
|
+
Supported db engines:
|
|
11
|
+
* Microsoft SQL Server
|
|
12
|
+
* PostgreSQL
|
|
13
|
+
* MySQL
|
|
14
|
+
* MariaDB
|
|
15
|
+
* Oracle Database
|
|
16
|
+
* SQLite
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
### Versions
|
|
21
|
+
midway-model-generator comes with preinstalled driver for each supported db(except for oracle). However if you want to use it as a dev-dependency you may want to install your db driver manually to reduce dependency footprint, reduce time spent in the CI. In such case you can use version without preinstalled db drivers - `npm i midway-model-generator@no-engines`.
|
|
22
|
+
### Global module
|
|
23
|
+
To install module globally simply type `npm i -g midway-model-generator` in your console.
|
|
24
|
+
### Npx way
|
|
25
|
+
Thanks to npx you can use npm modules without polluting global installs. So nothing to do here :)
|
|
26
|
+
>To use `npx` you need to use npm at version at least 5.2.0. Try updating your npm by `npm i -g npm`
|
|
27
|
+
### Database drivers
|
|
28
|
+
All database drivers except oracle are installed by default. To use midway-model-generator with oracle database you need to install driver with `npm i oracledb` and configure [oracle install client](http://www.oracle.com/technetwork/database/database-technologies/instant-client/overview/index.html) on your machine.
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
There are two way to use this utility:
|
|
32
|
+
- Use step by step wizard which will guide you though the process - just type `npx midway-model-generator` in your console.
|
|
33
|
+
- Provide all parameters through command line(examples below)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
Use `npx midway-model-generator --help` to see all available parameters with their descriptions. Some basic parameters below:
|
|
37
|
+
```shell
|
|
38
|
+
Usage: midway-model-generator -h <host> -d <database> -p [port] -u <user> -x
|
|
39
|
+
[password] -e [engine]
|
|
40
|
+
|
|
41
|
+
Options:
|
|
42
|
+
--help Show help [boolean]
|
|
43
|
+
--version Show version number [boolean]
|
|
44
|
+
-h, --host IP address/Hostname for database server
|
|
45
|
+
[default: "127.0.0.1"]
|
|
46
|
+
-d, --database Database name(or path for sqlite) [required]
|
|
47
|
+
-u, --user Username for database server
|
|
48
|
+
-x, --pass Password for database server [default: ""]
|
|
49
|
+
-p, --port Port number for database server
|
|
50
|
+
-e, --engine Database engine
|
|
51
|
+
[choices: "mssql", "postgres", "mysql", "mariadb", "oracle", "sqlite"]
|
|
52
|
+
[default: "mssql"]
|
|
53
|
+
-o, --output Where to place generated models
|
|
54
|
+
[default: "./output"]
|
|
55
|
+
-s, --schema Schema name to create model from. Only for mssql
|
|
56
|
+
and postgres. You can pass multiple values
|
|
57
|
+
separated by comma eg. -s scheme1,scheme2,scheme3
|
|
58
|
+
--ssl [boolean] [default: false]
|
|
59
|
+
```
|
|
60
|
+
### Examples
|
|
61
|
+
|
|
62
|
+
* Creating model from local MSSQL database
|
|
63
|
+
* Global module
|
|
64
|
+
```
|
|
65
|
+
midway-model-generator -h localhost -d tempdb -u sa -x !Passw0rd -e mssql -o .
|
|
66
|
+
````
|
|
67
|
+
* Npx Way
|
|
68
|
+
```
|
|
69
|
+
npx midway-model-generator -h localhost -d tempdb -u sa -x !Passw0rd -e mssql -o .
|
|
70
|
+
````
|
|
71
|
+
* Creating model from local Postgres database, public schema with ssl connection
|
|
72
|
+
* Global module
|
|
73
|
+
```
|
|
74
|
+
midway-model-generator -h localhost -d postgres -u postgres -x !Passw0rd -e postgres -o . -s public --ssl
|
|
75
|
+
````
|
|
76
|
+
* Npx Way
|
|
77
|
+
```
|
|
78
|
+
npx midway-model-generator -h localhost -d postgres -u postgres -x !Passw0rd -e postgres -o . -s public --ssl
|
|
79
|
+
````
|
|
80
|
+
* Creating model from SQLite database
|
|
81
|
+
* Global module
|
|
82
|
+
```
|
|
83
|
+
midway-model-generator -d "Z:\sqlite.db" -e sqlite -o .
|
|
84
|
+
````
|
|
85
|
+
* Npx Way
|
|
86
|
+
```
|
|
87
|
+
npx midway-model-generator -d "Z:\sqlite.db" -e sqlite -o .
|
|
88
|
+
````
|
|
89
|
+
## Use Cases
|
|
90
|
+
Please take a look at [few workflows](USECASES.md) which might help you with deciding how you're gonna use midway-model-generator.
|
|
91
|
+
## Naming strategy
|
|
92
|
+
If you want to generate custom names for properties in generated entities you need to use custom naming strategy. You need to create your own version of [NamingStrategy](https://github.com/Kononnable/midway-model-generator/blob/master/src/NamingStrategy.ts) and pass it as command parameter.
|
|
93
|
+
|
|
94
|
+
```midway-model-generator -d typeorm_mg --namingStrategy=./NamingStrategy -e sqlite -db /tmp/sqliteto.db```
|
package/USECASES.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Common use cases
|
|
2
|
+
Typeorm-model-generator can be used in multiple workflows. Here are described few recommended ones.
|
|
3
|
+
## Use directly from npm
|
|
4
|
+
You can use typeorm-model-generator directly from npm:
|
|
5
|
+
```
|
|
6
|
+
npx typeorm-model-generator
|
|
7
|
+
```
|
|
8
|
+
Please remember that by using `npx typeorm-model-generator` you will download latest available version. To avoid it you can specify version each time `npx typeorm-model-generator@0.3.0` or install a package locally - npx will use locally installed version then.
|
|
9
|
+
### command line parameters
|
|
10
|
+
You can customize generated output by specifying multiple parameters. Full list of parameters are available through `npx typeorm-model-generator --help`
|
|
11
|
+
### config file
|
|
12
|
+
If you execute `npx typeorm-model-generator` without specifying any parameters you will enter a wizard mode which will guide you through specifying connection settings and allow to customize generated models. At the end of this process you will be able to save your settings, so the process will run automatically next time.
|
|
13
|
+
## clone repo and make manual changes
|
|
14
|
+
If you need more power over how models are generated you can fork the repo and make changes to the code which are specific to your use case.
|
|
15
|
+
- fork the repo
|
|
16
|
+
- clone forked repo locally
|
|
17
|
+
- create branch for your changes:
|
|
18
|
+
```
|
|
19
|
+
git checkout -b my-branch master
|
|
20
|
+
```
|
|
21
|
+
- add remote repository:
|
|
22
|
+
```
|
|
23
|
+
git remote add upstream https://github.com/Kononnable/typeorm-model-generator.git
|
|
24
|
+
```
|
|
25
|
+
You can run model generation tool by running `npm run start` after installing dependencies.
|
|
26
|
+
|
|
27
|
+
When you want to download changes made on main typeorm-model-generator repo just
|
|
28
|
+
- checkout `master` branch
|
|
29
|
+
- download changes from main repository:
|
|
30
|
+
```
|
|
31
|
+
git pull --ff upstream master
|
|
32
|
+
```
|
|
33
|
+
- checkout branch with your changes:
|
|
34
|
+
```
|
|
35
|
+
git checkout my-branch
|
|
36
|
+
```
|
|
37
|
+
- merge changes onto your branch:
|
|
38
|
+
```
|
|
39
|
+
git merge master
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## git repo with dependency and entire pipeline
|
|
43
|
+
Similar to previous workflow, but this time we don't have to worry about manually merging changes from main repository.
|
|
44
|
+
- Init new package:
|
|
45
|
+
```
|
|
46
|
+
npm init -y
|
|
47
|
+
```
|
|
48
|
+
- Install typeorm-model-generator as a dependency:
|
|
49
|
+
```
|
|
50
|
+
npm install typeorm-model-generator
|
|
51
|
+
```
|
|
52
|
+
- Write code which loads generated entity files and change its content
|
|
53
|
+
- Run typeorm-model-generator, then your code which customizes it (you may add this step to `package.json` scripts section)
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "midway-model-gen",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Generates models for TypeORM from existing databases.",
|
|
5
|
+
"bin": "bin/typeorm-model-generator",
|
|
6
|
+
"main": "./dist/src/library.js",
|
|
7
|
+
"types": "./dist/src/library.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"start": "ts-node ./src/index.ts",
|
|
10
|
+
"build": "npm run clean && tsc && ncp src/templates/ dist/src/templates/ && ncp package.json dist/package.json",
|
|
11
|
+
"prepare": "npm run build",
|
|
12
|
+
"pretest": "tsc --noEmit",
|
|
13
|
+
"test": "nyc --reporter=lcov ts-node ./node_modules/mocha/bin/_mocha test/**/*.test.ts --config test/configs/mocha.json -- --bail",
|
|
14
|
+
"posttest": "eslint ./src/**/*.ts ./test/**/*.ts",
|
|
15
|
+
"clean": "rimraf coverage output dist",
|
|
16
|
+
"prettier": "prettier --write ./src/*.ts ./src/**/*.ts"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/Kononnable/typeorm-model-generator.git"
|
|
21
|
+
},
|
|
22
|
+
"author": "Kononnable",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/Kononnable/typeorm-model-generator/issues"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/Kononnable/typeorm-model-generator#readme",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"change-case": "^4.1.2",
|
|
30
|
+
"fs-extra": "^9.1.0",
|
|
31
|
+
"handlebars": "^4.7.7",
|
|
32
|
+
"inquirer": "^7.3.3",
|
|
33
|
+
"mssql": "^6.3.2",
|
|
34
|
+
"mysql2": "^2.3.0",
|
|
35
|
+
"pg": "^8.7.1",
|
|
36
|
+
"pluralize": "^8.0.0",
|
|
37
|
+
"prettier": "^2.3.2",
|
|
38
|
+
"reflect-metadata": "^0.1.13",
|
|
39
|
+
"sqlite3": "^5.0.2",
|
|
40
|
+
"typeorm": "^0.2.37",
|
|
41
|
+
"yargs": "^16.2.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/array.prototype.flatmap": "^1.2.2",
|
|
45
|
+
"@types/chai": "^4.2.21",
|
|
46
|
+
"@types/chai-as-promised": "^7.1.4",
|
|
47
|
+
"@types/chai-subset": "^1.3.3",
|
|
48
|
+
"@types/eslint": "^7.28.0",
|
|
49
|
+
"@types/fs-extra": "^9.0.12",
|
|
50
|
+
"@types/handlebars": "^4.1.0",
|
|
51
|
+
"@types/inquirer": "^7.3.3",
|
|
52
|
+
"@types/mocha": "^8.2.3",
|
|
53
|
+
"@types/mssql": "^6.0.8",
|
|
54
|
+
"@types/mysql": "^2.15.19",
|
|
55
|
+
"@types/node": "^14.17.15",
|
|
56
|
+
"@types/oracledb": "^5.2.1",
|
|
57
|
+
"@types/pg": "^7.14.11",
|
|
58
|
+
"@types/pluralize": "0.0.29",
|
|
59
|
+
"@types/prettier": "^2.3.2",
|
|
60
|
+
"@types/sinon": "^9.0.11",
|
|
61
|
+
"@types/sqlite3": "^3.1.7",
|
|
62
|
+
"@types/yargs": "^15.0.14",
|
|
63
|
+
"@typescript-eslint/eslint-plugin": "^3.7.1",
|
|
64
|
+
"@typescript-eslint/parser": "^3.7.1",
|
|
65
|
+
"@typescript-eslint/typescript-estree": "^3.7.1",
|
|
66
|
+
"array.prototype.flatmap": "^1.2.4",
|
|
67
|
+
"chai": "^4.3.4",
|
|
68
|
+
"chai-as-promised": "^7.1.1",
|
|
69
|
+
"chai-subset": "^1.6.0",
|
|
70
|
+
"codecov": "^3.8.3",
|
|
71
|
+
"dotenv": "^8.6.0",
|
|
72
|
+
"eslint": "^7.32.0",
|
|
73
|
+
"eslint-config-airbnb-base": "^14.2.1",
|
|
74
|
+
"eslint-config-prettier": "^6.15.0",
|
|
75
|
+
"eslint-plugin-import": "^2.24.2",
|
|
76
|
+
"husky": "^4.3.8",
|
|
77
|
+
"lint-staged": "^10.5.4",
|
|
78
|
+
"mocha": "^8.4.0",
|
|
79
|
+
"ncp": "^2.0.0",
|
|
80
|
+
"nyc": "^15.1.0",
|
|
81
|
+
"rimraf": "^3.0.2",
|
|
82
|
+
"sinon": "^9.2.4",
|
|
83
|
+
"sinon-chai": "^3.7.0",
|
|
84
|
+
"ts-node": "^9.1.1",
|
|
85
|
+
"typescript": "^4.4.2",
|
|
86
|
+
"yn": "^4.0.0"
|
|
87
|
+
},
|
|
88
|
+
"husky": {
|
|
89
|
+
"hooks": {
|
|
90
|
+
"pre-commit": "npm run prettier && git update-index --again"
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"nyc": {
|
|
94
|
+
"check-coverage": false,
|
|
95
|
+
"all": true,
|
|
96
|
+
"extension": [
|
|
97
|
+
".ts",
|
|
98
|
+
".tsx"
|
|
99
|
+
],
|
|
100
|
+
"lines": "50",
|
|
101
|
+
"include": [
|
|
102
|
+
"src/**/!(*.test.*).[tj]s?(x)"
|
|
103
|
+
]
|
|
104
|
+
},
|
|
105
|
+
"__npminstall_done": false
|
|
106
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import AbstractDriver from "./drivers/AbstractDriver";
|
|
2
|
+
import IConnectionOptions from "./IConnectionOptions";
|
|
3
|
+
import IGenerationOptions from "./IGenerationOptions";
|
|
4
|
+
import { Entity } from "./models/Entity";
|
|
5
|
+
export declare function createDriver(driverName: string): AbstractDriver;
|
|
6
|
+
export declare function createModelFromDatabase(driver: AbstractDriver, connectionOptions: IConnectionOptions, generationOptions: IGenerationOptions): Promise<void>;
|
|
7
|
+
export declare function dataCollectionPhase(driver: AbstractDriver, connectionOptions: IConnectionOptions, generationOptions: IGenerationOptions): Promise<Entity[]>;
|