db-crud-api 0.3.10 → 0.3.12

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/CHANGELOG.md CHANGED
@@ -1,47 +1,51 @@
1
- # Changelog
2
-
3
- ## v0.1.0 (2022-12-08)
4
-
5
- Initial release
6
- ## v0.1.1 (2023-01-01)
7
-
8
- Bug fix:
9
- - default server/database
10
- ## v0.1.4 (2024-02-24)
11
-
12
- Bug fix:
13
- - update mssql to 9.3.2
14
- - update uuid to 9.0.1
15
- ## v0.1.5 (2024-03-03)
16
-
17
- Bug fix:
18
- - deleteById function crash
19
- - new function return undefined
20
- ## v0.1.5 (2024-03-03)
21
- ## v0.1.6 (2024-03-03)
22
-
23
- Bug fix:
24
- - update function crash with date value
25
- ## v0.1.9 (2024-03-12)
26
-
27
- Added:
28
- - execute store procedure
29
- ## v0.2.0 (2024-04-02)
30
-
31
- Changes:
32
- - parameters position have been change for some api
33
- Added:
34
- - batch job that run multiple instructions
35
- ## v0.2.1 (2024-12-05)
36
-
37
- Refresh dependency
38
- ## v0.3.0 (2024-12-28)
39
-
40
- Changes:
41
- - execute api definition
42
- Added:
43
- - support for mySQL
44
- ## v0.3.1 (2025-01-01)
45
-
46
- Bug fix:
47
- - autoId flag not onored
1
+ # Changelog
2
+
3
+ ## v0.1.0 (2022-12-08)
4
+
5
+ Initial release
6
+ ## v0.1.1 (2023-01-01)
7
+
8
+ Bug fix:
9
+ - default server/database
10
+ ## v0.1.4 (2024-02-24)
11
+
12
+ Bug fix:
13
+ - update mssql to 9.3.2
14
+ - update uuid to 9.0.1
15
+ ## v0.1.5 (2024-03-03)
16
+
17
+ Bug fix:
18
+ - deleteById function crash
19
+ - new function return undefined
20
+ ## v0.1.5 (2024-03-03)
21
+ ## v0.1.6 (2024-03-03)
22
+
23
+ Bug fix:
24
+ - update function crash with date value
25
+ ## v0.1.9 (2024-03-12)
26
+
27
+ Added:
28
+ - execute store procedure
29
+ ## v0.2.0 (2024-04-02)
30
+
31
+ Changes:
32
+ - parameters position have been change for some api
33
+ Added:
34
+ - batch job that run multiple instructions
35
+ ## v0.2.1 (2024-12-05)
36
+
37
+ Refresh dependency
38
+ ## v0.3.0 (2024-12-28)
39
+
40
+ Changes:
41
+ - execute api definition
42
+ Added:
43
+ - support for mySQL
44
+ ## v0.3.1 (2025-01-01)
45
+
46
+ Bug fix:
47
+ - autoId flag not onored
48
+ ## v0.3.11 (2025-10-25)
49
+
50
+ Added:
51
+ - testConnection()
package/README.md CHANGED
@@ -1,98 +1,100 @@
1
- # db-crud-api 💡
2
- CRUD api for database tables.
3
-
4
- ## Installation
5
- npm install db-crud-api
6
-
7
- # Usage
8
- ```javascript
9
- import dbCrudApi from "db-crud-api";
10
- const apiFactory = dbCrudApi(mySchema);
11
-
12
- const mySchema = {
13
- servers: {
14
- server1: {
15
- realName: "server1.mydomain.com",
16
- type: "ms-sql",
17
- instance: "DEFAULT",
18
- user: "User1",
19
- password: "mypassword",
20
- options: {
21
- appName: "myAppName",
22
- ...
23
- },
24
- databases: {
25
- db1: {
26
- realName: "db_orders",
27
- tables: {
28
- table1: {
29
- realName: "tb_orders_head",
30
- idField: "Id",
31
- autoId: true,
32
- fields: {
33
- Id: { realName: "OrderId", type: "uuid", lengh: undefined, canBeNull: false, description: "Unique Id", defaultValue: undefined },
34
- CustomerId: { type: "string", lengh: undefined, canBeNull: false, description: "Customer Id", defaultValue: undefined },
35
- ...
36
- }
37
- },
38
- table2: {
39
- realName: "tb_orders_detail",
40
- idField: "Id",
41
- autoId: true,
42
- fields: {
43
- Id: { realName: "OrderId", type: "uuid", lengh: undefined, canBeNull: false, description: "Unique Id", defaultValue: undefined },
44
- OrderId: { type: "uuid", lengh: undefined, canBeNull: false, description: "Order Id", defaultValue: undefined },
45
- RowSeq: { type: "numeric", lengh: undefined, canBeNull: false, description: "Row sequence", defaultValue: undefined },
46
- ...
47
- }
48
- },
49
- ...
50
- }
51
- },
52
- ...
53
- }
54
- },
55
- ...
56
- }
57
- };
58
-
59
- const apiOrder = apiFactory.newROApi("server1.db1.table1"); // Read Only api
60
- const apiOrderDetail = apiFactory.newFullApi("table2"); // full CRUD api
61
- const apiExecuteSP = apiFactory.newExecuteApi("db1.my_storeproc"); // execute my_storeproc
62
-
63
- console.log(await apiOrder.getById("xxxxx-xxxxx-xxxxxxxxxxxx-xxxxxx"));
64
- console.log(await apiOrder.getById("xxxxx-xxxxx-xxxxxxxxxxxx-xxxxxx", {get: {fields: ["Id", "OrderNumber", "OrderTotal"]}}));
65
- console.log(await apiOrder.getByFilter({get: {filters: ["OrderType in ('P', 'A')", "and", "OrderDate > '2022-12-01'"]}})); // get filterd rows
66
- console.log(await apiOrder.getByFilter()); // this get all rows
67
- console.log(await apiOrderDetail.patchById({patch: {sets: {ItemRef: "2024-TX-0001", ItemDate: "2024-01-31"}}}, "xxxxx-xxxxx-xxxxxxxxxxxx-xxxxxx")); // change some fields
68
- console.log(await apiOrderDetail.patchByFilter({patch: {sets: {LastUpdate: "2023-04-30"}, filters: ["OrderId: 'xxxxx-xxxxx-xxxxxxxxxxxx-xxxxxx'"]}})); // change by filter
69
- console.log(await apiOrderDetail.deleteById("xxxxx-xxxxx-xxxxxxxxxxxx-xxxxxx")); // delete row by Id
70
- console.log(await apiOrderDetail.deleteByFilter({delete: {filters: ["ItemType in ('X', 'W')", "and", "ItemDate > '2022-12-01'"]}})); // delete filterd rows
71
- console.log(await apiExecuteSP.execute()); // execute procedure with no argument
72
- console.log(await apiExecuteSP.execute({execute: {arguments: "@Company, @OrderNumber", params: {Company: "XXX", OrderNumber: "12345"}}})); // execute procedure with arguments and params
73
- ```
74
-
75
- License
76
- -------
77
-
78
- MIT License
79
-
80
- Copyright (c) 2022
81
-
82
- Permission is hereby granted, free of charge, to any person obtaining a copy
83
- of this software and associated documentation files (the "Software"), to deal
84
- in the Software without restriction, including without limitation the rights
85
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
86
- copies of the Software, and to permit persons to whom the Software is
87
- furnished to do so, subject to the following conditions:
88
-
89
- The above copyright notice and this permission notice shall be included in all
90
- copies or substantial portions of the Software.
91
-
92
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
93
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
94
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
95
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
96
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
97
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ # db-crud-api 💡
2
+ CRUD api for database tables.
3
+
4
+ ## Installation
5
+ npm install db-crud-api
6
+
7
+ # Usage
8
+ ```javascript
9
+ import dbCrudApi from "db-crud-api";
10
+ const apiFactory = dbCrudApi(mySchema);
11
+
12
+ const mySchema = {
13
+ servers: {
14
+ server1: {
15
+ realName: "server1.mydomain.com",
16
+ type: "ms-sql",
17
+ instance: "DEFAULT",
18
+ user: "User1",
19
+ password: "mypassword",
20
+ options: {
21
+ appName: "myAppName",
22
+ ...
23
+ },
24
+ databases: {
25
+ db1: {
26
+ realName: "db_orders",
27
+ tables: {
28
+ table1: {
29
+ realName: "tb_orders_head",
30
+ idField: "Id",
31
+ autoId: true,
32
+ fields: {
33
+ Id: { realName: "OrderId", type: "uuid", lengh: undefined, canBeNull: false, description: "Unique Id", defaultValue: undefined },
34
+ CustomerId: { type: "string", lengh: undefined, canBeNull: false, description: "Customer Id", defaultValue: undefined },
35
+ ...
36
+ }
37
+ },
38
+ table2: {
39
+ realName: "tb_orders_detail",
40
+ idField: "Id",
41
+ autoId: true,
42
+ fields: {
43
+ Id: { realName: "OrderId", type: "uuid", lengh: undefined, canBeNull: false, description: "Unique Id", defaultValue: undefined },
44
+ OrderId: { type: "uuid", lengh: undefined, canBeNull: false, description: "Order Id", defaultValue: undefined },
45
+ RowSeq: { type: "numeric", lengh: undefined, canBeNull: false, description: "Row sequence", defaultValue: undefined },
46
+ ...
47
+ }
48
+ },
49
+ ...
50
+ }
51
+ },
52
+ ...
53
+ }
54
+ },
55
+ ...
56
+ }
57
+ };
58
+
59
+ const apiOrder = apiFactory.newROApi("server1.db1.table1"); // Read Only api
60
+ const apiOrderDetail = apiFactory.newFullApi("table2"); // full CRUD api
61
+ const apiExecuteSP = apiFactory.newExecuteApi("db1.my_storeproc"); // execute my_storeproc
62
+
63
+ console.log(await apiFactory.testConnection()); // optional
64
+
65
+ console.log(await apiOrder.getById("xxxxx-xxxxx-xxxxxxxxxxxx-xxxxxx"));
66
+ console.log(await apiOrder.getById("xxxxx-xxxxx-xxxxxxxxxxxx-xxxxxx", {get: {fields: ["Id", "OrderNumber", "OrderTotal"]}}));
67
+ console.log(await apiOrder.getByFilter({get: {filters: ["OrderType in ('P', 'A')", "and", "OrderDate > '2022-12-01'"]}})); // get filterd rows
68
+ console.log(await apiOrder.getByFilter()); // this get all rows
69
+ console.log(await apiOrderDetail.patchById({patch: {sets: {ItemRef: "2024-TX-0001", ItemDate: "2024-01-31"}}}, "xxxxx-xxxxx-xxxxxxxxxxxx-xxxxxx")); // change some fields
70
+ console.log(await apiOrderDetail.patchByFilter({patch: {sets: {LastUpdate: "2023-04-30"}, filters: ["OrderId: 'xxxxx-xxxxx-xxxxxxxxxxxx-xxxxxx'"]}})); // change by filter
71
+ console.log(await apiOrderDetail.deleteById("xxxxx-xxxxx-xxxxxxxxxxxx-xxxxxx")); // delete row by Id
72
+ console.log(await apiOrderDetail.deleteByFilter({delete: {filters: ["ItemType in ('X', 'W')", "and", "ItemDate > '2022-12-01'"]}})); // delete filterd rows
73
+ console.log(await apiExecuteSP.execute()); // execute procedure with no argument
74
+ console.log(await apiExecuteSP.execute({execute: {arguments: "@Company, @OrderNumber", params: {Company: "XXX", OrderNumber: "12345"}}})); // execute procedure with arguments and params
75
+ ```
76
+
77
+ License
78
+ -------
79
+
80
+ MIT License
81
+
82
+ Copyright (c) 2022
83
+
84
+ Permission is hereby granted, free of charge, to any person obtaining a copy
85
+ of this software and associated documentation files (the "Software"), to deal
86
+ in the Software without restriction, including without limitation the rights
87
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
88
+ copies of the Software, and to permit persons to whom the Software is
89
+ furnished to do so, subject to the following conditions:
90
+
91
+ The above copyright notice and this permission notice shall be included in all
92
+ copies or substantial portions of the Software.
93
+
94
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
95
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
96
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
97
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
98
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
99
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
98
100
  SOFTWARE.
package/deploy CHANGED
@@ -2,4 +2,4 @@
2
2
  ##### !!! pay attention to not publish files with secrets
3
3
  npm login
4
4
  npm publish
5
- npm unpublish db-crud-api@0.1.0
5
+ npm unpublish db-crud-api@0.X.X
@@ -1,27 +1,31 @@
1
- "use strict";
2
-
3
- import * as dbOpe from "./db-operations.js"
4
- import apiFull from "./api-full.js"
5
- import apiRO from "./api-ro.js"
6
- import apiExecute from "./api-execute.js"
7
- import apiBatch from "./api-batch.js"
8
-
9
- export function newFullApi(tablePath) {
10
- return new apiFull(tablePath);
11
- }
12
-
13
- export function newROApi(tablePath) {
14
- return new apiRO(tablePath);
15
- }
16
-
17
- export function newExecuteApi(procPath) {
18
- return new apiExecute(procPath);
19
- }
20
-
21
- export function newBatchApi(useTransaction) {
22
- return new apiBatch(useTransaction);
23
- }
24
-
25
- export function closeAllDbConnections() {
26
- return dbOpe.closeAllConnections();
1
+ "use strict";
2
+
3
+ import * as dbOpe from "./db-operations.js"
4
+ import apiFull from "./api-full.js"
5
+ import apiRO from "./api-ro.js"
6
+ import apiExecute from "./api-execute.js"
7
+ import apiBatch from "./api-batch.js"
8
+
9
+ export function newFullApi(tablePath) {
10
+ return new apiFull(tablePath);
11
+ }
12
+
13
+ export function newROApi(tablePath) {
14
+ return new apiRO(tablePath);
15
+ }
16
+
17
+ export function newExecuteApi(procPath) {
18
+ return new apiExecute(procPath);
19
+ }
20
+
21
+ export function newBatchApi(useTransaction) {
22
+ return new apiBatch(useTransaction);
23
+ }
24
+
25
+ export function closeAllDbConnections() {
26
+ return dbOpe.closeAllConnections();
27
+ }
28
+
29
+ export function testDbConnection() {
30
+ return dbOpe.testConnection();
27
31
  }