uranio 1.0.8 → 1.1.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/.uranio/package-lock.json +193 -14
- package/.uranio/package.json +3 -1
- package/.uranio/src/atom/postgresql.ts +109 -0
- package/.uranio/src/client/postgresql.ts +108 -0
- package/.uranio/src/client.ts +8 -0
- package/.uranio/src/index.ts +3 -0
- package/.uranio/src/types/atom.ts +3 -0
- package/README.md +37 -1
- package/dist/cli/generate/index.js +191 -48
- package/dist/cli/generate/index.js.map +1 -1
- package/dist/cli/init/index.d.ts +1 -1
- package/dist/cli/init/index.js +1 -1
- package/dist/cli/types.d.ts +1 -0
- package/dist/cli/types.js +1 -0
- package/dist/cli/types.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/generate/index.ts +267 -79
- package/src/cli/init/index.ts +1 -1
- package/src/cli/types.ts +1 -0
|
@@ -10,10 +10,12 @@
|
|
|
10
10
|
"@aws-sdk/util-dynamodb": "^3.995.0",
|
|
11
11
|
"mongodb": "^7.1.0",
|
|
12
12
|
"mysql2": "^3.17.5",
|
|
13
|
-
"
|
|
13
|
+
"pg": "^8.18.0",
|
|
14
|
+
"uranio": "1.0.8"
|
|
14
15
|
},
|
|
15
16
|
"devDependencies": {
|
|
16
17
|
"@types/node": "^25.3.0",
|
|
18
|
+
"@types/pg": "^8.16.0",
|
|
17
19
|
"dotenv": "^16.3.1",
|
|
18
20
|
"eslint": "^10.0.1",
|
|
19
21
|
"eslint-config-prettier": "^10.1.8",
|
|
@@ -2355,6 +2357,18 @@
|
|
|
2355
2357
|
"undici-types": "~7.18.0"
|
|
2356
2358
|
}
|
|
2357
2359
|
},
|
|
2360
|
+
"node_modules/@types/pg": {
|
|
2361
|
+
"version": "8.16.0",
|
|
2362
|
+
"resolved": "https://registry.npmjs.org/@types/pg/-/pg-8.16.0.tgz",
|
|
2363
|
+
"integrity": "sha512-RmhMd/wD+CF8Dfo+cVIy3RR5cl8CyfXQ0tGgW6XBL8L4LM/UTEbNXYRbLwU6w+CgrKBNbrQWt4FUtTfaU5jSYQ==",
|
|
2364
|
+
"dev": true,
|
|
2365
|
+
"license": "MIT",
|
|
2366
|
+
"dependencies": {
|
|
2367
|
+
"@types/node": "*",
|
|
2368
|
+
"pg-protocol": "*",
|
|
2369
|
+
"pg-types": "^2.2.0"
|
|
2370
|
+
}
|
|
2371
|
+
},
|
|
2358
2372
|
"node_modules/@types/webidl-conversions": {
|
|
2359
2373
|
"version": "7.0.3",
|
|
2360
2374
|
"resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz",
|
|
@@ -2435,15 +2449,6 @@
|
|
|
2435
2449
|
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
|
|
2436
2450
|
}
|
|
2437
2451
|
},
|
|
2438
|
-
"node_modules/app-root-path": {
|
|
2439
|
-
"version": "3.1.0",
|
|
2440
|
-
"resolved": "https://registry.npmjs.org/app-root-path/-/app-root-path-3.1.0.tgz",
|
|
2441
|
-
"integrity": "sha512-biN3PwB2gUtjaYy/isrU3aNWI5w+fAfvHkSvCKeQGxhmYpwKFUxudR3Yya+KqVRHBmEDYh+/lTozYCFbmzX4nA==",
|
|
2442
|
-
"license": "MIT",
|
|
2443
|
-
"engines": {
|
|
2444
|
-
"node": ">= 6.0.0"
|
|
2445
|
-
}
|
|
2446
|
-
},
|
|
2447
2452
|
"node_modules/aws-ssl-profiles": {
|
|
2448
2453
|
"version": "1.1.2",
|
|
2449
2454
|
"resolved": "https://registry.npmjs.org/aws-ssl-profiles/-/aws-ssl-profiles-1.1.2.tgz",
|
|
@@ -3072,6 +3077,18 @@
|
|
|
3072
3077
|
"url": "https://github.com/sponsors/sindresorhus"
|
|
3073
3078
|
}
|
|
3074
3079
|
},
|
|
3080
|
+
"node_modules/find-up-simple": {
|
|
3081
|
+
"version": "1.0.1",
|
|
3082
|
+
"resolved": "https://registry.npmjs.org/find-up-simple/-/find-up-simple-1.0.1.tgz",
|
|
3083
|
+
"integrity": "sha512-afd4O7zpqHeRyg4PfDQsXmlDe2PfdHtJt6Akt8jOWaApLOZk5JXs6VMR29lz03pRe9mpykrRCYIYxaJYcfpncQ==",
|
|
3084
|
+
"license": "MIT",
|
|
3085
|
+
"engines": {
|
|
3086
|
+
"node": ">=18"
|
|
3087
|
+
},
|
|
3088
|
+
"funding": {
|
|
3089
|
+
"url": "https://github.com/sponsors/sindresorhus"
|
|
3090
|
+
}
|
|
3091
|
+
},
|
|
3075
3092
|
"node_modules/flat-cache": {
|
|
3076
3093
|
"version": "4.0.1",
|
|
3077
3094
|
"resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-4.0.1.tgz",
|
|
@@ -3725,6 +3742,111 @@
|
|
|
3725
3742
|
"through": "~2.3"
|
|
3726
3743
|
}
|
|
3727
3744
|
},
|
|
3745
|
+
"node_modules/pg": {
|
|
3746
|
+
"version": "8.18.0",
|
|
3747
|
+
"resolved": "https://registry.npmjs.org/pg/-/pg-8.18.0.tgz",
|
|
3748
|
+
"integrity": "sha512-xqrUDL1b9MbkydY/s+VZ6v+xiMUmOUk7SS9d/1kpyQxoJ6U9AO1oIJyUWVZojbfe5Cc/oluutcgFG4L9RDP1iQ==",
|
|
3749
|
+
"license": "MIT",
|
|
3750
|
+
"peer": true,
|
|
3751
|
+
"dependencies": {
|
|
3752
|
+
"pg-connection-string": "^2.11.0",
|
|
3753
|
+
"pg-pool": "^3.11.0",
|
|
3754
|
+
"pg-protocol": "^1.11.0",
|
|
3755
|
+
"pg-types": "2.2.0",
|
|
3756
|
+
"pgpass": "1.0.5"
|
|
3757
|
+
},
|
|
3758
|
+
"engines": {
|
|
3759
|
+
"node": ">= 16.0.0"
|
|
3760
|
+
},
|
|
3761
|
+
"optionalDependencies": {
|
|
3762
|
+
"pg-cloudflare": "^1.3.0"
|
|
3763
|
+
},
|
|
3764
|
+
"peerDependencies": {
|
|
3765
|
+
"pg-native": ">=3.0.1"
|
|
3766
|
+
},
|
|
3767
|
+
"peerDependenciesMeta": {
|
|
3768
|
+
"pg-native": {
|
|
3769
|
+
"optional": true
|
|
3770
|
+
}
|
|
3771
|
+
}
|
|
3772
|
+
},
|
|
3773
|
+
"node_modules/pg-cloudflare": {
|
|
3774
|
+
"version": "1.3.0",
|
|
3775
|
+
"resolved": "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.3.0.tgz",
|
|
3776
|
+
"integrity": "sha512-6lswVVSztmHiRtD6I8hw4qP/nDm1EJbKMRhf3HCYaqud7frGysPv7FYJ5noZQdhQtN2xJnimfMtvQq21pdbzyQ==",
|
|
3777
|
+
"license": "MIT",
|
|
3778
|
+
"optional": true
|
|
3779
|
+
},
|
|
3780
|
+
"node_modules/pg-connection-string": {
|
|
3781
|
+
"version": "2.11.0",
|
|
3782
|
+
"resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.11.0.tgz",
|
|
3783
|
+
"integrity": "sha512-kecgoJwhOpxYU21rZjULrmrBJ698U2RxXofKVzOn5UDj61BPj/qMb7diYUR1nLScCDbrztQFl1TaQZT0t1EtzQ==",
|
|
3784
|
+
"license": "MIT"
|
|
3785
|
+
},
|
|
3786
|
+
"node_modules/pg-int8": {
|
|
3787
|
+
"version": "1.0.1",
|
|
3788
|
+
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
|
|
3789
|
+
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==",
|
|
3790
|
+
"license": "ISC",
|
|
3791
|
+
"engines": {
|
|
3792
|
+
"node": ">=4.0.0"
|
|
3793
|
+
}
|
|
3794
|
+
},
|
|
3795
|
+
"node_modules/pg-pool": {
|
|
3796
|
+
"version": "3.11.0",
|
|
3797
|
+
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.11.0.tgz",
|
|
3798
|
+
"integrity": "sha512-MJYfvHwtGp870aeusDh+hg9apvOe2zmpZJpyt+BMtzUWlVqbhFmMK6bOBXLBUPd7iRtIF9fZplDc7KrPN3PN7w==",
|
|
3799
|
+
"license": "MIT",
|
|
3800
|
+
"peerDependencies": {
|
|
3801
|
+
"pg": ">=8.0"
|
|
3802
|
+
}
|
|
3803
|
+
},
|
|
3804
|
+
"node_modules/pg-protocol": {
|
|
3805
|
+
"version": "1.11.0",
|
|
3806
|
+
"resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.11.0.tgz",
|
|
3807
|
+
"integrity": "sha512-pfsxk2M9M3BuGgDOfuy37VNRRX3jmKgMjcvAcWqNDpZSf4cUmv8HSOl5ViRQFsfARFn0KuUQTgLxVMbNq5NW3g==",
|
|
3808
|
+
"license": "MIT"
|
|
3809
|
+
},
|
|
3810
|
+
"node_modules/pg-types": {
|
|
3811
|
+
"version": "2.2.0",
|
|
3812
|
+
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz",
|
|
3813
|
+
"integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==",
|
|
3814
|
+
"license": "MIT",
|
|
3815
|
+
"dependencies": {
|
|
3816
|
+
"pg-int8": "1.0.1",
|
|
3817
|
+
"postgres-array": "~2.0.0",
|
|
3818
|
+
"postgres-bytea": "~1.0.0",
|
|
3819
|
+
"postgres-date": "~1.0.4",
|
|
3820
|
+
"postgres-interval": "^1.1.0"
|
|
3821
|
+
},
|
|
3822
|
+
"engines": {
|
|
3823
|
+
"node": ">=4"
|
|
3824
|
+
}
|
|
3825
|
+
},
|
|
3826
|
+
"node_modules/pgpass": {
|
|
3827
|
+
"version": "1.0.5",
|
|
3828
|
+
"resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz",
|
|
3829
|
+
"integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==",
|
|
3830
|
+
"license": "MIT",
|
|
3831
|
+
"dependencies": {
|
|
3832
|
+
"split2": "^4.1.0"
|
|
3833
|
+
}
|
|
3834
|
+
},
|
|
3835
|
+
"node_modules/pkg-dir": {
|
|
3836
|
+
"version": "8.0.0",
|
|
3837
|
+
"resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-8.0.0.tgz",
|
|
3838
|
+
"integrity": "sha512-4peoBq4Wks0riS0z8741NVv+/8IiTvqnZAr8QGgtdifrtpdXbNw/FxRS1l6NFqm4EMzuS0EDqNNx4XGaz8cuyQ==",
|
|
3839
|
+
"license": "MIT",
|
|
3840
|
+
"dependencies": {
|
|
3841
|
+
"find-up-simple": "^1.0.0"
|
|
3842
|
+
},
|
|
3843
|
+
"engines": {
|
|
3844
|
+
"node": ">=18"
|
|
3845
|
+
},
|
|
3846
|
+
"funding": {
|
|
3847
|
+
"url": "https://github.com/sponsors/sindresorhus"
|
|
3848
|
+
}
|
|
3849
|
+
},
|
|
3728
3850
|
"node_modules/plutonio": {
|
|
3729
3851
|
"version": "0.7.7",
|
|
3730
3852
|
"resolved": "https://registry.npmjs.org/plutonio/-/plutonio-0.7.7.tgz",
|
|
@@ -3735,6 +3857,45 @@
|
|
|
3735
3857
|
"typescript": "^5.9.3"
|
|
3736
3858
|
}
|
|
3737
3859
|
},
|
|
3860
|
+
"node_modules/postgres-array": {
|
|
3861
|
+
"version": "2.0.0",
|
|
3862
|
+
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz",
|
|
3863
|
+
"integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==",
|
|
3864
|
+
"license": "MIT",
|
|
3865
|
+
"engines": {
|
|
3866
|
+
"node": ">=4"
|
|
3867
|
+
}
|
|
3868
|
+
},
|
|
3869
|
+
"node_modules/postgres-bytea": {
|
|
3870
|
+
"version": "1.0.1",
|
|
3871
|
+
"resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.1.tgz",
|
|
3872
|
+
"integrity": "sha512-5+5HqXnsZPE65IJZSMkZtURARZelel2oXUEO8rH83VS/hxH5vv1uHquPg5wZs8yMAfdv971IU+kcPUczi7NVBQ==",
|
|
3873
|
+
"license": "MIT",
|
|
3874
|
+
"engines": {
|
|
3875
|
+
"node": ">=0.10.0"
|
|
3876
|
+
}
|
|
3877
|
+
},
|
|
3878
|
+
"node_modules/postgres-date": {
|
|
3879
|
+
"version": "1.0.7",
|
|
3880
|
+
"resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz",
|
|
3881
|
+
"integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==",
|
|
3882
|
+
"license": "MIT",
|
|
3883
|
+
"engines": {
|
|
3884
|
+
"node": ">=0.10.0"
|
|
3885
|
+
}
|
|
3886
|
+
},
|
|
3887
|
+
"node_modules/postgres-interval": {
|
|
3888
|
+
"version": "1.2.0",
|
|
3889
|
+
"resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz",
|
|
3890
|
+
"integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==",
|
|
3891
|
+
"license": "MIT",
|
|
3892
|
+
"dependencies": {
|
|
3893
|
+
"xtend": "^4.0.0"
|
|
3894
|
+
},
|
|
3895
|
+
"engines": {
|
|
3896
|
+
"node": ">=0.10.0"
|
|
3897
|
+
}
|
|
3898
|
+
},
|
|
3738
3899
|
"node_modules/prelude-ls": {
|
|
3739
3900
|
"version": "1.2.1",
|
|
3740
3901
|
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz",
|
|
@@ -3967,6 +4128,15 @@
|
|
|
3967
4128
|
"node": "*"
|
|
3968
4129
|
}
|
|
3969
4130
|
},
|
|
4131
|
+
"node_modules/split2": {
|
|
4132
|
+
"version": "4.2.0",
|
|
4133
|
+
"resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz",
|
|
4134
|
+
"integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==",
|
|
4135
|
+
"license": "ISC",
|
|
4136
|
+
"engines": {
|
|
4137
|
+
"node": ">= 10.x"
|
|
4138
|
+
}
|
|
4139
|
+
},
|
|
3970
4140
|
"node_modules/sql-escaper": {
|
|
3971
4141
|
"version": "1.3.3",
|
|
3972
4142
|
"resolved": "https://registry.npmjs.org/sql-escaper/-/sql-escaper-1.3.3.tgz",
|
|
@@ -4148,14 +4318,14 @@
|
|
|
4148
4318
|
"license": "MIT"
|
|
4149
4319
|
},
|
|
4150
4320
|
"node_modules/uranio": {
|
|
4151
|
-
"version": "1.0.
|
|
4152
|
-
"resolved": "https://registry.npmjs.org/uranio/-/uranio-1.0.
|
|
4153
|
-
"integrity": "sha512-
|
|
4321
|
+
"version": "1.0.8",
|
|
4322
|
+
"resolved": "https://registry.npmjs.org/uranio/-/uranio-1.0.8.tgz",
|
|
4323
|
+
"integrity": "sha512-S6kU0AEensbEO5Zn+cFS8lDwdD8f+r7Z5kKmDBLr2zV9kf3o+e+haQugIlVnlQsyJD41Zx6CEUFpkJg4v1vJ7g==",
|
|
4154
4324
|
"license": "UNLICENSED",
|
|
4155
4325
|
"dependencies": {
|
|
4156
|
-
"app-root-path": "^3.1.0",
|
|
4157
4326
|
"i0n": "^0.9.0",
|
|
4158
4327
|
"inquirer": "^13.3.0",
|
|
4328
|
+
"pkg-dir": "^8.0.0",
|
|
4159
4329
|
"plutonio": "^0.7.7",
|
|
4160
4330
|
"r4y": "^0.9.0",
|
|
4161
4331
|
"yaml": "^2.8.2"
|
|
@@ -4305,6 +4475,15 @@
|
|
|
4305
4475
|
"node": ">=0.10.0"
|
|
4306
4476
|
}
|
|
4307
4477
|
},
|
|
4478
|
+
"node_modules/xtend": {
|
|
4479
|
+
"version": "4.0.2",
|
|
4480
|
+
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
|
|
4481
|
+
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==",
|
|
4482
|
+
"license": "MIT",
|
|
4483
|
+
"engines": {
|
|
4484
|
+
"node": ">=0.4"
|
|
4485
|
+
}
|
|
4486
|
+
},
|
|
4308
4487
|
"node_modules/yaml": {
|
|
4309
4488
|
"version": "2.8.2",
|
|
4310
4489
|
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.8.2.tgz",
|
package/.uranio/package.json
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"@types/node": "^25.3.0",
|
|
14
|
+
"@types/pg": "^8.16.0",
|
|
14
15
|
"dotenv": "^16.3.1",
|
|
15
16
|
"eslint": "^10.0.1",
|
|
16
17
|
"eslint-config-prettier": "^10.1.8",
|
|
@@ -26,6 +27,7 @@
|
|
|
26
27
|
"@aws-sdk/util-dynamodb": "^3.995.0",
|
|
27
28
|
"mongodb": "^7.1.0",
|
|
28
29
|
"mysql2": "^3.17.5",
|
|
29
|
-
"
|
|
30
|
+
"pg": "^8.18.0",
|
|
31
|
+
"uranio": "1.1.1"
|
|
30
32
|
}
|
|
31
33
|
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* PostgreSQL Atom client module
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
import {PostgreSQLClient} from '../client/postgresql';
|
|
9
|
+
import * as sql from '../sql/index';
|
|
10
|
+
|
|
11
|
+
import * as atom_types from '../types/atom';
|
|
12
|
+
import * as where_types from '../types/where';
|
|
13
|
+
import * as sql_types from '../types/sql';
|
|
14
|
+
|
|
15
|
+
export class PostgreSQLAtomClient<S extends atom_types.postgresql_atom> {
|
|
16
|
+
|
|
17
|
+
constructor(
|
|
18
|
+
public client: PostgreSQLClient,
|
|
19
|
+
public name: string
|
|
20
|
+
) {}
|
|
21
|
+
|
|
22
|
+
public async getAtom(where: where_types.Where<S>): Promise<S | null> {
|
|
23
|
+
const {query, map} = sql.param.compose_select({
|
|
24
|
+
table: this.name,
|
|
25
|
+
where,
|
|
26
|
+
limit: '1',
|
|
27
|
+
});
|
|
28
|
+
const [rows] = await this.client.exe(query, map);
|
|
29
|
+
if (Array.isArray(rows) && rows[0]) {
|
|
30
|
+
return rows[0] as S;
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public async getAtoms({
|
|
36
|
+
where,
|
|
37
|
+
order,
|
|
38
|
+
limit,
|
|
39
|
+
}: {
|
|
40
|
+
where?: where_types.Where<S>;
|
|
41
|
+
order?: sql_types.OrderBy;
|
|
42
|
+
limit?: string;
|
|
43
|
+
}): Promise<S[]> {
|
|
44
|
+
const {query, map} = sql.param.compose_select({
|
|
45
|
+
table: this.name,
|
|
46
|
+
where,
|
|
47
|
+
order,
|
|
48
|
+
limit,
|
|
49
|
+
});
|
|
50
|
+
const [rows] = await this.client.exe(query, map);
|
|
51
|
+
if (Array.isArray(rows)) {
|
|
52
|
+
return rows as S[];
|
|
53
|
+
}
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public async putAtom(shape: Partial<S>): Promise<any> {
|
|
58
|
+
const columns:(keyof S)[] = [];
|
|
59
|
+
for(const [key, _] of Object.entries(shape)){
|
|
60
|
+
columns.push(key as keyof S);
|
|
61
|
+
}
|
|
62
|
+
const {query, query_records} = sql.param.compose_insert({
|
|
63
|
+
table: this.name,
|
|
64
|
+
columns,
|
|
65
|
+
records: [shape]
|
|
66
|
+
});
|
|
67
|
+
const response = await this.client.exe(query, query_records);
|
|
68
|
+
return response;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public async putAtoms(shapes: Partial<S>[]): Promise<any> {
|
|
72
|
+
const columns:(keyof S)[] = [];
|
|
73
|
+
if(!Array.isArray(shapes) || shapes.length < 1 || !shapes[0]){
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
for(const [key, _] of Object.entries(shapes[0])){
|
|
77
|
+
columns.push(key as keyof S);
|
|
78
|
+
}
|
|
79
|
+
const {query, query_records} = sql.param.compose_insert({
|
|
80
|
+
table: this.name,
|
|
81
|
+
columns,
|
|
82
|
+
records: shapes
|
|
83
|
+
});
|
|
84
|
+
const response = await this.client.exe(query, query_records);
|
|
85
|
+
return response;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public async updateAtoms(
|
|
89
|
+
atom: Partial<S>,
|
|
90
|
+
where?: where_types.Where<S>,
|
|
91
|
+
): Promise<any> {
|
|
92
|
+
const {query, map} = sql.param.compose_update({
|
|
93
|
+
table: this.name,
|
|
94
|
+
where,
|
|
95
|
+
update: atom
|
|
96
|
+
});
|
|
97
|
+
const response = await this.client.exe(query, map);
|
|
98
|
+
return response;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public async deleteAtoms(where: where_types.Where<S>): Promise<any> {
|
|
102
|
+
const {query, map} = sql.param.compose_delete({
|
|
103
|
+
table: this.name,
|
|
104
|
+
where,
|
|
105
|
+
});
|
|
106
|
+
const response = await this.client.exe(query, map);
|
|
107
|
+
return response;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* PostgreSQL Client module
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {Pool, PoolClient} from 'pg';
|
|
10
|
+
import {log} from '../log/index';
|
|
11
|
+
|
|
12
|
+
export type PostgreSQLClientParams = {
|
|
13
|
+
uri: string;
|
|
14
|
+
usePool?: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export class PostgreSQLClient {
|
|
18
|
+
public pool?: Pool;
|
|
19
|
+
public mainConnection: PoolClient | undefined;
|
|
20
|
+
protected uri: string;
|
|
21
|
+
constructor(params: PostgreSQLClientParams) {
|
|
22
|
+
this.uri = params.uri;
|
|
23
|
+
if (params.usePool === true) {
|
|
24
|
+
this.pool = new Pool({
|
|
25
|
+
connectionString: params.uri,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
public async exe(sql: string, values?: any) {
|
|
30
|
+
// Convert named parameters object to positional parameters array
|
|
31
|
+
const {query, paramValues} = this._convert_named_to_positional(sql, values);
|
|
32
|
+
const with_values =
|
|
33
|
+
typeof paramValues !== 'undefined' && paramValues.length > 0
|
|
34
|
+
? ` with values [${paramValues}]`
|
|
35
|
+
: '';
|
|
36
|
+
log.trace(`Excuting query '${query}'${with_values}`);
|
|
37
|
+
if (this.pool) {
|
|
38
|
+
return await this._execute_from_pool_connection(query, paramValues);
|
|
39
|
+
}
|
|
40
|
+
if (!this.mainConnection) {
|
|
41
|
+
await this.connect();
|
|
42
|
+
}
|
|
43
|
+
const result = await this.mainConnection!.query(query, paramValues);
|
|
44
|
+
return [result.rows, result.fields];
|
|
45
|
+
}
|
|
46
|
+
public async connect() {
|
|
47
|
+
log.trace(`Connecting to PostgreSQL database...`);
|
|
48
|
+
if (!this.pool) {
|
|
49
|
+
this.pool = new Pool({
|
|
50
|
+
connectionString: this.uri,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
this.mainConnection = await this.pool.connect();
|
|
54
|
+
log.debug(`Connected to PostgreSQL database`);
|
|
55
|
+
}
|
|
56
|
+
public async disconnect() {
|
|
57
|
+
log.trace(`Disconnecting from PostgreSQL database...`);
|
|
58
|
+
if (this.mainConnection) {
|
|
59
|
+
this.mainConnection.release();
|
|
60
|
+
this.mainConnection = undefined;
|
|
61
|
+
}
|
|
62
|
+
if (this.pool) {
|
|
63
|
+
await this.pool.end();
|
|
64
|
+
}
|
|
65
|
+
log.debug(`Disconnected from PostgreSQL database`);
|
|
66
|
+
}
|
|
67
|
+
private async _execute_from_pool_connection(sql: string, values?: any[]) {
|
|
68
|
+
if (!this.pool) {
|
|
69
|
+
throw new Error(`Pool was not initialized`);
|
|
70
|
+
}
|
|
71
|
+
log.trace(`Retrieving pool connection...`);
|
|
72
|
+
const pool_connection = await this.pool.connect();
|
|
73
|
+
log.trace(`Retrieved pool connection`);
|
|
74
|
+
const result = await pool_connection.query(sql, values);
|
|
75
|
+
log.trace(`Releasing pool connection...`);
|
|
76
|
+
pool_connection.release();
|
|
77
|
+
log.trace(`Released pool connection`);
|
|
78
|
+
return [result.rows, result.fields];
|
|
79
|
+
}
|
|
80
|
+
private _convert_named_to_positional(
|
|
81
|
+
sql: string,
|
|
82
|
+
namedParams?: Record<string, any>
|
|
83
|
+
): {query: string; paramValues: any[]} {
|
|
84
|
+
// Convert MySQL backticks to PostgreSQL double quotes
|
|
85
|
+
let convertedQuery = sql.replace(/`/g, '"');
|
|
86
|
+
|
|
87
|
+
if (!namedParams || Object.keys(namedParams).length === 0) {
|
|
88
|
+
return {query: convertedQuery, paramValues: []};
|
|
89
|
+
}
|
|
90
|
+
// Sort keys to ensure consistent ordering
|
|
91
|
+
const sortedKeys = Object.keys(namedParams).sort();
|
|
92
|
+
let paramIndex = 1;
|
|
93
|
+
const paramValues: any[] = [];
|
|
94
|
+
|
|
95
|
+
// Replace each :paramName with $1, $2, etc.
|
|
96
|
+
for (const key of sortedKeys) {
|
|
97
|
+
const namedParam = `:${key}`;
|
|
98
|
+
// Replace all occurrences of this named parameter
|
|
99
|
+
while (convertedQuery.includes(namedParam)) {
|
|
100
|
+
convertedQuery = convertedQuery.replace(namedParam, `$${paramIndex}`);
|
|
101
|
+
}
|
|
102
|
+
paramValues.push(namedParams[key]);
|
|
103
|
+
paramIndex++;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return {query: convertedQuery, paramValues};
|
|
107
|
+
}
|
|
108
|
+
}
|
package/.uranio/src/client.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import {MongoDBClient, MongoDBClientParams} from './client/mongodb';
|
|
10
10
|
import {MySQLClient, MySQLClientParams} from './client/mysql';
|
|
11
11
|
import {DynamoDBClient, DynamoDBClientParams} from './client/dynamodb';
|
|
12
|
+
import {PostgreSQLClient, PostgreSQLClientParams} from './client/postgresql';
|
|
12
13
|
|
|
13
14
|
export class UranioMongoDBClient extends MongoDBClient {
|
|
14
15
|
constructor(params: MongoDBClientParams) {
|
|
@@ -27,3 +28,10 @@ export class UranioDynamoDBClient extends DynamoDBClient {
|
|
|
27
28
|
super(params);
|
|
28
29
|
}
|
|
29
30
|
}
|
|
31
|
+
|
|
32
|
+
export class UranioPostgreSQLClient extends PostgreSQLClient {
|
|
33
|
+
constructor(params: PostgreSQLClientParams) {
|
|
34
|
+
super(params);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
package/.uranio/src/index.ts
CHANGED
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|

|
|
4
4
|
|
|
5
5
|
Uranio is the lightest Typescript Object Document Mapper (ODM) for MongoDB,
|
|
6
|
-
Object Relational Mapping (ORM) for MySQL, and DynamoDB.\
|
|
6
|
+
Object Relational Mapping (ORM) for MySQL and PostgreSQL, and DynamoDB.\
|
|
7
7
|
It creates a client for querying collections/tables in a database by just parsing
|
|
8
8
|
the types in a repository.
|
|
9
9
|
|
|
@@ -24,6 +24,12 @@ npm install uranio mongodb
|
|
|
24
24
|
npm install uranio mysql2
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
### For PostgreSQL users:
|
|
28
|
+
```bash
|
|
29
|
+
npm install uranio pg
|
|
30
|
+
npm install --save-dev @types/pg
|
|
31
|
+
```
|
|
32
|
+
|
|
27
33
|
### For DynamoDB users:
|
|
28
34
|
```bash
|
|
29
35
|
npm install uranio @aws-sdk/client-dynamodb @aws-sdk/util-dynamodb
|
|
@@ -36,6 +42,8 @@ Run:
|
|
|
36
42
|
uranio generate -d mongodb
|
|
37
43
|
// or
|
|
38
44
|
uranio generate -d mysql
|
|
45
|
+
// or
|
|
46
|
+
uranio generate -d postgresql
|
|
39
47
|
```
|
|
40
48
|
|
|
41
49
|
The above command search for all interfaces in your repository that extends
|
|
@@ -139,6 +147,29 @@ const urn = uranio.MySQLClient({
|
|
|
139
147
|
|
|
140
148
|
The timezone setting affects how JavaScript `Date` objects are converted when storing to and retrieving from the database. Using UTC (default) is recommended for consistency across different timezones.
|
|
141
149
|
|
|
150
|
+
### PostgreSQL Client Options
|
|
151
|
+
|
|
152
|
+
When creating a PostgreSQL client, you can configure additional options:
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
import uranio from 'uranio';
|
|
156
|
+
|
|
157
|
+
const uri = process.env.POSTGRESQL_DATABASE_URI || '';
|
|
158
|
+
|
|
159
|
+
// Default: no connection pool
|
|
160
|
+
const urn = uranio.PostgreSQLClient({ uri });
|
|
161
|
+
|
|
162
|
+
// With connection pool (recommended for production)
|
|
163
|
+
const urn = uranio.PostgreSQLClient({
|
|
164
|
+
uri,
|
|
165
|
+
usePool: true
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Connection Pool:**
|
|
170
|
+
- Connection pooling is recommended for production environments to manage database connections efficiently
|
|
171
|
+
- PostgreSQL handles timezones natively, so no timezone configuration is needed
|
|
172
|
+
|
|
142
173
|
## Troubleshooting
|
|
143
174
|
|
|
144
175
|
### Missing Database SDK Error
|
|
@@ -147,6 +178,7 @@ If you get an error like:
|
|
|
147
178
|
```
|
|
148
179
|
Error: Cannot find module 'mongodb'
|
|
149
180
|
Error: Cannot find module 'mysql2'
|
|
181
|
+
Error: Cannot find module 'pg'
|
|
150
182
|
Error: Cannot find module '@aws-sdk/client-dynamodb'
|
|
151
183
|
```
|
|
152
184
|
|
|
@@ -159,6 +191,10 @@ npm install mongodb
|
|
|
159
191
|
# For MySQL
|
|
160
192
|
npm install mysql2
|
|
161
193
|
|
|
194
|
+
# For PostgreSQL
|
|
195
|
+
npm install pg
|
|
196
|
+
npm install --save-dev @types/pg
|
|
197
|
+
|
|
162
198
|
# For DynamoDB
|
|
163
199
|
npm install @aws-sdk/client-dynamodb @aws-sdk/util-dynamodb
|
|
164
200
|
```
|