<commit_before>import * as _ from 'lodash';
import { AqlQuery } from 'arangojs/lib/cjs/aql-query';
import * as Long from 'long';

/**
 * Ensure that the collection exists and process the query
 * @param {Object} db arangodb connection
 * @param {string} collectionName collection name
 * @param {string} query query string
 * @param {Object} args list of arguments, optional
 * @return {Promise} arangojs query result
 */
export async function query(db: any, collectionName: string, query: string | AqlQuery,
  args?: Object): Promise<any> {
  try {
    return await db.query(query, args);
  } catch (err) {
    if (err.message && err.message.indexOf('collection or view not found') == -1) {
      throw err;
    }
  }
  const collection = db.collection(collectionName);
  await collection.create();
  await collection.load(false);
  return db.query(query, args);
}

/**
 * Convert id to arangodb friendly key.
 * @param {string} id document identification
 * @return {any} arangodb friendly key<commit_msg>revert<commit_after>import * as _ from 'lodash';
import { AqlQuery } from 'arangojs/lib/cjs/aql-query';
import * as Long from 'long';

/**
 * Ensure that the collection exists and process the query
 * @param {Object} db arangodb connection
 * @param {string} collectionName collection name
 * @param {string} query query string
 * @param {Object} args list of arguments, optional
 * @return {Promise} arangojs query result
 */
export async function query(db: any, collectionName: string, query: string | AqlQuery,
  args?: Object): Promise<any> {
  try {
    return await db.query(query, args);
  } catch (err) {
    if (err.message && err.message.indexOf('collection not found') == -1) {
      throw err;
    }
  }
  const collection = db.collection(collectionName);
  await collection.create();
  await collection.load(false);
  return db.query(query, args);
}

/**
 * Convert id to arangodb friendly key.
 * @param {string} id document identification
 * @return {any} arangodb friendly key
{'fraction_non_alphanumeric': 0.12206103051525763, 'fraction_numerical': 0.0010005002501250625, 'mean_word_length': 4.115089514066496, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3209760', 'n_tokens_mistral': 596, 'n_tokens_neox': 593, 'n_words': 207}