multi-db-orm 2.1.4 → 2.1.7

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.
@@ -1,24 +1,24 @@
1
- # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
- # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3
-
4
- name: NPM Publish
5
-
6
- on:
7
- release:
8
- types: [created]
9
- push:
10
- branches:
11
- - "master"
12
-
13
- jobs:
14
- publish:
15
- runs-on: ubuntu-latest
16
- steps:
17
- - uses: actions/checkout@v1
18
- - uses: actions/setup-node@v1
19
- with:
20
- node-version: 14
21
- - run: npm install
22
- - uses: JS-DevTools/npm-publish@v1
23
- with:
24
- token: ${{ secrets.NPM_TOKEN }}
1
+ # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
+ # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3
+
4
+ name: NPM Publish
5
+
6
+ on:
7
+ release:
8
+ types: [created]
9
+ push:
10
+ branches:
11
+ - "master"
12
+
13
+ jobs:
14
+ publish:
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: actions/checkout@v1
18
+ - uses: actions/setup-node@v1
19
+ with:
20
+ node-version: 14
21
+ - run: npm install
22
+ - uses: JS-DevTools/npm-publish@v1
23
+ with:
24
+ token: ${{ secrets.NPM_TOKEN }}
@@ -1,30 +1,30 @@
1
- {
2
- // Use IntelliSense to learn about possible attributes.
3
- // Hover to view descriptions of existing attributes.
4
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
- "version": "0.2.0",
6
- "configurations": [
7
- {
8
- "name": "Launch via NPM",
9
- "request": "launch",
10
- "runtimeArgs": [
11
- "run-script",
12
- "test"
13
- ],
14
- "runtimeExecutable": "npm",
15
- "skipFiles": [
16
- "<node_internals>/**"
17
- ],
18
- "type": "node"
19
- },
20
- {
21
- "type": "node",
22
- "request": "launch",
23
- "name": "Launch Program",
24
- "skipFiles": [
25
- "<node_internals>/**"
26
- ],
27
- "program": "${workspaceFolder}/test/test.js"
28
- }
29
- ]
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "Launch via NPM",
9
+ "request": "launch",
10
+ "runtimeArgs": [
11
+ "run-script",
12
+ "test"
13
+ ],
14
+ "runtimeExecutable": "npm",
15
+ "skipFiles": [
16
+ "<node_internals>/**"
17
+ ],
18
+ "type": "node"
19
+ },
20
+ {
21
+ "type": "node",
22
+ "request": "launch",
23
+ "name": "Launch Program",
24
+ "skipFiles": [
25
+ "<node_internals>/**"
26
+ ],
27
+ "program": "${workspaceFolder}/test/test.js"
28
+ }
29
+ ]
30
30
  }
@@ -1,11 +1,11 @@
1
- {
2
- "sqltools.connections": [
3
- {
4
- "previewLimit": 50,
5
- "driver": "SQLite",
6
- "name": "test",
7
- "database": "${workspaceFolder:multi-db-safe}/test.db"
8
- }
9
- ],
10
- "sqltools.useNodeRuntime": true
1
+ {
2
+ "sqltools.connections": [
3
+ {
4
+ "previewLimit": 50,
5
+ "driver": "SQLite",
6
+ "name": "test",
7
+ "database": "${workspaceFolder:multi-db-safe}/test.db"
8
+ }
9
+ ],
10
+ "sqltools.useNodeRuntime": true
11
11
  }
package/Dockerfile CHANGED
@@ -1,17 +1,17 @@
1
- # The base image
2
- FROM node:10
3
-
4
- # The working directory inside the image
5
- WORKDIR /multi-db-safe
6
-
7
- # Copy everything from folder with the docker file to /app
8
- COPY . .
9
-
10
- # Run a commandline when docker build
11
- RUN npm install
12
-
13
- # Upon start of image this command will run , This is taken as a startup command and can be overriden from cmd line when 'docker run'
14
- CMD ["echo","Starting Migration..."]
15
-
16
- # Upon start of image this command will run , This is taken as a stable command and cannot be overriden from cmd line when 'docker run'
17
- ENTRYPOINT ["/multi-db-safe/migrate.sh"]
1
+ # The base image
2
+ FROM node:10
3
+
4
+ # The working directory inside the image
5
+ WORKDIR /multi-db-safe
6
+
7
+ # Copy everything from folder with the docker file to /app
8
+ COPY . .
9
+
10
+ # Run a commandline when docker build
11
+ RUN npm install
12
+
13
+ # Upon start of image this command will run , This is taken as a startup command and can be overriden from cmd line when 'docker run'
14
+ CMD ["echo","Starting Migration..."]
15
+
16
+ # Upon start of image this command will run , This is taken as a stable command and cannot be overriden from cmd line when 'docker run'
17
+ ENTRYPOINT ["/multi-db-safe/migrate.sh"]
package/README.md CHANGED
@@ -1,229 +1,229 @@
1
- # multi-db-orm
2
- ORM for multiple SQL and NoSQL databases like firestore , MongoDB , SQlite with Sync , Backup and Restore support .
3
-
4
- [![NPM Publish](https://github.com/shiveshnavin/multi-db-orm/actions/workflows/npm-publish.yml/badge.svg)](https://github.com/shiveshnavin/multi-db-orm/actions/workflows/npm-publish.yml)
5
-
6
- ## 1. Object Relational Mapping
7
-
8
- Supported databases:
9
- 1. MongoDB
10
- 2. Google Firestore
11
- 3. SQlite3
12
- 4. Oracle
13
- 4. MySQL
14
-
15
- ### Install
16
- The package is available on npm
17
- `
18
- npm install multi-db-orm
19
- `
20
-
21
- ### Initialize
22
- Install the target optional database dependencies based on your usage
23
- ```
24
- npm install --save mongodb
25
- npm install --save firebase-admin
26
- npm install --save sqlite3
27
- npm install --save oracledb oracle-instantclient
28
- npm install --save mysql
29
- ```
30
-
31
- Configure the database
32
- ```
33
- const { MultiDbORM, FireStoreDB, MongoDB, SQLiteDB, MySQLDB, Sync } = require("multi-db-orm");
34
-
35
- // You can choose to initialize any or all of the supported databases in singe app
36
-
37
- // Firestore
38
- var firebasedb = new FireStoreDB(require("/path/to/serviceAccountFile.json"));
39
- Note: If you use firebase DB then keys with undefined values will be set to null while insert or update as firebase dosent support undefined values
40
-
41
- // Sqlite
42
- var sqlitedb = new SQLiteDB("/path/to/mydatabase.db"); // if no path is passed , an in-memory db is used
43
-
44
- // MongoDB
45
- var mongodb = new MongoDB("mongodb+srv://username:PassW0rd@host.server.net/my_db_name","my_db_name");
46
-
47
- // OracleDB
48
- // Download client credentials (Wallet) and extract to /path/to/your/extracted/wallet-dir
49
- // Oracle field names are case insensetive, Always name your fields in snake case
50
- var oracledb = new OracleDB({
51
- username: 'your-username',
52
- password: 'your-password',
53
- wallet_dir: '/path/to/your/extracted/wallet-dir',
54
- net_service_name: 'connstring-high', //get any one from tnsnames.ora
55
- connection_pool_name:'your-conn-pool-name' //optional
56
- });
57
-
58
- // MySQLDB
59
- var mysqldb = new MySQLDB({
60
- "host": "db.mysql.com",
61
- "port": "3306",
62
- "username": "test",
63
- "password": "Password@123",
64
- "database": "test"
65
- });
66
-
67
- var db = firebasedb;
68
- ```
69
-
70
- ### Usage
71
- You can perform Create,Insert,Get,GetOne,Update,Delete queries . You only need to base your code on the interface MultiDbORM
72
-
73
- <b>Note:</b>
74
- 1. Firestore DB requires a `documentPath` specified for each document in a collection . For FirestoreDB functions you can optionally specify this path as the last parameter in getOne,update,insert,delete functions or have a 'id' field in all your objects . If none are specified the Date.now() is used.
75
- 2. All the functions are `async` i.e. they return a promise so you can use `..then()` or `await`
76
-
77
- #### Create
78
- You can create a Table from a sample object in SQlite . NoSQL databases need not create a entity explicitly .
79
- ```
80
- // db.create(modelname,sampleObject)
81
-
82
- var db = new SQLiteDB("/path/to/mydatabase.db"); // if no path is passed , an in-memory db is used
83
- db.create('game',aSampleGameObject);
84
- // creates a game table in db .
85
- // The fields and their data types are extracted from aSampleGameObject but aSampleGameObject is not saved in db
86
- ```
87
-
88
- #### Insert
89
- The same code will insert a object to the database entity based on the Implementation of MultiDbORM selected from Initialize Step above . Calling `db.insert()` returns a promise so can be used with async/await easily .
90
- ```
91
- // db.insert(modelname,object)
92
-
93
- var res = await db.insert('game', gm);
94
-
95
- OR
96
-
97
- db.insert('game', gm).then(response=>{
98
- console.log(response);
99
- }).catch(err=>{
100
- console.log(err);
101
- });
102
- ```
103
-
104
- #### Get
105
- The code will retrieve object(s) from the database .
106
- ```
107
- // db.get(modelname,filter)
108
-
109
- var games = await db.get('game', { amount: 19.00 , type: 'Hockey' });
110
- // returns an array of games having amount = 19.00 and type = Hockey
111
-
112
- var oneGame = await db.getOne('game', { country: 'India' }); // returns single game having country = 19.00
113
-
114
- var oneGameFr = await db.getOne('game', { country: 'India' },"32g274hfn48vnf"));
115
- // Only for firestore if docPath is passed optionally , filter is ignored and the object is returned
116
- ```
117
-
118
-
119
- #### Get with Range and sort
120
- The code will retrieve object(s) from the database with range (supported range operations : > , < , >= , >= , != , = ) and sort (asc or desc) on single field , limit and offset.
121
- ```
122
- var gamesFr = await mongodb.get('games', { amount: 400 }, {
123
- apply: {
124
- field: 'timeStamp',
125
- sort: 'desc',
126
- ineq: {
127
- op: '>=',
128
- value: 1650398288
129
- }
130
- },
131
- limit: 2, offset: 1
132
- })
133
-
134
- ```
135
-
136
- #### Get with Sort , Limit and Offset
137
- The code will retrieve object(s) from the database with sort (asc or desc) , limit and offset.
138
- ```
139
- var oneGameFr = await mongodb.get('game',
140
- { country: 'India' },
141
- { sort: [{ field: 'timeStamp', order: 'asc' },
142
- { field: 'amount', order: 'asc' }],
143
- limit: 5, offset: 1
144
- })
145
-
146
- ```
147
- Note :
148
- 1. For firestore indexes have to be created before using sort . In case indexes are not there you will get an error in the console with a link where you can create the required index .
149
- 2. sort is not applicable when using apply and will be ignored
150
-
151
-
152
- #### Update
153
- The code will update objects in the database .
154
- ```
155
- // db.update(modelname,filter,object)
156
-
157
-
158
- var result = await db.update('game', { amount: 19.00 , type: 'Hockey' },{status : "cancelled",closingTime:Date.now()});
159
- // updates all the games having amount=19.00 and type=Hockey to status=cancelled
160
- // and closingTime as current time while other fields are not touched
161
-
162
- var result_fire = await db.update('game', { amount: 19.00 , type: 'Hockey' },"32g274hfn48vnf");
163
- /* Only for firestore with optional docPath , it will update collection("game").doc("32g274hfn48vnf") .
164
- The filters amount and type are ignored when docPath is passed */
165
- ```
166
-
167
- #### Delete
168
- The code will delete objects in the database .
169
- ````
170
- // db.delete(modelname,filter)
171
-
172
-
173
- var result = await db.delete('game', { amount: 19.00 , type: 'Hockey' });
174
- // deletes all the games having amount=19.00 and type=Hockey
175
-
176
- var result_fire = await db.delete('game', { amount: 19.00 , type: 'Hockey' },"32g274hfn48vnf");
177
- /* Only for firestore with optional docPath , it will delete collection("game").doc("32g274hfn48vnf") .
178
- The filters amount and type are ignored when docPath is passed */
179
- ````
180
-
181
-
182
-
183
-
184
- ## 2. Migration
185
-
186
- #### Mongo DB
187
-
188
- Pass your SOURCE and TARGET DB credentials
189
-
190
- Using Docker
191
- ```
192
- docker run shiveshnavin/multi-db-safe 'mongodb://username:paswd@dbhost:13873/sourceDBName' 'mongodb://username:paswd@dbhost:13873/targetDBName' 0
193
-
194
- ```
195
- Using Shell
196
- ```
197
- ./migrate.sh 'mongodb://username:paswd@dbhost:13873/sourceDBName' 'mongodb://username:paswd@dbhost:13873/targetDBName' 0
198
-
199
- ```
200
-
201
- Note : To run deduplication as well set 1 instead of 0 at last cmd line argument
202
-
203
- ## 3. Backup
204
-
205
- #### Mongo DB
206
- ```
207
- node backup.js 'mongodb://username:paswd@dbhost:13873/sourceDBName'
208
- ```
209
-
210
- This will create a dump file in dumps/
211
-
212
- ## 4. Restore
213
-
214
- #### Mongo DB
215
- ```
216
- Without Deduplication : node restore.js dumpfile.json 'mongodb://username:paswd@dbhost:13873/targetDBName'
217
-
218
- With Deduplication : node restore.js dumpfile.json 'mongodb://username:paswd@dbhost:13873/targetDBName' 1
219
- ```
220
-
221
-
222
- ## 5. Work in Progress
223
- Working on enhancing the tool with below features in progress. Feel free to contribute and create a PR .
224
-
225
- - [ ] Add Backup support for other databases
226
- - [ ] Add Restore support for other databases
227
- - [X] Range Operations like `>=` `<=`
228
- - [ ] Aggregations
229
- - [ ] InsertMany
1
+ # multi-db-orm
2
+ ORM for multiple SQL and NoSQL databases like firestore , MongoDB , SQlite with Sync , Backup and Restore support .
3
+
4
+ [![NPM Publish](https://github.com/shiveshnavin/multi-db-orm/actions/workflows/npm-publish.yml/badge.svg)](https://github.com/shiveshnavin/multi-db-orm/actions/workflows/npm-publish.yml)
5
+
6
+ ## 1. Object Relational Mapping
7
+
8
+ Supported databases:
9
+ 1. MongoDB
10
+ 2. Google Firestore
11
+ 3. SQlite3
12
+ 4. Oracle
13
+ 4. MySQL
14
+
15
+ ### Install
16
+ The package is available on npm
17
+ `
18
+ npm install multi-db-orm
19
+ `
20
+
21
+ ### Initialize
22
+ Install the target optional database dependencies based on your usage
23
+ ```
24
+ npm install --save mongodb
25
+ npm install --save firebase-admin
26
+ npm install --save sqlite3
27
+ npm install --save oracledb oracle-instantclient
28
+ npm install --save mysql
29
+ ```
30
+
31
+ Configure the database
32
+ ```
33
+ const { MultiDbORM, FireStoreDB, MongoDB, SQLiteDB, MySQLDB, Sync } = require("multi-db-orm");
34
+
35
+ // You can choose to initialize any or all of the supported databases in singe app
36
+
37
+ // Firestore
38
+ var firebasedb = new FireStoreDB(require("/path/to/serviceAccountFile.json"));
39
+ Note: If you use firebase DB then keys with undefined values will be set to null while insert or update as firebase dosent support undefined values
40
+
41
+ // Sqlite
42
+ var sqlitedb = new SQLiteDB("/path/to/mydatabase.db"); // if no path is passed , an in-memory db is used
43
+
44
+ // MongoDB
45
+ var mongodb = new MongoDB("mongodb+srv://username:PassW0rd@host.server.net/my_db_name","my_db_name");
46
+
47
+ // OracleDB
48
+ // Download client credentials (Wallet) and extract to /path/to/your/extracted/wallet-dir
49
+ // Oracle field names are case insensetive, Always name your fields in snake case
50
+ var oracledb = new OracleDB({
51
+ username: 'your-username',
52
+ password: 'your-password',
53
+ wallet_dir: '/path/to/your/extracted/wallet-dir',
54
+ net_service_name: 'connstring-high', //get any one from tnsnames.ora
55
+ connection_pool_name:'your-conn-pool-name' //optional
56
+ });
57
+
58
+ // MySQLDB
59
+ var mysqldb = new MySQLDB({
60
+ "host": "db.mysql.com",
61
+ "port": "3306",
62
+ "username": "test",
63
+ "password": "Password@123",
64
+ "database": "test"
65
+ });
66
+
67
+ var db = firebasedb;
68
+ ```
69
+
70
+ ### Usage
71
+ You can perform Create,Insert,Get,GetOne,Update,Delete queries . You only need to base your code on the interface MultiDbORM
72
+
73
+ <b>Note:</b>
74
+ 1. Firestore DB requires a `documentPath` specified for each document in a collection . For FirestoreDB functions you can optionally specify this path as the last parameter in getOne,update,insert,delete functions or have a 'id' field in all your objects . If none are specified the Date.now() is used.
75
+ 2. All the functions are `async` i.e. they return a promise so you can use `..then()` or `await`
76
+
77
+ #### Create
78
+ You can create a Table from a sample object in SQlite . NoSQL databases need not create a entity explicitly .
79
+ ```
80
+ // db.create(modelname,sampleObject)
81
+
82
+ var db = new SQLiteDB("/path/to/mydatabase.db"); // if no path is passed , an in-memory db is used
83
+ db.create('game',aSampleGameObject);
84
+ // creates a game table in db .
85
+ // The fields and their data types are extracted from aSampleGameObject but aSampleGameObject is not saved in db
86
+ ```
87
+
88
+ #### Insert
89
+ The same code will insert a object to the database entity based on the Implementation of MultiDbORM selected from Initialize Step above . Calling `db.insert()` returns a promise so can be used with async/await easily .
90
+ ```
91
+ // db.insert(modelname,object)
92
+
93
+ var res = await db.insert('game', gm);
94
+
95
+ OR
96
+
97
+ db.insert('game', gm).then(response=>{
98
+ console.log(response);
99
+ }).catch(err=>{
100
+ console.log(err);
101
+ });
102
+ ```
103
+
104
+ #### Get
105
+ The code will retrieve object(s) from the database .
106
+ ```
107
+ // db.get(modelname,filter)
108
+
109
+ var games = await db.get('game', { amount: 19.00 , type: 'Hockey' });
110
+ // returns an array of games having amount = 19.00 and type = Hockey
111
+
112
+ var oneGame = await db.getOne('game', { country: 'India' }); // returns single game having country = 19.00
113
+
114
+ var oneGameFr = await db.getOne('game', { country: 'India' },"32g274hfn48vnf"));
115
+ // Only for firestore if docPath is passed optionally , filter is ignored and the object is returned
116
+ ```
117
+
118
+
119
+ #### Get with Range and sort
120
+ The code will retrieve object(s) from the database with range (supported range operations : > , < , >= , >= , != , = ) and sort (asc or desc) on single field , limit and offset.
121
+ ```
122
+ var gamesFr = await mongodb.get('games', { amount: 400 }, {
123
+ apply: {
124
+ field: 'timeStamp',
125
+ sort: 'desc',
126
+ ineq: {
127
+ op: '>=',
128
+ value: 1650398288
129
+ }
130
+ },
131
+ limit: 2, offset: 1
132
+ })
133
+
134
+ ```
135
+
136
+ #### Get with Sort , Limit and Offset
137
+ The code will retrieve object(s) from the database with sort (asc or desc) , limit and offset.
138
+ ```
139
+ var oneGameFr = await mongodb.get('game',
140
+ { country: 'India' },
141
+ { sort: [{ field: 'timeStamp', order: 'asc' },
142
+ { field: 'amount', order: 'asc' }],
143
+ limit: 5, offset: 1
144
+ })
145
+
146
+ ```
147
+ Note :
148
+ 1. For firestore indexes have to be created before using sort . In case indexes are not there you will get an error in the console with a link where you can create the required index .
149
+ 2. sort is not applicable when using apply and will be ignored
150
+
151
+
152
+ #### Update
153
+ The code will update objects in the database .
154
+ ```
155
+ // db.update(modelname,filter,object)
156
+
157
+
158
+ var result = await db.update('game', { amount: 19.00 , type: 'Hockey' },{status : "cancelled",closingTime:Date.now()});
159
+ // updates all the games having amount=19.00 and type=Hockey to status=cancelled
160
+ // and closingTime as current time while other fields are not touched
161
+
162
+ var result_fire = await db.update('game', { amount: 19.00 , type: 'Hockey' },"32g274hfn48vnf");
163
+ /* Only for firestore with optional docPath , it will update collection("game").doc("32g274hfn48vnf") .
164
+ The filters amount and type are ignored when docPath is passed */
165
+ ```
166
+
167
+ #### Delete
168
+ The code will delete objects in the database .
169
+ ````
170
+ // db.delete(modelname,filter)
171
+
172
+
173
+ var result = await db.delete('game', { amount: 19.00 , type: 'Hockey' });
174
+ // deletes all the games having amount=19.00 and type=Hockey
175
+
176
+ var result_fire = await db.delete('game', { amount: 19.00 , type: 'Hockey' },"32g274hfn48vnf");
177
+ /* Only for firestore with optional docPath , it will delete collection("game").doc("32g274hfn48vnf") .
178
+ The filters amount and type are ignored when docPath is passed */
179
+ ````
180
+
181
+
182
+
183
+
184
+ ## 2. Migration
185
+
186
+ #### Mongo DB
187
+
188
+ Pass your SOURCE and TARGET DB credentials
189
+
190
+ Using Docker
191
+ ```
192
+ docker run shiveshnavin/multi-db-safe 'mongodb://username:paswd@dbhost:13873/sourceDBName' 'mongodb://username:paswd@dbhost:13873/targetDBName' 0
193
+
194
+ ```
195
+ Using Shell
196
+ ```
197
+ ./migrate.sh 'mongodb://username:paswd@dbhost:13873/sourceDBName' 'mongodb://username:paswd@dbhost:13873/targetDBName' 0
198
+
199
+ ```
200
+
201
+ Note : To run deduplication as well set 1 instead of 0 at last cmd line argument
202
+
203
+ ## 3. Backup
204
+
205
+ #### Mongo DB
206
+ ```
207
+ node backup.js 'mongodb://username:paswd@dbhost:13873/sourceDBName'
208
+ ```
209
+
210
+ This will create a dump file in dumps/
211
+
212
+ ## 4. Restore
213
+
214
+ #### Mongo DB
215
+ ```
216
+ Without Deduplication : node restore.js dumpfile.json 'mongodb://username:paswd@dbhost:13873/targetDBName'
217
+
218
+ With Deduplication : node restore.js dumpfile.json 'mongodb://username:paswd@dbhost:13873/targetDBName' 1
219
+ ```
220
+
221
+
222
+ ## 5. Work in Progress
223
+ Working on enhancing the tool with below features in progress. Feel free to contribute and create a PR .
224
+
225
+ - [ ] Add Backup support for other databases
226
+ - [ ] Add Restore support for other databases
227
+ - [X] Range Operations like `>=` `<=`
228
+ - [ ] Aggregations
229
+ - [ ] InsertMany