@andymic/pigeon 1.4.0 → 1.4.2
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/README.md +12 -1
- package/package.json +2 -2
- package/src/cli.js +1 -0
- package/src/index.js +18 -4
package/README.md
CHANGED
|
@@ -20,12 +20,15 @@ Install with [npm](https://www.npmjs.com):
|
|
|
20
20
|
--force overwrites already existing files
|
|
21
21
|
--output [path:String] output directory for the generated files.
|
|
22
22
|
--config [path:String] path to .pigeon.json config file.
|
|
23
|
+
--pgAdmin [path:String] path to the pgAdmin ERD file.
|
|
24
|
+
--offline (only with pgAdmin) does not contact the database
|
|
23
25
|
|
|
24
26
|
Examples
|
|
25
27
|
$ pigeon --init
|
|
26
28
|
$ pigeon --output C:/Users/User/Documents/Project
|
|
27
|
-
$ pigeon --output ./generatedFiles
|
|
29
|
+
$ pigeon --output ./generatedFiles --force
|
|
28
30
|
$ pigeon --config ./customPigeonConfig.json
|
|
31
|
+
$ pigeon --pgAdmin C:/Users/User/Documents/Project/ERD.json --offline
|
|
29
32
|
|
|
30
33
|
Exit Status
|
|
31
34
|
Pigeon returns the following codes:
|
|
@@ -48,6 +51,14 @@ const result = await runPigeon('output/directory', 'localhost', 5432, 'database'
|
|
|
48
51
|
console.log(result.message);
|
|
49
52
|
```
|
|
50
53
|
|
|
54
|
+
### pgAdmin ERD
|
|
55
|
+
|
|
56
|
+
Pigeon supports generating code from pgAdmin ERD files. To do that the necessary `--pgAdmin` flag needs to point to the
|
|
57
|
+
ERD file.
|
|
58
|
+
|
|
59
|
+
The `--offline` flag prevents any contact with the database. A side effect of that is that the enum labels cannot be
|
|
60
|
+
populated.
|
|
61
|
+
|
|
51
62
|
## Configuration
|
|
52
63
|
|
|
53
64
|
Pigeon requires a configuration file `.pigeon.json` to connect to your PostgreSQL database. You can generate this file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andymic/pigeon",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"author": "Andreas Michael <ateasm03@gmail.com>",
|
|
5
5
|
"description": "Pigeon is a TypeScript-based tool for generating TypeScript classes and methods from PostgreSQL database schemas.",
|
|
6
6
|
"keywords": [
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"pg": "^8.15.6",
|
|
36
36
|
"prompt-sync": "^4.2.0"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "04b72fd9eb0dde3a4005146b38d899b9655f0d83"
|
|
39
39
|
}
|
package/src/cli.js
CHANGED
|
@@ -103,6 +103,7 @@ export async function run(flags) {
|
|
|
103
103
|
const generationResult = runGeneration(flags.output, database, tableProcessing(tables), enums);
|
|
104
104
|
if (generationResult instanceof PigeonError)
|
|
105
105
|
return generationResult;
|
|
106
|
+
return;
|
|
106
107
|
}
|
|
107
108
|
if (flags.guided) {
|
|
108
109
|
const params = guided();
|
package/src/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { arrayMaker, consoleMessage, getCombinations, getType, nameBeautifier, q
|
|
|
2
2
|
import prompt from "prompt-sync";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import * as path from "node:path";
|
|
5
|
+
import { jsTypes } from "./maps.js";
|
|
5
6
|
export class PigeonError {
|
|
6
7
|
exitCode;
|
|
7
8
|
message;
|
|
@@ -395,15 +396,28 @@ function createClass(tableName, columns, primaryKey, foreignKeys) {
|
|
|
395
396
|
text += "\t */\n";
|
|
396
397
|
text += "\t" + column.column_name + ": " + dataType;
|
|
397
398
|
if (column.column_default !== null) {
|
|
398
|
-
|
|
399
|
+
let columnDefault = column.column_default.split("::")[0];
|
|
400
|
+
let type = column.column_default.split("::")[1];
|
|
401
|
+
if (!columnDefault.includes("nextval")) {
|
|
399
402
|
if (dataType === "Date") {
|
|
400
|
-
if (
|
|
403
|
+
if (columnDefault.toLowerCase() === "now()")
|
|
401
404
|
text += " = new Date()";
|
|
402
405
|
else
|
|
403
|
-
text += " = new Date(" +
|
|
406
|
+
text += " = new Date(" + columnDefault.replace(" ", "T") + ")";
|
|
404
407
|
}
|
|
405
408
|
else if (dataType === "number" || dataType === "boolean")
|
|
406
|
-
text += " = " +
|
|
409
|
+
text += " = " + columnDefault;
|
|
410
|
+
else if (type) {
|
|
411
|
+
if (jsTypes.get(type) === "string")
|
|
412
|
+
text += " = \"" + columnDefault + "\"";
|
|
413
|
+
else {
|
|
414
|
+
const jsType = jsTypes.get(type);
|
|
415
|
+
if (jsType)
|
|
416
|
+
text += " = " + columnDefault + " as " + jsType;
|
|
417
|
+
else
|
|
418
|
+
text += " = " + columnDefault + " as " + nameBeautifier(type).replaceAll(" ", "");
|
|
419
|
+
}
|
|
420
|
+
}
|
|
407
421
|
else
|
|
408
422
|
text += " = \"" + column.column_default + "\"";
|
|
409
423
|
}
|