multi-db-orm 1.3.0 → 1.3.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.
@@ -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,17 +1,17 @@
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
- "type": "node",
9
- "request": "launch",
10
- "name": "Launch Program",
11
- "skipFiles": [
12
- "<node_internals>/**"
13
- ],
14
- "program": "${workspaceFolder}/test/test.js"
15
- }
16
- ]
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
+ "type": "node",
9
+ "request": "launch",
10
+ "name": "Launch Program",
11
+ "skipFiles": [
12
+ "<node_internals>/**"
13
+ ],
14
+ "program": "${workspaceFolder}/test/test.js"
15
+ }
16
+ ]
17
17
  }
@@ -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,196 +1,197 @@
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
-
13
- ### Install
14
- The package is available on npm
15
- `
16
- npm install multi-db-orm
17
- `
18
-
19
- ### Initialize
20
- ```
21
- const { MultiDbORM, FireStoreDB, MongoDB, SQLiteDB, Sync } = require("multi-db-orm");
22
-
23
- // You can choose to initialize any or all of the supported databases in singe app
24
-
25
- // Firestore
26
- var firebasedb = new FireStoreDB(require("/path/to/serviceAccountFile.json"));
27
-
28
- // Sqlite
29
- var sqlitedb = new SQLiteDB("/path/to/mydatabase.db"); // if no path is passed , an in-memory db is used
30
-
31
- // MongoDB
32
- var mongodb = new MongoDB("mongodb+srv://username:PassW0rd@host.server.net/my_db_name","my_db_name");
33
-
34
- var db = firebasedb;
35
- ```
36
-
37
- ### Usage
38
- You can perform Create,Insert,Get,GetOne,Update,Delete queries . You only need to base your code on the interface MultiDbORM
39
-
40
- <b>Note:</b>
41
- 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.
42
- 2. All the functions are `async` i.e. they return a promise so you can use `..then()` or `await`
43
-
44
- #### Create
45
- You can create a Table from a sample object in SQlite . NoSQL databases need not create a entity explicitly .
46
- ```
47
- // db.create(modelname,sampleObject)
48
-
49
- var db = new SQLiteDB("/path/to/mydatabase.db"); // if no path is passed , an in-memory db is used
50
- db.create('game',aSampleGameObject);
51
- // creates a game table in db .
52
- // The fields and their data types are extracted from aSampleGameObject but aSampleGameObject is not saved in db
53
- ```
54
-
55
- #### Insert
56
- 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 .
57
- ```
58
- // db.insert(modelname,object)
59
-
60
- var res = await db.insert('game', gm);
61
-
62
- OR
63
-
64
- db.insert('game', gm).then(response=>{
65
- console.log(response);
66
- }).catch(err=>{
67
- console.log(err);
68
- });
69
- ```
70
-
71
- #### Get
72
- The code will retrieve object(s) from the database .
73
- ```
74
- // db.get(modelname,filter)
75
-
76
- var games = await db.get('game', { amount: 19.00 , type: 'Hockey' });
77
- // returns an array of games having amount = 19.00 and type = Hockey
78
-
79
- var oneGame = await db.getOne('game', { country: 'India' }); // returns single game having country = 19.00
80
-
81
- var oneGameFr = await db.getOne('game', { country: 'India' },"32g274hfn48vnf"));
82
- // Only for firestore if docPath is passed optionally , filter is ignored and the object is returned
83
- ```
84
-
85
-
86
- #### Get with Range and sort
87
- 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.
88
- ```
89
- var gamesFr = await mongodb.get('games', { amount: 400 }, {
90
- apply: {
91
- field: 'timeStamp',
92
- sort: 'desc',
93
- ineq: {
94
- op: '>=',
95
- value: 1650398288
96
- }
97
- },
98
- limit: 2, offset: 1
99
- })
100
-
101
- ```
102
-
103
- #### Get with Sort , Limit and Offset
104
- The code will retrieve object(s) from the database with sort (asc or desc) , limit and offset.
105
- ```
106
- var oneGameFr = await mongodb.get('game',
107
- { country: 'India' },
108
- { sort: [{ field: 'timeStamp', order: 'asc' },
109
- { field: 'amount', order: 'asc' }],
110
- limit: 5, offset: 1
111
- })
112
-
113
- ```
114
- Note :
115
- 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 .
116
- 2. sort is not applicable when using apply and will be ignored
117
-
118
-
119
- #### Update
120
- The code will update objects in the database .
121
- ```
122
- // db.update(modelname,filter,object)
123
-
124
-
125
- var result = await db.update('game', { amount: 19.00 , type: 'Hockey' },{status : "cancelled",closingTime:Date.now()});
126
- // updates all the games having amount=19.00 and type=Hockey to status=cancelled
127
- // and closingTime as current time while other fields are not touched
128
-
129
- var result_fire = await db.update('game', { amount: 19.00 , type: 'Hockey' },"32g274hfn48vnf");
130
- /* Only for firestore with optional docPath , it will update collection("game").doc("32g274hfn48vnf") .
131
- The filters amount and type are ignored when docPath is passed */
132
- ```
133
-
134
- #### Delete
135
- The code will delete objects in the database .
136
- ````
137
- // db.delete(modelname,filter)
138
-
139
-
140
- var result = await db.delete('game', { amount: 19.00 , type: 'Hockey' });
141
- // deletes all the games having amount=19.00 and type=Hockey
142
-
143
- var result_fire = await db.delete('game', { amount: 19.00 , type: 'Hockey' },"32g274hfn48vnf");
144
- /* Only for firestore with optional docPath , it will delete collection("game").doc("32g274hfn48vnf") .
145
- The filters amount and type are ignored when docPath is passed */
146
- ````
147
-
148
-
149
-
150
-
151
- ## 2. Migration
152
-
153
- #### Mongo DB
154
-
155
- Pass your SOURCE and TARGET DB credentials
156
-
157
- Using Docker
158
- ```
159
- docker run shiveshnavin/multi-db-safe 'mongodb://username:paswd@dbhost:13873/sourceDBName' 'mongodb://username:paswd@dbhost:13873/targetDBName' 0
160
-
161
- ```
162
- Using Shell
163
- ```
164
- ./migrate.sh 'mongodb://username:paswd@dbhost:13873/sourceDBName' 'mongodb://username:paswd@dbhost:13873/targetDBName' 0
165
-
166
- ```
167
-
168
- Note : To run deduplication as well set 1 instead of 0 at last cmd line argument
169
-
170
- ## 3. Backup
171
-
172
- #### Mongo DB
173
- ```
174
- node backup.js 'mongodb://username:paswd@dbhost:13873/sourceDBName'
175
- ```
176
-
177
- This will create a dump file in dumps/
178
-
179
- ## 4. Restore
180
-
181
- #### Mongo DB
182
- ```
183
- Without Deduplication : node restore.js dumpfile.json 'mongodb://username:paswd@dbhost:13873/targetDBName'
184
-
185
- With Deduplication : node restore.js dumpfile.json 'mongodb://username:paswd@dbhost:13873/targetDBName' 1
186
- ```
187
-
188
-
189
- ## 5. Work in Progress
190
- Working on enhancing the tool with below features in progress. Feel free to contribute and create a PR .
191
-
192
- - [ ] Add Backup support for other databases
193
- - [ ] Add Restore support for other databases
194
- - [X] Range Operations like `>=` `<=`
195
- - [ ] Aggregations
196
- - [ ] 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
+
13
+ ### Install
14
+ The package is available on npm
15
+ `
16
+ npm install multi-db-orm
17
+ `
18
+
19
+ ### Initialize
20
+ ```
21
+ const { MultiDbORM, FireStoreDB, MongoDB, SQLiteDB, Sync } = require("multi-db-orm");
22
+
23
+ // You can choose to initialize any or all of the supported databases in singe app
24
+
25
+ // Firestore
26
+ var firebasedb = new FireStoreDB(require("/path/to/serviceAccountFile.json"));
27
+ 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
28
+
29
+ // Sqlite
30
+ var sqlitedb = new SQLiteDB("/path/to/mydatabase.db"); // if no path is passed , an in-memory db is used
31
+
32
+ // MongoDB
33
+ var mongodb = new MongoDB("mongodb+srv://username:PassW0rd@host.server.net/my_db_name","my_db_name");
34
+
35
+ var db = firebasedb;
36
+ ```
37
+
38
+ ### Usage
39
+ You can perform Create,Insert,Get,GetOne,Update,Delete queries . You only need to base your code on the interface MultiDbORM
40
+
41
+ <b>Note:</b>
42
+ 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.
43
+ 2. All the functions are `async` i.e. they return a promise so you can use `..then()` or `await`
44
+
45
+ #### Create
46
+ You can create a Table from a sample object in SQlite . NoSQL databases need not create a entity explicitly .
47
+ ```
48
+ // db.create(modelname,sampleObject)
49
+
50
+ var db = new SQLiteDB("/path/to/mydatabase.db"); // if no path is passed , an in-memory db is used
51
+ db.create('game',aSampleGameObject);
52
+ // creates a game table in db .
53
+ // The fields and their data types are extracted from aSampleGameObject but aSampleGameObject is not saved in db
54
+ ```
55
+
56
+ #### Insert
57
+ 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 .
58
+ ```
59
+ // db.insert(modelname,object)
60
+
61
+ var res = await db.insert('game', gm);
62
+
63
+ OR
64
+
65
+ db.insert('game', gm).then(response=>{
66
+ console.log(response);
67
+ }).catch(err=>{
68
+ console.log(err);
69
+ });
70
+ ```
71
+
72
+ #### Get
73
+ The code will retrieve object(s) from the database .
74
+ ```
75
+ // db.get(modelname,filter)
76
+
77
+ var games = await db.get('game', { amount: 19.00 , type: 'Hockey' });
78
+ // returns an array of games having amount = 19.00 and type = Hockey
79
+
80
+ var oneGame = await db.getOne('game', { country: 'India' }); // returns single game having country = 19.00
81
+
82
+ var oneGameFr = await db.getOne('game', { country: 'India' },"32g274hfn48vnf"));
83
+ // Only for firestore if docPath is passed optionally , filter is ignored and the object is returned
84
+ ```
85
+
86
+
87
+ #### Get with Range and sort
88
+ 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.
89
+ ```
90
+ var gamesFr = await mongodb.get('games', { amount: 400 }, {
91
+ apply: {
92
+ field: 'timeStamp',
93
+ sort: 'desc',
94
+ ineq: {
95
+ op: '>=',
96
+ value: 1650398288
97
+ }
98
+ },
99
+ limit: 2, offset: 1
100
+ })
101
+
102
+ ```
103
+
104
+ #### Get with Sort , Limit and Offset
105
+ The code will retrieve object(s) from the database with sort (asc or desc) , limit and offset.
106
+ ```
107
+ var oneGameFr = await mongodb.get('game',
108
+ { country: 'India' },
109
+ { sort: [{ field: 'timeStamp', order: 'asc' },
110
+ { field: 'amount', order: 'asc' }],
111
+ limit: 5, offset: 1
112
+ })
113
+
114
+ ```
115
+ Note :
116
+ 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 .
117
+ 2. sort is not applicable when using apply and will be ignored
118
+
119
+
120
+ #### Update
121
+ The code will update objects in the database .
122
+ ```
123
+ // db.update(modelname,filter,object)
124
+
125
+
126
+ var result = await db.update('game', { amount: 19.00 , type: 'Hockey' },{status : "cancelled",closingTime:Date.now()});
127
+ // updates all the games having amount=19.00 and type=Hockey to status=cancelled
128
+ // and closingTime as current time while other fields are not touched
129
+
130
+ var result_fire = await db.update('game', { amount: 19.00 , type: 'Hockey' },"32g274hfn48vnf");
131
+ /* Only for firestore with optional docPath , it will update collection("game").doc("32g274hfn48vnf") .
132
+ The filters amount and type are ignored when docPath is passed */
133
+ ```
134
+
135
+ #### Delete
136
+ The code will delete objects in the database .
137
+ ````
138
+ // db.delete(modelname,filter)
139
+
140
+
141
+ var result = await db.delete('game', { amount: 19.00 , type: 'Hockey' });
142
+ // deletes all the games having amount=19.00 and type=Hockey
143
+
144
+ var result_fire = await db.delete('game', { amount: 19.00 , type: 'Hockey' },"32g274hfn48vnf");
145
+ /* Only for firestore with optional docPath , it will delete collection("game").doc("32g274hfn48vnf") .
146
+ The filters amount and type are ignored when docPath is passed */
147
+ ````
148
+
149
+
150
+
151
+
152
+ ## 2. Migration
153
+
154
+ #### Mongo DB
155
+
156
+ Pass your SOURCE and TARGET DB credentials
157
+
158
+ Using Docker
159
+ ```
160
+ docker run shiveshnavin/multi-db-safe 'mongodb://username:paswd@dbhost:13873/sourceDBName' 'mongodb://username:paswd@dbhost:13873/targetDBName' 0
161
+
162
+ ```
163
+ Using Shell
164
+ ```
165
+ ./migrate.sh 'mongodb://username:paswd@dbhost:13873/sourceDBName' 'mongodb://username:paswd@dbhost:13873/targetDBName' 0
166
+
167
+ ```
168
+
169
+ Note : To run deduplication as well set 1 instead of 0 at last cmd line argument
170
+
171
+ ## 3. Backup
172
+
173
+ #### Mongo DB
174
+ ```
175
+ node backup.js 'mongodb://username:paswd@dbhost:13873/sourceDBName'
176
+ ```
177
+
178
+ This will create a dump file in dumps/
179
+
180
+ ## 4. Restore
181
+
182
+ #### Mongo DB
183
+ ```
184
+ Without Deduplication : node restore.js dumpfile.json 'mongodb://username:paswd@dbhost:13873/targetDBName'
185
+
186
+ With Deduplication : node restore.js dumpfile.json 'mongodb://username:paswd@dbhost:13873/targetDBName' 1
187
+ ```
188
+
189
+
190
+ ## 5. Work in Progress
191
+ Working on enhancing the tool with below features in progress. Feel free to contribute and create a PR .
192
+
193
+ - [ ] Add Backup support for other databases
194
+ - [ ] Add Restore support for other databases
195
+ - [X] Range Operations like `>=` `<=`
196
+ - [ ] Aggregations
197
+ - [ ] InsertMany