<commit_before>import {IData} from './data';
import {Db} from '@types/mongodb';

export abstract class DataLoader {

  private db: Db;
  private data: IData;

  // constructor
  constructor(db: Db, data: IData) {
    this.db = db;
    this.data = data;
    this.prepareData();
  }

  // main
  prepareData() {
    console.log('\nPrepare collection ' + this.getCollectionName() + ':');
    this.drop();
    this.insert(this.data.getData());
  }

  // drop collection
  drop() {
    this.db.collection(this.getCollectionName()).drop(() => {
      console.log('- Drop collection ' + this.getCollectionName());
    });
  }

  // insert data
  insert(data) {
    this.db.collection(this.getCollectionName()).insert(data, () => {
      data.forEach((obj) => {
        console.log('+ ' + this.getCollectionName() + ' added as ' + obj.name);
      });
    });
  }

  // get Collection Name
  abstract getCollectionName(): string;
}<commit_msg>Avoid deprecated method<commit_after>import {IData} from './data';
import {Db} from '@types/mongodb';

export abstract class DataLoader {

  private db: Db;
  private data: IData;

  // constructor
  constructor(db: Db, data: IData) {
    this.db = db;
    this.data = data;
    this.prepareData();
  }

  // main
  prepareData() {
    console.log('\nPrepare collection ' + this.getCollectionName() + ':');
    this.drop();
    this.insert(this.data.getData());
  }

  // drop collection
  drop() {
    this.db.collection(this.getCollectionName()).drop(() => {
      console.log('- Drop collection ' + this.getCollectionName());
    });
  }

  // insert data
  insert(data) {
    this.db.collection(this.getCollectionName()).insertMany(data, () => {
      data.forEach((obj) => {
        console.log('+ ' + this.getCollectionName() + ' added as ' + obj.name);
      });
    });
  }

  // get Collection Name
  abstract getCollectionName(): string;
}
{'fraction_non_alphanumeric': 0.1751592356687898, 'fraction_numerical': 0.0, 'mean_word_length': 2.9026915113871636, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5429536', 'n_tokens_mistral': 612, 'n_tokens_neox': 593, 'n_words': 120}