@sdflc/backend-helpers 1.0.49 → 1.0.50

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,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -19,45 +8,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
19
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
20
9
  });
21
10
  };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
50
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
13
  };
52
14
  Object.defineProperty(exports, "__esModule", { value: true });
53
15
  exports.DataCache = void 0;
54
- var dataloader_1 = __importDefault(require("dataloader"));
55
- var redis_dataloader_1 = __importDefault(require("redis-dataloader"));
56
- var utils_1 = require("@sdflc/utils");
57
- var _1 = require(".");
58
- var DataCache = /** @class */ (function () {
59
- function DataCache(props) {
60
- var _a = props || {}, loaderFn = _a.loaderFn, keyPrefix = _a.keyPrefix, context = _a.context, buildKey = _a.buildKey, redisClient = _a.redisClient, table = _a.table;
16
+ const dataloader_1 = __importDefault(require("dataloader"));
17
+ const redis_dataloader_1 = __importDefault(require("redis-dataloader"));
18
+ const utils_1 = require("@sdflc/utils");
19
+ const _1 = require(".");
20
+ class DataCache {
21
+ constructor(props) {
22
+ const { loaderFn, keyPrefix, context, buildKey, redisClient, table } = props || {};
61
23
  if (!(props === null || props === void 0 ? void 0 : props.idField)) {
62
24
  props.idField = _1.FIELDS.ID;
63
25
  }
@@ -65,59 +27,49 @@ var DataCache = /** @class */ (function () {
65
27
  this.buildKey = typeof buildKey === 'function' ? buildKey : utils_1.buildKey;
66
28
  this.batchLoaderDefault = this.batchLoaderDefault.bind(this);
67
29
  this.redisDataLoader = redisClient ? (0, redis_dataloader_1.default)({ redis: redisClient }) : null;
68
- var fn = typeof loaderFn === 'function' ? loaderFn : this.batchLoaderDefault(props);
69
- var prefixToUse = (context === null || context === void 0 ? void 0 : context.keyPrefix) || keyPrefix || table;
30
+ const fn = typeof loaderFn === 'function' ? loaderFn : this.batchLoaderDefault(props);
31
+ const prefixToUse = (context === null || context === void 0 ? void 0 : context.keyPrefix) || keyPrefix || table;
70
32
  this.init(fn, prefixToUse, context);
71
33
  }
72
- DataCache.prototype.batchLoaderDefault = function (props) {
73
- var _this = this;
74
- var table = props.table, idField = props.idField, readAll = props.readAll, db = props.db;
34
+ batchLoaderDefault(props) {
35
+ const { table, idField, readAll, db } = props;
75
36
  if (!table) {
76
- throw Error("DataCache requires 'table' property to be setup");
37
+ throw Error(`DataCache requires 'table' property to be setup`);
77
38
  }
78
39
  else if (!idField && readAll == null) {
79
- throw Error("DataCache requires 'idField' or 'readAll' property to be setup");
40
+ throw Error(`DataCache requires 'idField' or 'readAll' property to be setup`);
80
41
  }
81
42
  else if (!db) {
82
- throw Error("DataCache requires 'db' property to be setup");
43
+ throw Error(`DataCache requires 'db' property to be setup`);
83
44
  }
84
- return function (ids) { return __awaiter(_this, void 0, void 0, function () {
85
- var resultItems, readCfg, dbItems;
86
- var _this = this;
87
- return __generator(this, function (_a) {
88
- switch (_a.label) {
89
- case 0:
90
- resultItems = [];
91
- readCfg = __assign(__assign({}, props), { buildKey: this.buildKey });
92
- if (!readAll) {
93
- readCfg.mapBy = idField;
94
- readCfg.whereIn = {
95
- field: idField,
96
- values: ids.filter(function (id) { return id; }),
97
- };
98
- }
99
- return [4 /*yield*/, db.read(readCfg)];
100
- case 1:
101
- dbItems = _a.sent();
102
- if (readAll) {
103
- resultItems.push.apply(resultItems, dbItems);
104
- }
105
- else {
106
- resultItems.push.apply(resultItems, ids.map(function (id) { return dbItems[_this.buildKey(id)] || null; }));
107
- }
108
- return [2 /*return*/, resultItems];
109
- }
110
- });
111
- }); };
112
- };
113
- DataCache.prototype.init = function (batchFunction, keyPrefix, context) {
45
+ return (ids) => __awaiter(this, void 0, void 0, function* () {
46
+ const resultItems = [];
47
+ const readCfg = Object.assign(Object.assign({}, props), { buildKey: this.buildKey });
48
+ if (!readAll) {
49
+ readCfg.mapBy = idField;
50
+ readCfg.whereIn = {
51
+ field: idField,
52
+ values: ids.filter((id) => id),
53
+ };
54
+ }
55
+ const dbItems = yield db.read(readCfg);
56
+ if (readAll) {
57
+ resultItems.push(...dbItems);
58
+ }
59
+ else {
60
+ resultItems.push(...ids.map((id) => dbItems[this.buildKey(id)] || null));
61
+ }
62
+ return resultItems;
63
+ });
64
+ }
65
+ init(batchFunction, keyPrefix, context) {
114
66
  if (this.redisDataLoader) {
115
67
  this.loader = new this.redisDataLoader(
116
68
  // set a prefix for the keys stored in redis. This way you can avoid key
117
69
  // collisions for different data-sets in your redis instance.
118
70
  keyPrefix,
119
71
  // create a regular dataloader. This should always be set with caching disabled.
120
- new dataloader_1.default(function (ids) { return batchFunction(ids, context); }, {
72
+ new dataloader_1.default((ids) => batchFunction(ids, context), {
121
73
  cache: false,
122
74
  }), {
123
75
  cache: true,
@@ -125,26 +77,23 @@ var DataCache = /** @class */ (function () {
125
77
  });
126
78
  }
127
79
  else {
128
- this.loader = new dataloader_1.default(function (ids) { return batchFunction(ids, context); });
80
+ this.loader = new dataloader_1.default((ids) => batchFunction(ids, context));
129
81
  }
130
- };
131
- DataCache.prototype.load = function (key) {
82
+ }
83
+ load(key) {
132
84
  return this.loader.load(this.buildKey(key));
133
- };
134
- DataCache.prototype.loadMany = function (keys) {
135
- var _this = this;
136
- return this.loader.loadMany(keys.map(function (key) { return _this.buildKey(key); }));
137
- };
138
- DataCache.prototype.clear = function (key) {
139
- var _this = this;
85
+ }
86
+ loadMany(keys) {
87
+ return this.loader.loadMany(keys.map((key) => this.buildKey(key)));
88
+ }
89
+ clear(key) {
140
90
  var _a;
141
91
  if (Array.isArray(key)) {
142
- key.forEach(function (item) { var _a; return (_a = _this.loader) === null || _a === void 0 ? void 0 : _a.clear(_this.buildKey(item)); });
92
+ key.forEach((item) => { var _a; return (_a = this.loader) === null || _a === void 0 ? void 0 : _a.clear(this.buildKey(item)); });
143
93
  }
144
94
  else {
145
95
  (_a = this.loader) === null || _a === void 0 ? void 0 : _a.clear(this.buildKey(key));
146
96
  }
147
- };
148
- return DataCache;
149
- }());
97
+ }
98
+ }
150
99
  exports.DataCache = DataCache;
package/build/Database.js CHANGED
@@ -8,43 +8,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
13
  };
41
14
  Object.defineProperty(exports, "__esModule", { value: true });
42
15
  exports.Database = void 0;
43
- var lodash_1 = require("lodash");
44
- var knex_1 = __importDefault(require("knex"));
45
- var utils_1 = require("@sdflc/utils");
46
- var Database = /** @class */ (function () {
47
- function Database(props) {
16
+ const lodash_1 = require("lodash");
17
+ const knex_1 = __importDefault(require("knex"));
18
+ const utils_1 = require("@sdflc/utils");
19
+ class Database {
20
+ constructor(props) {
48
21
  this.trx = null;
49
22
  this.knexHandle = null;
50
23
  this.dbSchema = '';
@@ -55,159 +28,114 @@ var Database = /** @class */ (function () {
55
28
  this.dbSchema = props.dbSchema || '';
56
29
  this.trx = props.trx;
57
30
  }
58
- Database.prototype.destroy = function () {
31
+ destroy() {
59
32
  if (this.knexHandle) {
60
33
  this.knexHandle.destroy();
61
34
  }
62
- };
63
- Database.prototype.isDbError = function (ex) {
64
- var code = (ex || {}).code;
35
+ }
36
+ isDbError(ex) {
37
+ const { code } = ex || {};
65
38
  switch (code) {
66
39
  default:
67
40
  return [false, ''];
68
41
  case '23505':
69
- return [true, "Such item already exists"];
42
+ return [true, `Such item already exists`];
70
43
  }
71
- };
72
- Database.prototype.createTransaction = function (trx) {
73
- var _this = this;
74
- return new Promise(function (resolve) {
75
- return (trx ? trx : _this.knexHandle).transaction(resolve);
44
+ }
45
+ createTransaction(trx) {
46
+ return new Promise((resolve) => {
47
+ return (trx ? trx : this.knexHandle).transaction(resolve);
76
48
  });
77
- };
78
- Database.prototype.getSchema = function () {
49
+ }
50
+ getSchema() {
79
51
  return this.dbSchema;
80
- };
81
- Database.prototype.getBuilder = function (arg) {
52
+ }
53
+ getBuilder(arg) {
82
54
  return this.trx ? this.trx(arg).withSchema(this.getSchema()) : this.knexHandle(arg).withSchema(this.getSchema());
83
- };
84
- Database.prototype.raw = function (query, bindings) {
55
+ }
56
+ raw(query, bindings) {
85
57
  return this.knexHandle.raw(query, bindings);
86
- };
87
- Database.prototype.runRawQuery = function (query, bindings) {
88
- return __awaiter(this, void 0, void 0, function () {
89
- var rows;
90
- return __generator(this, function (_a) {
91
- switch (_a.label) {
92
- case 0: return [4 /*yield*/, (this.trx ? this.trx : this.knexHandle).raw(query, bindings)];
93
- case 1:
94
- rows = _a.sent();
95
- return [2 /*return*/, rows];
96
- }
97
- });
58
+ }
59
+ runRawQuery(query, bindings) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ const rows = yield (this.trx ? this.trx : this.knexHandle).raw(query, bindings);
62
+ return rows;
98
63
  });
99
- };
100
- Database.prototype.startTransaction = function () {
101
- return __awaiter(this, void 0, void 0, function () {
102
- var trx;
103
- return __generator(this, function (_a) {
104
- switch (_a.label) {
105
- case 0: return [4 /*yield*/, this.createTransaction(this.trx)];
106
- case 1:
107
- trx = _a.sent();
108
- this.trx = trx;
109
- return [2 /*return*/, trx];
110
- }
111
- });
64
+ }
65
+ startTransaction() {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const trx = yield this.createTransaction(this.trx);
68
+ this.trx = trx;
69
+ return trx;
112
70
  });
113
- };
114
- Database.prototype.setTransaction = function (trx) {
71
+ }
72
+ setTransaction(trx) {
115
73
  this.trx = trx;
116
- };
117
- Database.prototype.commitTransaction = function () {
118
- return __awaiter(this, void 0, void 0, function () {
119
- return __generator(this, function (_a) {
120
- switch (_a.label) {
121
- case 0:
122
- if (!this.trx) return [3 /*break*/, 2];
123
- return [4 /*yield*/, this.trx.commit()];
124
- case 1:
125
- _a.sent();
126
- this.trx = undefined;
127
- _a.label = 2;
128
- case 2: return [2 /*return*/];
129
- }
130
- });
74
+ }
75
+ commitTransaction() {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ if (this.trx) {
78
+ yield this.trx.commit();
79
+ this.trx = undefined;
80
+ }
131
81
  });
132
- };
133
- Database.prototype.rollbackTransaction = function () {
134
- return __awaiter(this, void 0, void 0, function () {
135
- var ex_1;
136
- return __generator(this, function (_a) {
137
- switch (_a.label) {
138
- case 0:
139
- if (!this.trx) return [3 /*break*/, 4];
140
- _a.label = 1;
141
- case 1:
142
- _a.trys.push([1, 3, , 4]);
143
- return [4 /*yield*/, this.trx.rollback()];
144
- case 2:
145
- _a.sent();
146
- return [3 /*break*/, 4];
147
- case 3:
148
- ex_1 = _a.sent();
149
- return [3 /*break*/, 4];
150
- case 4:
151
- this.trx = undefined;
152
- return [2 /*return*/];
82
+ }
83
+ rollbackTransaction() {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ if (this.trx) {
86
+ try {
87
+ yield this.trx.rollback();
153
88
  }
154
- });
89
+ catch (ex) {
90
+ // Do nothing here
91
+ }
92
+ }
93
+ this.trx = undefined;
155
94
  });
156
- };
157
- Database.prototype.doCalculated = function (item, calculatedFields) {
158
- calculatedFields.forEach(function (calcField) {
95
+ }
96
+ doCalculated(item, calculatedFields) {
97
+ calculatedFields.forEach((calcField) => {
159
98
  if (calcField.name) {
160
99
  item[calcField.name] = typeof calcField.value === 'function' ? calcField.value(item) : calcField.value;
161
100
  }
162
101
  });
163
- };
164
- Database.prototype.read = function (args) {
165
- return __awaiter(this, void 0, void 0, function () {
166
- var _a, where, whereIn, extendQuery, table, selectFields, mapBy, calculated, buildKey, query, dbResults, fnBuildKey_1;
167
- var _this = this;
168
- return __generator(this, function (_b) {
169
- switch (_b.label) {
170
- case 0:
171
- _a = args || {}, where = _a.where, whereIn = _a.whereIn, extendQuery = _a.extendQuery, table = _a.table, selectFields = _a.selectFields, mapBy = _a.mapBy, calculated = _a.calculated, buildKey = _a.buildKey;
172
- query = this.getBuilder(table).select(Array.isArray(selectFields) && selectFields.length > 0 ? selectFields : '*');
173
- if (where) {
174
- query.where(where);
175
- }
176
- if (whereIn) {
177
- query.whereIn(whereIn.field, whereIn.values);
178
- }
179
- if (!(typeof extendQuery === 'function')) return [3 /*break*/, 2];
180
- return [4 /*yield*/, extendQuery(query)];
181
- case 1:
182
- _b.sent();
183
- _b.label = 2;
184
- case 2: return [4 /*yield*/, query];
185
- case 3:
186
- dbResults = _b.sent();
187
- if (mapBy) {
188
- fnBuildKey_1 = typeof buildKey === 'function' ? buildKey : utils_1.buildKey;
189
- dbResults = dbResults.reduce(function (acc, item) {
190
- var key = fnBuildKey_1(item[(0, lodash_1.camelCase)(mapBy)]);
191
- if (Array.isArray(calculated) && calculated.length > 0) {
192
- _this.doCalculated(item, calculated);
193
- }
194
- acc[key] = item;
195
- return acc;
196
- }, {});
197
- }
198
- else {
199
- if (Array.isArray(calculated) && calculated.length > 0) {
200
- dbResults.forEach(function (row) {
201
- _this.doCalculated(row, calculated);
202
- });
203
- }
204
- }
205
- return [2 /*return*/, dbResults];
102
+ }
103
+ read(args) {
104
+ return __awaiter(this, void 0, void 0, function* () {
105
+ const { where, whereIn, extendQuery, table, selectFields, mapBy, calculated, buildKey } = args || {};
106
+ const query = this.getBuilder(table).select(Array.isArray(selectFields) && selectFields.length > 0 ? selectFields : '*');
107
+ if (where) {
108
+ query.where(where);
109
+ }
110
+ if (whereIn) {
111
+ query.whereIn(whereIn.field, whereIn.values);
112
+ }
113
+ if (typeof extendQuery === 'function') {
114
+ yield extendQuery(query);
115
+ }
116
+ let dbResults = yield query;
117
+ if (mapBy) {
118
+ const fnBuildKey = typeof buildKey === 'function' ? buildKey : utils_1.buildKey;
119
+ dbResults = dbResults.reduce((acc, item) => {
120
+ const key = fnBuildKey(item[(0, lodash_1.camelCase)(mapBy)]);
121
+ if (Array.isArray(calculated) && calculated.length > 0) {
122
+ this.doCalculated(item, calculated);
123
+ }
124
+ acc[key] = item;
125
+ return acc;
126
+ }, {});
127
+ }
128
+ else {
129
+ if (Array.isArray(calculated) && calculated.length > 0) {
130
+ dbResults.forEach((row) => {
131
+ this.doCalculated(row, calculated);
132
+ });
206
133
  }
207
- });
134
+ }
135
+ return dbResults;
208
136
  });
209
- };
210
- Database.prototype.createSortBy = function (sortBy, defaultSortBy) {
137
+ }
138
+ createSortBy(sortBy, defaultSortBy) {
211
139
  if (!sortBy) {
212
140
  if (Array.isArray(defaultSortBy)) {
213
141
  return this.createSortBy(defaultSortBy);
@@ -216,32 +144,31 @@ var Database = /** @class */ (function () {
216
144
  return null;
217
145
  }
218
146
  }
219
- return sortBy.reduce(function (acc, item) {
147
+ return sortBy.reduce((acc, item) => {
220
148
  acc.push({
221
149
  column: item.name,
222
150
  order: item.order,
223
151
  });
224
152
  return acc;
225
153
  }, []);
226
- };
227
- Database.prototype.createLimitOffset = function (page, pageSize) {
228
- var limit = isNaN(pageSize) || pageSize == null ? undefined : Number(pageSize);
229
- var pageToUse = isNaN(page) || page < 1 ? 1 : Number(page);
154
+ }
155
+ createLimitOffset(page, pageSize) {
156
+ const limit = isNaN(pageSize) || pageSize == null ? undefined : Number(pageSize);
157
+ const pageToUse = isNaN(page) || page < 1 ? 1 : Number(page);
230
158
  return {
231
- limit: limit,
159
+ limit,
232
160
  offset: limit ? (pageToUse - 1) * limit : 0,
233
161
  };
234
- };
235
- Database.prototype.createLimitOffsetSortBy = function (pagination, defaultSortBy) {
236
- var _a = pagination || {}, page = _a.page, pageSize = _a.pageSize, sortBy = _a.sortBy;
237
- var _b = this.createLimitOffset(page, pageSize), limit = _b.limit, offset = _b.offset;
238
- var sortByToUse = this.createSortBy(sortBy, defaultSortBy);
162
+ }
163
+ createLimitOffsetSortBy(pagination, defaultSortBy) {
164
+ const { page, pageSize, sortBy } = pagination || {};
165
+ const { limit, offset } = this.createLimitOffset(page, pageSize);
166
+ const sortByToUse = this.createSortBy(sortBy, defaultSortBy);
239
167
  return {
240
- limit: limit,
241
- offset: offset,
168
+ limit,
169
+ offset,
242
170
  sortBy: sortByToUse,
243
171
  };
244
- };
245
- return Database;
246
- }());
172
+ }
173
+ }
247
174
  exports.Database = Database;