<commit_before>const Stream = require('stream')
const util = require('util')
const Promise = require('bluebird')
const map = require('map-stream')
const xtend = require('xtend')
const create = require('./lib/create')
const hasCallback = require('./lib/has-callback')
const callbackResolver = require('./lib/callback-resolver')
const fmt = util.format.bind(util)

const dbProto = {}
const tableProto = {}

dbProto.close = function close(callback) {
  return this.driver.close(this.connection, callback)
}

dbProto.table = function table(name, definition) {
  if (definition)
    return this.registerTable.apply(this, arguments)

  const tableDefinition = this.tables[name]
  if (!tableDefinition)
    throw new Error(fmt('No table registered with the name `%s`', name))
  return tableDefinition
}

dbProto.registerTable = function registerTable(name, def) {
  const fields = def.fields || []
  const primaryKey = def.primaryKey || 'id'

  if (fields.indexOf(primaryKey) === -1)
    fields.unshift(primaryKey)

  if (!def.hasOwnProperty('constructor')) {
    def.constructor = function createRow (data) {
      return create(table.row, data)
    }
  }

  const table = create(tableProto, {
    table: def.tableName || name,
    primaryKey: primaryKey,
    fields: fields,
    row: def.methods || {},
    constructor: def.constructor,
    relationships: def.relationships || {},
    db: this,
  })

  this.tables[name] = table
  return table
}

tableProto.put = function put(row, callback) {
  const resolver = hasCallback(arguments)
    ? callbackResolver(callback, this)
    : Promise.defer()

  const table = this.table
  const primaryKey = this.primaryKey<commit_msg>Expose `methods` from table definition<commit_after>const Stream = require('stream')
const util = require('util')
const Promise = require('bluebird')
const map = require('map-stream')
const xtend = require('xtend')
const create = require('./lib/create')
const hasCallback = require('./lib/has-callback')
const callbackResolver = require('./lib/callback-resolver')
const fmt = util.format.bind(util)

const dbProto = {}
const tableProto = {}

dbProto.close = function close(callback) {
  return this.driver.close(this.connection, callback)
}

dbProto.table = function table(name, definition) {
  if (definition)
    return this.registerTable.apply(this, arguments)

  const tableDefinition = this.tables[name]
  if (!tableDefinition)
    throw new Error(fmt('No table registered with the name `%s`', name))
  return tableDefinition
}

dbProto.registerTable = function registerTable(name, def) {
  const fields = def.fields || []
  const primaryKey = def.primaryKey || 'id'

  if (fields.indexOf(primaryKey) === -1)
    fields.unshift(primaryKey)

  if (!def.hasOwnProperty('constructor')) {
    def.constructor = function createRow (data) {
      return create(table.row, data)
    }
  }

  const table = create(tableProto, {
    table: def.tableName || name,
    primaryKey: primaryKey,
    fields: fields,
    methods: def.methods || {},
    row: def.methods || {},
    constructor: def.constructor,
    relationships: def.relationships || {},
    db: this,
  })

  this.tables[name] = table
  return table
}

tableProto.put = function put(row, callback) {
  const resolver = hasCallback(arguments)
    ? callbackResolver(callback, this)
    : Promise.defer()

  const table = this.table
  const primaryKey = this.primaryKey
{'fraction_non_alphanumeric': 0.1317418213969938, 'fraction_numerical': 0.0005894488653109342, 'mean_word_length': 4.173780487804878, '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': '3118681', 'n_tokens_mistral': 999, 'n_tokens_neox': 988, 'n_words': 255}