UNPKG

2.14 kBJavaScriptView Raw
1"use strict";
2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4 return new (P || (P = Promise))(function (resolve, reject) {
5 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8 step((generator = generator.apply(thisArg, _arguments || [])).next());
9 });
10};
11Object.defineProperty(exports, "__esModule", { value: true });
12const common_1 = require("../common");
13/**
14 * Allows to import collections into database.
15 */
16class CollectionImporter {
17 /**
18 * Constructs new `CollectionImporter` instance.
19 *
20 * @param db Database object
21 * @param collectionInsertManyOptions Optional MongoDB Collection InsertMany Options
22 */
23 constructor(db, collectionInsertManyOptions) {
24 this.db = db;
25 this.collectionInsertManyOptions = collectionInsertManyOptions;
26 }
27 /**
28 * Imports multiple collections into database.
29 *
30 * @param collections Array of collections
31 */
32 import(collections) {
33 return __awaiter(this, void 0, void 0, function* () {
34 for (const collection of collections) {
35 yield this.importCollection(collection);
36 }
37 });
38 }
39 /**
40 * Imports single collection into database.
41 *
42 * @param collection Collection definition
43 */
44 importCollection(collection) {
45 return __awaiter(this, void 0, void 0, function* () {
46 common_1.log(`Inserting ${collection.documents.length} documents into collection ${collection.name}...`);
47 return this.db.insertDocumentsIntoCollection(collection.documents, collection.name, this.collectionInsertManyOptions);
48 });
49 }
50}
51exports.CollectionImporter = CollectionImporter;
52//# sourceMappingURL=index.js.map
\No newline at end of file