 query_mapping = assign {}, filter_mapping, expression: 'KeyConditionExpression', index: 'IndexName', limit: 'Limit', forward: 'ScanIndexForward'
 scan_mapping = assign {}, filter_mapping, limit: 'Limit'
 
+_apply_timestamps = (item) ->
+  now = new Date()
+  item.created_at = now unless item.created_at?
+  item.updated_at = now
+  item
+
+_apply_identifier = (item) ->
+  item.identifier = keygen.url @key_size unless item.identifier?
+  item
+
+
+
 class Model
 
   constructor: (@name, extension={}) ->

    params = RequestItems: {}
    items = map items, (item) =>
      item = assign {}, item
      @_apply_timestamps item
      @_apply_identifier item
    params.RequestItems[@name] = (PutRequest: Item: item for item in items)
    @_request('batchWrite', params, false).then (results) ->
      items

  insert: (item, params={}) ->
    item = assign {}, item
    @_apply_identifier item
    params.condition = 'identifier <> :identifier'
    params.values =  ':identifier': item.identifier
    @put item, params


  put: (item, params={}) ->
    item = assign {}, item
    _apply_timestamps item if @auto_timestamps
    _apply_identifier item if @hash_key == 'identifier'
    params = map_parameters params, condition_mapping
    params.Item = item
    @_request('put', params).then (result) ->
