<commit_before>var type = require('type');
var Schema = require('./schema');
var Store = require('./idb-store');
var Index = require('./idb-index');
var range = require('./range');

/**
 * `indexedDB` reference.
 */

var indexedDB = window.indexedDB
  || window.msIndexedDB
  || window.mozIndexedDB
  || window.webkitIndexedDB;

/**
 * Expose `Treo`.
 */

exports = module.exports = Treo;

/**
 * Initialize new `Treo` instance.
 *
 * @param {String} name
 * @param {Schema} schema
 */

function Treo(name, schema) {
  if (!(this instanceof Treo)) return new Treo(name, schema);
  if (type(name) != 'string') throw new TypeError('`name` required');
  if (!(schema instanceof Schema)) throw new TypeError('not valid schema');

  this.name = name;
  this.status = 'close';
  this.origin = null;
  this.stores = {};
  this.version = schema.getVersion();
  this.upgradeCallback = createUpgradeCallback(schema._versions);

  // setup stores and indexes
  Object.keys(schema._stores).forEach(function(storeName) {
    var s = schema._stores[storeName];
    var store = this.stores[storeName] = new Store(this, s.name, s.opts);
    Object.keys(s.indexes).forEach(function(indexName) {
      var i = s.indexes[indexName];
      store.indexes[indexName] = new Index(store, i.name, i.field, i.opts);
    });
  }, this);
}

/**
 * Expose core classes.
 */

exports.schema = Schema;
exports.range = range;
exports.cmp = cmp;
exports.Treo = Treo;
exports.Schema = Schema;
exports.Store = Store;
exports.Index = Index;

/**
 * Drop.
 *
 * @param {Function} cb
 */

Treo.prototype.drop = function(cb) {
  var name = this.name;
  this.close(function(err) {
    if (err) return cb(err);
    var req = indexedDB.deleteDatabase(name);
    req.onerror = cb;
    req.onsuccess = function onsuccess() { cb() };<commit_msg>add treo.use<commit_after>var type = require('type');
var Schema = require('./schema');
var Store = require('./idb-store');
var Index = require('./idb-index');
var range = require('./range');

/**
 * `indexedDB` reference.
 */

var indexedDB = window.indexedDB
  || window.msIndexedDB
  || window.mozIndexedDB
  || window.webkitIndexedDB;

/**
 * Expose `Treo`.
 */

exports = module.exports = Treo;

/**
 * Initialize new `Treo` instance.
 *
 * @param {String} name
 * @param {Schema} schema
 */

function Treo(name, schema) {
  if (!(this instanceof Treo)) return new Treo(name, schema);
  if (type(name) != 'string') throw new TypeError('`name` required');
  if (!(schema instanceof Schema)) throw new TypeError('not valid schema');

  this.name = name;
  this.status = 'close';
  this.origin = null;
  this.stores = {};
  this.version = schema.getVersion();
  this.upgradeCallback = createUpgradeCallback(schema._versions);

  // setup stores and indexes
  Object.keys(schema._stores).forEach(function(storeName) {
    var s = schema._stores[storeName];
    var store = this.stores[storeName] = new Store(this, s.name, s.opts);
    Object.keys(s.indexes).forEach(function(indexName) {
      var i = s.indexes[indexName];
      store.indexes[indexName] = new Index(store, i.name, i.field, i.opts);
    });
  }, this);
}

/**
 * Expose core classes.
 */

exports.schema = Schema;
exports.range = range;
exports.cmp = cmp;
exports.Treo = Treo;
exports.Schema = Schema;
exports.Store = Store;
exports.Index = Index;

/**
 * Use the given plugin `fn(db, treo)`.
 *
 * @param {Function} fn
 * @return {Treo}
 */

Treo.prototype.use = function(fn) {
  fn(this, exports);
  return this;
};

/**
 * Drop.
 *
 * @param {Function} cb
 */

Treo.prototype.drop = function(cb) {
  var name = this.name;
  this.close(function(err) {
    if (err) return cb(err);
    var req = indexedDB.deleteDatabase(name);
    req.onerror = cb;
    req.onsuccess = function onsuccess() { cb() };
{'fraction_non_alphanumeric': 0.16847970283894934, 'fraction_numerical': 0.0, 'mean_word_length': 3.6600741656365883, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6289467', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1259, 'n_words': 302}