<commit_before>
import Rx = require('rx');
import mongodb = require('mongodb');

import {IAuthToken} from "../../contracts/common";

import {IRefreshToken,IUserToken} from "../../contracts/node";

export class DataBaseConnection{
	private _tokenCollectionName = process.env.TOKEN_COLLECTION_NAME;
	private _dbConnection: mongodb.Db;

	public createConnection(): Rx.Observable<boolean>{

		console.log(`DATABASE_CONNECTION: connecting to database ${process.env.MONGODB_URI}`);
		console.log(`DATABASE_CONNECTION: using collection ${this._tokenCollectionName} to store tokens`);
		var createConnection = Rx.Observable.fromNodeCallback<mongodb.Db>(mongodb.MongoClient.connect);

		return createConnection(process.env.MONGODB_URI)
			.doOnError(error => this.handleConnectionError(error))
			.do(db => {
				console.log("DATABASE_CONNECTION: Database connection ready");
				this._dbConnection = db;
			})
			.map(() => true);
	}

	public storeRefreshToken(tokens: IUserToken): Rx.Observable<IAuthToken>{
		const refreshTokens: IRefreshToken = <any>tokens;

		if( refreshTokens.refresh_token != null ){
			return this.removeExistingRowsForUser(tokens)
				.flatMap(() => this.insertRow(refreshTokens));
		}
		else {
			console.log(`DATABASE_CONNECTION: no refresh token found. No database record update.`);
			return this.getUserTokens(tokens)
		}
	}

	public getRefreshToken(id: string): Rx.Observable<IRefreshToken>{
		console.log(`DATABASE_CONNECTION: getting refresh token with id ${id}`);

		const collection = this._dbConnection.collection(this._tokenCollectionName);

		const find = collection.find({ _id: new mongodb.ObjectID(id) });<commit_msg>minor logging improvement<commit_after>
import Rx = require('rx');
import mongodb = require('mongodb');

import {IAuthToken} from "../../contracts/common";

import {IRefreshToken,IUserToken} from "../../contracts/node";

export class DataBaseConnection{
	private _tokenCollectionName = process.env.TOKEN_COLLECTION_NAME;
	private _dbConnection: mongodb.Db;

	public createConnection(): Rx.Observable<boolean>{

		console.log(`DATABASE_CONNECTION: connecting to database ${process.env.MONGODB_URI}`);
		console.log(`DATABASE_CONNECTION: using collection '${this._tokenCollectionName}' to store tokens`);
		var createConnection = Rx.Observable.fromNodeCallback<mongodb.Db>(mongodb.MongoClient.connect);

		return createConnection(process.env.MONGODB_URI)
			.doOnError(error => this.handleConnectionError(error))
			.do(db => {
				console.log("DATABASE_CONNECTION: Database connection ready");
				this._dbConnection = db;
			})
			.map(() => true);
	}

	public storeRefreshToken(tokens: IUserToken): Rx.Observable<IAuthToken>{
		const refreshTokens: IRefreshToken = <any>tokens;

		if( refreshTokens.refresh_token != null ){
			return this.removeExistingRowsForUser(tokens)
				.flatMap(() => this.insertRow(refreshTokens));
		}
		else {
			console.log(`DATABASE_CONNECTION: no refresh token found. No database record update.`);
			return this.getUserTokens(tokens)
		}
	}

	public getRefreshToken(id: string): Rx.Observable<IRefreshToken>{
		console.log(`DATABASE_CONNECTION: getting refresh token with id ${id}`);

		const collection = this._dbConnection.collection(this._tokenCollectionName);

		const find = collection.find({ _id: new mongodb.ObjectID(id) });
{'fraction_non_alphanumeric': 0.1286231884057971, 'fraction_numerical': 0.0, 'mean_word_length': 5.58648111332008, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, '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': '4914493', 'n_tokens_mistral': 1089, 'n_tokens_neox': 1005, 'n_words': 206}