<commit_before>var Key = require("./Key")
  , Attributes = require("./Attributes")
  , Update = require("./Update")

function Item(key, table, database) {
  Object.defineProperty(
    this, "database",
    {value: database, enumerable: false}
  )

  if (key) this.Key = Key(key)
  if (table) this.TableName = table
}

Item.prototype = {
  get: function(attrs) {
    this.AttributesToGet = attrs

    return this
  },

  update: function(key, value) {
    var update = new Update(this.TableName, this.database)
    update.Key = this.Key

    if (!key) return update

    if (typeof key == "function") {
      key.call(update, update)
      return update
    }

    return update.put(key, value)
  },

  fetch: function(opts, cb) {
    if (typeof opts == "function") cb = opts, opts = {}

    var self = this
      , attrs = {}
      , data = {
          TableName: this.TableName,
          Key: this.Key
        }

    if (opts.consistent) data.ConsistentRead = true

    this.database.request(
      "GetItem",
      data,
      function(err, data) {
        if (err) return cb(err)

        if (!data.Item) return cb(new Error("Not found."))

        cb(null, Attributes.prototype.parse(data.Item))
      }
    )

    return this
  }
}

module.exports = Item<commit_msg>return empty instead of an error when no item is found. (#4)<commit_after>var Key = require("./Key")
  , Attributes = require("./Attributes")
  , Update = require("./Update")

function Item(key, table, database) {
  Object.defineProperty(
    this, "database",
    {value: database, enumerable: false}
  )

  if (key) this.Key = Key(key)
  if (table) this.TableName = table
}

Item.prototype = {
  get: function(attrs) {
    this.AttributesToGet = attrs

    return this
  },

  update: function(key, value) {
    var update = new Update(this.TableName, this.database)
    update.Key = this.Key

    if (!key) return update

    if (typeof key == "function") {
      key.call(update, update)
      return update
    }

    return update.put(key, value)
  },

  fetch: function(opts, cb) {
    if (typeof opts == "function") cb = opts, opts = {}

    var self = this
      , attrs = {}
      , data = {
          TableName: this.TableName,
          Key: this.Key
        }

    if (opts.consistent) data.ConsistentRead = true

    this.database.request(
      "GetItem",
      data,
      function(err, data) {
        if (err || !data.Item) return cb(err)

        cb(null, Attributes.prototype.parse(data.Item))
      }
    )

    return this
  }
}

module.exports = Item
{'fraction_non_alphanumeric': 0.1363457760314342, 'fraction_numerical': 0.0003929273084479371, 'mean_word_length': 2.3901464713715046, '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': '1814316', 'n_tokens_mistral': 832, 'n_tokens_neox': 806, 'n_words': 209}