multi-db-orm 3.0.12 → 3.1.0

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,18 +1,18 @@
1
- import MongoClient from 'mongodb/lib/mongo_client';
2
- import { MultiDbORM } from './multidb';
3
-
4
- export declare class MongoDB extends MultiDbORM {
5
- mongodbname: string;
6
- dbc: typeof import('mongodb');
7
- db: typeof import('mongodb');
8
- client: MongoClient;
9
- url: string;
10
-
11
- constructor(secureUrl: string, mongodbname: string);
12
-
13
- _close(): Promise<void>;
14
-
15
- _connect(): Promise<void>;
16
-
17
- run(query: string): Promise<any>;
18
- }
1
+ import MongoClient from 'mongodb/lib/mongo_client';
2
+ import { MultiDbORM } from './multidb';
3
+
4
+ export declare class MongoDB extends MultiDbORM {
5
+ mongodbname: string;
6
+ dbc: typeof import('mongodb');
7
+ db: typeof import('mongodb');
8
+ client: MongoClient;
9
+ url: string;
10
+
11
+ constructor(secureUrl: string, mongodbname: string);
12
+
13
+ _close(): Promise<void>;
14
+
15
+ _connect(): Promise<void>;
16
+
17
+ run(query: string): Promise<any>;
18
+ }
@@ -1,149 +1,149 @@
1
- const { MultiDbORM } = require("./multidb");
2
-
3
- class MongoDB extends MultiDbORM {
4
-
5
- mongodbname
6
- dbc
7
- client
8
- url
9
- constructor(secureUrl, mongodbname) {
10
- super()
11
-
12
- this.url = secureUrl;
13
- this.mongodbname = mongodbname
14
-
15
- const MongoClient = require('mongodb').MongoClient;
16
- this.client = new MongoClient(this.url, {
17
- useUnifiedTopology: true,
18
- useNewUrlParser: true
19
- });
20
- this._connect();
21
- }
22
-
23
- async _close() {
24
- this.dbc.close();
25
- }
26
-
27
- async _connect() {
28
- var dbc = await this.client.connect();
29
- this.dbc = dbc;
30
- this.db = dbc.db(this.mongodbname);
31
- console.log("MongoDB Initialized");
32
- this.dbType = 'mongodb'
33
- }
34
-
35
- async run(query) {
36
- if (this.loglevel > 3)
37
- console.log('RUN : Not Supported in DB Type', this.dbType)
38
- }
39
- _inq2mongop(symbol) {
40
- switch (symbol) {
41
- case "=":
42
- return "$eq";
43
- case ">":
44
- return "$gt";
45
- case ">=":
46
- return "$gte";
47
- case "<":
48
- return "$lt";
49
- case "<=":
50
- return "$lte";
51
- case "!=":
52
- return "$ne";
53
- }
54
- }
55
- async get(modelname, filter, options) {
56
- this.metrics.get(modelname, filter, options);
57
- if (options && options.apply && options.apply.ineq) {
58
- filter[`${options.apply.field}`] = {};
59
- filter[`${options.apply.field}`][`${this._inq2mongop(options.apply.ineq.op)}`] = options.apply.ineq.value
60
- }
61
- var crs = this.getdb().collection(modelname).find(filter);
62
- if (options) {
63
- if (options.apply) {
64
- if (options.apply.sort) {
65
- var order = 1;
66
- if (options.apply.sort == 'desc') {
67
- order = -1;
68
- }
69
- var sortOption = {};
70
- sortOption[`${options.apply.field}`] = order;
71
- crs = crs.sort(sortOption);
72
- }
73
-
74
- } else if (options.sort) {
75
-
76
- var sortOption = {};
77
- options.sort.forEach(srt => {
78
- var order = 1;
79
- if (srt.order == 'desc') {
80
- order = -1;
81
- }
82
- sortOption[`${srt.field}`] = order;
83
- });
84
- crs = crs.sort(sortOption);
85
- }
86
-
87
- if (options.limit) {
88
- crs.limit(options.limit)
89
- }
90
-
91
- if (options.offset) {
92
- crs.skip(options.offset)
93
- }
94
- }
95
-
96
- var snapshot = await crs.toArray()
97
- return snapshot;
98
-
99
- }
100
-
101
- async getOne(modelname, filter, options) {
102
- this.metrics.getOne(modelname, filter, options);
103
- var snapshot = await this.getdb().collection(modelname).findOne(filter)
104
- return snapshot;
105
- }
106
-
107
- async create(modelname, sampleObject) {
108
- this.sync.create(modelname, sampleObject)
109
- this.metrics.create(modelname, sampleObject);
110
-
111
- if (this.loglevel > 3)
112
- console.log('CREATE : Not required in DB Type', this.dbType)
113
- }
114
-
115
- async insert(modelname, object) {
116
- this.sync.insert(modelname, object)
117
- this.metrics.insert(modelname, object)
118
-
119
- const collref = this.getdb().collection(modelname)
120
- try {
121
- return await collref.insertOne(object);
122
- } catch (e) {
123
-
124
- throw e;
125
-
126
- }
127
-
128
- }
129
-
130
- async update(modelname, filter, object) {
131
- this.sync.update(modelname, filter, object)
132
- this.metrics.update(modelname, filter, object)
133
- var resp = await this.getdb().collection(modelname).updateMany(filter, { $set: object })
134
- return resp;
135
- }
136
-
137
- async delete(modelname, filter) {
138
- this.sync.delete(modelname, filter)
139
- this.metrics.delete(modelname, filter)
140
- var resp = await this.getdb().collection(modelname).deleteMany(filter)
141
- return resp;
142
- }
143
- }
144
-
145
-
146
-
147
- module.exports = {
148
- MongoDB
1
+ const { MultiDbORM } = require("./multidb");
2
+
3
+ class MongoDB extends MultiDbORM {
4
+
5
+ mongodbname
6
+ dbc
7
+ client
8
+ url
9
+ constructor(secureUrl, mongodbname) {
10
+ super()
11
+
12
+ this.url = secureUrl;
13
+ this.mongodbname = mongodbname
14
+
15
+ const MongoClient = require('mongodb').MongoClient;
16
+ this.client = new MongoClient(this.url, {
17
+ useUnifiedTopology: true,
18
+ useNewUrlParser: true
19
+ });
20
+ this._connect();
21
+ }
22
+
23
+ async _close() {
24
+ this.dbc.close();
25
+ }
26
+
27
+ async _connect() {
28
+ var dbc = await this.client.connect();
29
+ this.dbc = dbc;
30
+ this.db = dbc.db(this.mongodbname);
31
+ console.log("MongoDB Initialized");
32
+ this.dbType = 'mongodb'
33
+ }
34
+
35
+ async run(query) {
36
+ if (this.loglevel > 3)
37
+ console.log('RUN : Not Supported in DB Type', this.dbType)
38
+ }
39
+ _inq2mongop(symbol) {
40
+ switch (symbol) {
41
+ case "=":
42
+ return "$eq";
43
+ case ">":
44
+ return "$gt";
45
+ case ">=":
46
+ return "$gte";
47
+ case "<":
48
+ return "$lt";
49
+ case "<=":
50
+ return "$lte";
51
+ case "!=":
52
+ return "$ne";
53
+ }
54
+ }
55
+ async get(modelname, filter, options) {
56
+ this.metrics.get(modelname, filter, options);
57
+ if (options && options.apply && options.apply.ineq) {
58
+ filter[`${options.apply.field}`] = {};
59
+ filter[`${options.apply.field}`][`${this._inq2mongop(options.apply.ineq.op)}`] = options.apply.ineq.value
60
+ }
61
+ var crs = this.getdb().collection(modelname).find(filter);
62
+ if (options) {
63
+ if (options.apply) {
64
+ if (options.apply.sort) {
65
+ var order = 1;
66
+ if (options.apply.sort == 'desc') {
67
+ order = -1;
68
+ }
69
+ var sortOption = {};
70
+ sortOption[`${options.apply.field}`] = order;
71
+ crs = crs.sort(sortOption);
72
+ }
73
+
74
+ } else if (options.sort) {
75
+
76
+ var sortOption = {};
77
+ options.sort.forEach(srt => {
78
+ var order = 1;
79
+ if (srt.order == 'desc') {
80
+ order = -1;
81
+ }
82
+ sortOption[`${srt.field}`] = order;
83
+ });
84
+ crs = crs.sort(sortOption);
85
+ }
86
+
87
+ if (options.limit) {
88
+ crs.limit(options.limit)
89
+ }
90
+
91
+ if (options.offset) {
92
+ crs.skip(options.offset)
93
+ }
94
+ }
95
+
96
+ var snapshot = await crs.toArray()
97
+ return snapshot;
98
+
99
+ }
100
+
101
+ async getOne(modelname, filter, options) {
102
+ this.metrics.getOne(modelname, filter, options);
103
+ var snapshot = await this.getdb().collection(modelname).findOne(filter)
104
+ return snapshot;
105
+ }
106
+
107
+ async create(modelname, sampleObject) {
108
+ this.sync.create(modelname, sampleObject)
109
+ this.metrics.create(modelname, sampleObject);
110
+
111
+ if (this.loglevel > 3)
112
+ console.log('CREATE : Not required in DB Type', this.dbType)
113
+ }
114
+
115
+ async insert(modelname, object) {
116
+ this.sync.insert(modelname, object)
117
+ this.metrics.insert(modelname, object)
118
+
119
+ const collref = this.getdb().collection(modelname)
120
+ try {
121
+ return await collref.insertOne(object);
122
+ } catch (e) {
123
+
124
+ throw e;
125
+
126
+ }
127
+
128
+ }
129
+
130
+ async update(modelname, filter, object) {
131
+ this.sync.update(modelname, filter, object)
132
+ this.metrics.update(modelname, filter, object)
133
+ var resp = await this.getdb().collection(modelname).updateMany(filter, { $set: object })
134
+ return resp;
135
+ }
136
+
137
+ async delete(modelname, filter) {
138
+ this.sync.delete(modelname, filter)
139
+ this.metrics.delete(modelname, filter)
140
+ var resp = await this.getdb().collection(modelname).deleteMany(filter)
141
+ return resp;
142
+ }
143
+ }
144
+
145
+
146
+
147
+ module.exports = {
148
+ MongoDB
149
149
  }
@@ -1,41 +1,41 @@
1
- export class MultiDbORM {
2
- db: any;
3
- dbType: string;
4
- reqMade: number;
5
- lastQLatency: any;
6
- loglevel: number;
7
- sync: import('../sync').Sync;
8
- metrics: import('./metrics').Metrics;
9
-
10
- constructor(db: any);
11
-
12
- connect(): Promise<void>;
13
-
14
- setdb(db: any): void;
15
-
16
- getdb(): any;
17
-
18
- get(modelname: string, filter?: Record<string, any>, options?: {
19
- apply?: {
20
- field: string,
21
- sort: string,
22
- ineq: {
23
- op: '>=' | '<=' | '=' | '>' | '<',
24
- value: string | number | boolean
25
- }
26
- },
27
- sort?: { field: string, order: 'asc' | 'desc' }[]
28
- limit?: number,
29
- offset?: number
30
- }): Promise<any[]>;
31
-
32
- getOne(modelname: string, filter: Record<string, any>): Promise<any>;
33
-
34
- create(modelname: string, object: Record<string, any>): Promise<any>;
35
-
36
- insert(modelname: string, object: Record<string, any>): Promise<any>;
37
-
38
- update(modelname: string, filter: Record<string, any>, object: Record<string, any>): Promise<any>;
39
-
40
- delete(modelname: string, filter?: Record<string, any>): Promise<any>;
41
- }
1
+ export class MultiDbORM {
2
+ db: any;
3
+ dbType: string;
4
+ reqMade: number;
5
+ lastQLatency: any;
6
+ loglevel: number;
7
+ sync: import('../sync').Sync;
8
+ metrics: import('./metrics').Metrics;
9
+
10
+ constructor(db: any);
11
+
12
+ connect(): Promise<void>;
13
+
14
+ setdb(db: any): void;
15
+
16
+ getdb(): any;
17
+
18
+ get<T = any>(modelname: string, filter?: Record<string, any>, options?: {
19
+ apply?: {
20
+ field: string,
21
+ sort: string,
22
+ ineq: {
23
+ op: '>=' | '<=' | '=' | '>' | '<',
24
+ value: string | number | boolean
25
+ }
26
+ },
27
+ sort?: { field: string, order: 'asc' | 'desc' }[]
28
+ limit?: number,
29
+ offset?: number
30
+ }): Promise<T[]>;
31
+
32
+ getOne<T = any>(modelname: string, filter: Record<string, any>): Promise<T>;
33
+
34
+ create<T = any>(modelname: string, object: Record<string, any>): Promise<T>;
35
+
36
+ insert<T = any>(modelname: string, object: Record<string, any>): Promise<T>;
37
+
38
+ update<T = any>(modelname: string, filter: Record<string, any>, object: Record<string, any>): Promise<T>;
39
+
40
+ delete<T = any>(modelname: string, filter?: Record<string, any>): Promise<T>;
41
+ }
@@ -1,68 +1,68 @@
1
- const { Sync } = require('../sync')
2
- const { Metrics } = require('./metrics')
3
- class MultiDbORM {
4
-
5
- db
6
- dbType
7
- reqMade
8
- lastQLatency
9
- loglevel = 0
10
- sync
11
- metrics
12
-
13
- constructor(db) {
14
- this.db = db
15
- this.sync = new Sync()
16
- this.metrics = new Metrics(this.loglevel)
17
- }
18
-
19
- async connect() {
20
-
21
- }
22
-
23
- setdb(db) {
24
- this.reqMade = 0
25
- this.db = db;
26
- }
27
-
28
- getdb() {
29
- this.reqMade++
30
- return this.db;
31
- }
32
-
33
- async get(modelname, filter) {
34
- if (this.loglevel > 4)
35
- console.log("Not implemented")
36
- }
37
-
38
- async getOne(modelname, filter) {
39
- if (this.loglevel > 4)
40
- console.log("Not implemented")
41
- }
42
-
43
- async create(modelname, object) {
44
- if (this.loglevel > 4)
45
- console.log("Not implemented")
46
- }
47
-
48
- async insert(modelname, object) {
49
- if (this.loglevel > 4)
50
- console.log("Not implemented")
51
- }
52
-
53
- async update(modelname, filter, object) {
54
- if (this.loglevel > 4)
55
- console.log("Not implemented")
56
- }
57
-
58
- async delete(modelname, filter) {
59
- if (this.loglevel > 4)
60
- console.log("Not implemented")
61
- }
62
-
63
- }
64
-
65
-
66
- module.exports = {
67
- MultiDbORM: MultiDbORM
1
+ const { Sync } = require('../sync')
2
+ const { Metrics } = require('./metrics')
3
+ class MultiDbORM {
4
+
5
+ db
6
+ dbType
7
+ reqMade
8
+ lastQLatency
9
+ loglevel = 0
10
+ sync
11
+ metrics
12
+
13
+ constructor(db) {
14
+ this.db = db
15
+ this.sync = new Sync()
16
+ this.metrics = new Metrics(this.loglevel)
17
+ }
18
+
19
+ async connect() {
20
+
21
+ }
22
+
23
+ setdb(db) {
24
+ this.reqMade = 0
25
+ this.db = db;
26
+ }
27
+
28
+ getdb() {
29
+ this.reqMade++
30
+ return this.db;
31
+ }
32
+
33
+ async get(modelname, filter) {
34
+ if (this.loglevel > 4)
35
+ console.log("Not implemented")
36
+ }
37
+
38
+ async getOne(modelname, filter) {
39
+ if (this.loglevel > 4)
40
+ console.log("Not implemented")
41
+ }
42
+
43
+ async create(modelname, object) {
44
+ if (this.loglevel > 4)
45
+ console.log("Not implemented")
46
+ }
47
+
48
+ async insert(modelname, object) {
49
+ if (this.loglevel > 4)
50
+ console.log("Not implemented")
51
+ }
52
+
53
+ async update(modelname, filter, object) {
54
+ if (this.loglevel > 4)
55
+ console.log("Not implemented")
56
+ }
57
+
58
+ async delete(modelname, filter) {
59
+ if (this.loglevel > 4)
60
+ console.log("Not implemented")
61
+ }
62
+
63
+ }
64
+
65
+
66
+ module.exports = {
67
+ MultiDbORM: MultiDbORM
68
68
  }
@@ -1,25 +1,25 @@
1
- import { MultiDbORM } from './multidb';
2
-
3
- export type MySQLDBConfig = {
4
- host: string;
5
- port: string;
6
- username: string;
7
- password: string;
8
- database: string;
9
- connectionLimit?: Number;
10
- connectTimeout?: Number;
11
- acquireTimeout?: Number;
12
- timeout?: Number;
13
- }
14
-
15
- export class MySQLDB extends MultiDbORM {
16
- db: typeof import('mysql')
17
- mysql: typeof import('mysql');
18
- connection: import('mysql').Connection;
19
-
20
- constructor(credentials: MySQLDBConfig);
21
-
22
- run(query: string): Promise<any[]>;
23
-
24
- closePool(): void;
25
- }
1
+ import { MultiDbORM } from './multidb';
2
+
3
+ export type MySQLDBConfig = {
4
+ host: string;
5
+ port: string;
6
+ username: string;
7
+ password: string;
8
+ database: string;
9
+ connectionLimit?: Number;
10
+ connectTimeout?: Number;
11
+ acquireTimeout?: Number;
12
+ timeout?: Number;
13
+ }
14
+
15
+ export class MySQLDB extends MultiDbORM {
16
+ db: typeof import('mysql')
17
+ mysql: typeof import('mysql');
18
+ connection: import('mysql').Connection;
19
+
20
+ constructor(credentials: MySQLDBConfig);
21
+
22
+ run(query: string): Promise<any[]>;
23
+
24
+ closePool(): void;
25
+ }
@@ -1,24 +1,24 @@
1
- import { MultiDbORM } from './multidb';
2
-
3
- export interface OracleDBConfig {
4
- username: string;
5
- password: string;
6
- net_service_name: string;
7
- wallet_dir: string;
8
- connection_pool_name?: string;
9
- wallet_password?: string;
10
- lib_dir?: string;
11
- }
12
-
13
- export declare class OracleDB extends MultiDbORM {
14
- db: typeof import('oracledb')
15
- connection_pool_name: string;
16
- schema: string;
17
- pool_creation: Promise<any>;
18
-
19
- constructor(config: OracleDBConfig);
20
-
21
- connect(): Promise<void>;
22
-
23
- run(query: string): Promise<any>;
24
- }
1
+ import { MultiDbORM } from './multidb';
2
+
3
+ export interface OracleDBConfig {
4
+ username: string;
5
+ password: string;
6
+ net_service_name: string;
7
+ wallet_dir: string;
8
+ connection_pool_name?: string;
9
+ wallet_password?: string;
10
+ lib_dir?: string;
11
+ }
12
+
13
+ export declare class OracleDB extends MultiDbORM {
14
+ db: typeof import('oracledb')
15
+ connection_pool_name: string;
16
+ schema: string;
17
+ pool_creation: Promise<any>;
18
+
19
+ constructor(config: OracleDBConfig);
20
+
21
+ connect(): Promise<void>;
22
+
23
+ run(query: string): Promise<any>;
24
+ }