<commit_before>'use strict';
import extend from 'extend';
import all from './util/all';
import Connection from './connection';
import ArrayCursor from './cursor';
import Graph from './graph';
import constructCollection, {
  DocumentCollection,
  EdgeCollection
} from './collection';

export default class Database {
  constructor(config) {
    this._connection = new Connection(config);
    this._api = this._connection.route('_api');
    this.name = this._connection.config.databaseName;
  }

  route(path, headers) {
    return this._connection.route(path, headers);
  }

  // Database manipulation

  useDatabase(databaseName) {
    this._connection.config.databaseName = databaseName;
    this.name = databaseName;
  }

  get(cb) {
    const {promise, callback} = this._connection.promisify(cb);
    this._api.get(
      'database/current',
      (err, res) => err ? callback(err) : callback(null, res.body.result)
    );
    return promise;
  }

  createDatabase(databaseName, users, cb) {
    if (typeof users === 'function') {
      cb = users;
      users = undefined;
    }
    const {promise, callback} = this._connection.promisify(cb);
    this._api.post(
      'database',
      {users, name: databaseName},
      (err, res) => err ? callback(err) : callback(null, res.body)
    );
    return promise;
  }

  listDatabases(cb) {
    const {promise, callback} = this._connection.promisify(cb);
    this._api.get(
      'database',
      (err, res) => err ? callback(err) : callback(null, res.body.result)
    );
    return promise;
  }

  listUserDatabases(cb) {
    const {promise, callback} = this._connection.promisify(cb);
    this._api.get(
      'database/user',
      (err, res) => err ? callback(err) : callback(null, res.body.result)
    );
    return promise;
  }

  dropDatabase(databaseName, cb) {
    const {promise, callback} = this._connection.promisify(cb);
    this._api.delete(
      `database/${databaseName}`,
      (err, res) => err ? callback(err) : callback(null, res.body)
    );
    return promise;
  }

  // Collection manipulation

  collection(collectionName) {
    return new DocumentCollection(this._connection, collectionName);
  }

  edgeCollection(collectionName) {
    return new EdgeCollection(this._connection, collectionName);
  }

  listCollections(excludeSystem, cb) {
    if (typeof excludeSystem === 'function') {
      cb = excludeSystem;
      excludeSystem = undefined;
    }
    const {promise, callback} = this._connection.promisify(cb);
    if (typeof excludeSystem !== 'boolean') excludeSystem = true;
    this._api.get(
      'collection',
      {excludeSystem},
      (err, res) => err ? callback(err) : callback(null, res.body.collections)
    );
    return promise;
  }

  collections(excludeSystem, cb) {
    const {promise, callback} = this._connection.promisify(cb);
    this.listCollections(
      excludeSystem,
      (err, collections) => (
        err
        ? callback(err)
        : callback(collections.map(info => constructCollection(this._connection, info)))
      )
    );
    return promise;<commit_msg>Fixed collections callback call<commit_after>'use strict';
import extend from 'extend';
import all from './util/all';
import Connection from './connection';
import ArrayCursor from './cursor';
import Graph from './graph';
import constructCollection, {
  DocumentCollection,
  EdgeCollection
} from './collection';

export default class Database {
  constructor(config) {
    this._connection = new Connection(config);
    this._api = this._connection.route('_api');
    this.name = this._connection.config.databaseName;
  }

  route(path, headers) {
    return this._connection.route(path, headers);
  }

  // Database manipulation

  useDatabase(databaseName) {
    this._connection.config.databaseName = databaseName;
    this.name = databaseName;
  }

  get(cb) {
    const {promise, callback} = this._connection.promisify(cb);
    this._api.get(
      'database/current',
      (err, res) => err ? callback(err) : callback(null, res.body.result)
    );
    return promise;
  }

  createDatabase(databaseName, users, cb) {
    if (typeof users === 'function') {
      cb = users;
      users = undefined;
    }
    const {promise, callback} = this._connection.promisify(cb);
    this._api.post(
      'database',
      {users, name: databaseName},
      (err, res) => err ? callback(err) : callback(null, res.body)
    );
    return promise;
  }

  listDatabases(cb) {
    const {promise, callback} = this._connection.promisify(cb);
    this._api.get(
      'database',
      (err, res) => err ? callback(err) : callback(null, res.body.result)
    );
    return promise;
  }

  listUserDatabases(cb) {
    const {promise, callback} = this._connection.promisify(cb);
    this._api.get(
      'database/user',
      (err, res) => err ? callback(err) : callback(null, res.body.result)
    );
    return promise;
  }

  dropDatabase(databaseName, cb) {
    const {promise, callback} = this._connection.promisify(cb);
    this._api.delete(
      `database/${databaseName}`,
      (err, res) => err ? callback(err) : callback(null, res.body)
    );
    return promise;
  }

  // Collection manipulation

  collection(collectionName) {
    return new DocumentCollection(this._connection, collectionName);
  }

  edgeCollection(collectionName) {
    return new EdgeCollection(this._connection, collectionName);
  }

  listCollections(excludeSystem, cb) {
    if (typeof excludeSystem === 'function') {
      cb = excludeSystem;
      excludeSystem = undefined;
    }
    const {promise, callback} = this._connection.promisify(cb);
    if (typeof excludeSystem !== 'boolean') excludeSystem = true;
    this._api.get(
      'collection',
      {excludeSystem},
      (err, res) => err ? callback(err) : callback(null, res.body.collections)
    );
    return promise;
  }

  collections(excludeSystem, cb) {
    const {promise, callback} = this._connection.promisify(cb);
    this.listCollections(
      excludeSystem,
      (err, collections) => (
        err
        ? callback(err)
        : callback(null, collections.map(info => constructCollection(this._connection, info)))
      )
    );
    return promise;
{'fraction_non_alphanumeric': 0.13493859082094375, 'fraction_numerical': 0.0, 'mean_word_length': 3.1789331532748144, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '1496213', 'n_tokens_mistral': 1859, 'n_tokens_neox': 1833, 'n_words': 405}