ActiveRecord for NeDB
NeDB sources and specification: https://github.com/louischatriot/nedb

@param name
@returns {F}
@constructor
161438
function ActiveRecord(name) {

    var cfg = {};
    
    var ext = {
        format:'txt',
        location:'database'
    };

    function buildFileName(name) {
        return ext.location + '/' + name + '.' + ext.format;
    }

    ActiveRecord._config &&
    _.extend(cfg, ActiveRecord._config);

    cfg.format &&
    (ext.format = cfg.format) &&
    (delete cfg.format);

    cfg.location &&
    (ext.location = cfg.location) &&
    (delete cfg.location);

    if(name) {
        cfg.filename = buildFileName(name);
    } else {
        throw new Error("Required parameter 'name' is not defined!");
    }

    var db = new DB(cfg);

    !cfg.autoload && db.loadDatabase();

    var flow = new Flow();

    /**
     * The exported class is responsible for a specific collection
     *
     * @param params
     * @constructor
     */
    function F(params) {
        params && (_.extend(this, params));
        generateId(this);
    }

    F.prototype.save = function() {
        var buffer = _.clone(this),
            refreshBuffer = function() {
                this.createdAt &&
                (buffer.createdAt = this.createdAt);
            },
            syncData = function(data){
                return _.isArray(data) &&
                    _.extend(this, data[1]) || data;
            };

        return F.pre(refreshBuffer.bind(this))
            .update({_id: this._id}, buffer, { upsert: true })
            .then(syncData.bind(this));
    };

    F.prototype.remove = function() {
        return F.remove({_id: this._id}, {});
    };

    /**
     * Cursor for methods: find, findOne or count
     *
     * @param dbCursor
     * @constructor
     */
    function C(dbCursor) {
        var chain = dbCursor;

        _.each(['sort', 'skip', 'limit', 'projection'], function(fName) {
            this[fName] = function() {
                chain = chain[fName].apply(chain, arguments);
                return this;
            }
        }.bind(this));

        this.exec = function(){
            return convertToPromise(chain, 'exec', [], function(data) {
                if(_.isArray(data)) return dbCallbacks.find(data);
                if(_.isObject(data)) return dbCallbacks.findOne(data);
                return data;
            });
        };
    }

    function generateId(o){
        o && !o._id && (o._id = db.createNewId());
    }

    /**
     * Generator of functions using Cursor API: sort, limit, skip, projection
     *
     * @example {$$sort:{planet: 1}, $$skip:1, $$limit:2, $$projection: { planet: 1, system: 1 }, $not: { planet: 'Earth' }}
     * @param fnName
     * @returns {*}
     */
    function generateCursorApi(fnName) {
        return function (query, projections) {
            var cursorOptions = _.pick(query, '$$sort', '$$skip', '$$limit', '$$projection');
            query = _.omit.apply(_, _.flatten([query, _.keys(cursorOptions)]));

            if (_.keys(cursorOptions).length || projections) {
                projections && (cursorOptions.$$projection = projections);

                var cursor = new C(db[fnName](query));
                _.reduce(_.keys(cursorOptions), function (c, method) {
                    return c[method.replace('$$','')](cursorOptions[method]);
                }, cursor);

                return cursor.exec();
            }

            return convertToPromise(db, fnName, arguments,
                (fnName === 'find' ? dbCallbacks.find : (fnName === 'findOne' ? dbCallbacks.findOne : null)));
        };
    }

    function convertToPromise(ctx, method, args, success) {
        return flow.execute(function(){
            var promise = Q.nfapply(ctx[method].bind(ctx), args);
            return success
                ? promise.then(success)
                : promise;
        });
    }

    function createRecord(doc) {
        return doc ? new F(doc) : null;
    }

    var dbCallbacks = {
        insert: function(docs){
            return _.isArray(docs)
                ? _.map(docs, createRecord)
                : createRecord(docs);
        },

        find: function(docs) {
            return _.map(docs, createRecord);
        },

        findOne: function(doc) {
            return createRecord(doc);
        },

        update: function(data) {
            _.isArray(data) &&
            (data[1] = createRecord(data[1]));
            return data;
        }
    };

    F.pre = function(fn) {
        return flow.execute(fn) && F;
    };

    F.update = function(){
        return convertToPromise(db, 'update', arguments, dbCallbacks.update);
    };

    F.insert = function(){
        return convertToPromise(db, 'insert', arguments, dbCallbacks.insert);
    };

    F.remove = function(){
        return convertToPromise(db, 'remove', arguments);
    };

    F.ensureIndex = function(){
        return convertToPromise(db, 'ensureIndex', arguments);
    };

    F.removeIndex = function(){
        return convertToPromise(db, 'removeIndex', arguments);
    };

    F.find = generateCursorApi('find');

    F.count = generateCursorApi('count');

    F.findOne = generateCursorApi('findOne');

    return F;
}
455898
@Override
    public Object getMember(String name) {
        switch (name) {
            case "wrapRDD": return F_wrapRDD;
            case "persist": return F_persist;
            case "unpersist": return F_unpersist;
            case "distinct": return F_distinct;
            case "filter": return F_filter;
            case "cache": return F_cache;
            case "coalesce": return F_coalesce;
            case "repartition": return F_repartition;
            case "sample": return F_sample;
            case "sampleByKey": return F_sampleByKey;
            case "sampleByKeyExact": return F_sampleByKeyExact;
            case "union": return F_union;
            case "intersection": return F_intersection;
            case "first": return F_first;
            case "combineByKey": return F_combineByKey;
            case "reduceByKey": return F_reduceByKey;
            case "reduceByKeyLocally": return F_reduceByKeyLocally;
            case "countByKey": return F_countByKey;
            case "countByKeyApprox": return F_countByKeyApprox;
            case "aggregateByKey": return F_aggregateByKey;
            case "foldByKey": return F_foldByKey;
            case "groupByKey": return F_groupByKey;
            case "subtract": return F_subtract;
            case "subtractByKey": return F_subtractByKey;
            case "join": return F_join;
            case "leftOuterJoin": return F_leftOuterJoin;
            case "rightOuterJoin": return F_rightOuterJoin;
            case "fullOuterJoin": return F_fullOuterJoin;
            case "collectAsMap": return F_collectAsMap;
            case "mapValues": return F_mapValues;
            case "flatMapValues": return F_flatMapValues;
            case "cogroup": return F_cogroup;
            case "groupWith": return F_groupWith;
            case "lookup": return F_lookup;
            case "sortByKey": return F_sortByKey;
            case "keys": return F_keys;
            case "values": return F_values;
            case "countApproxDistinctByKey": return F_countApproxDistinctByKey;
            case "setName": return F_setName;
            case "rdd": return F_rdd;

        }
        return super.getMember(name);
    }
815152
function (name) { var self = this

        //console.log ('callChainMethod', this.constructor.$meta.name, name)

        const methods = _.filter2 (this.constructor.$traits || [], function (Trait) {

                                                                        var method = Trait.prototype[name]

                                                                        // if (method) {
                                                                        //     return (...args) => {
                                                                        //         console.log ('Calling', Trait.$meta.name, name)
                                                                        //         return method.call (self, ...args)
                                                                        //     }
                                                                        // }

                                                                        return (method && method.bind (self)) || false })

        return __.seq (methods) }
1160478
def [](name)
      key = name.to_s
      if attributes.key?(key)
        attributes[key]
      elsif index = underscored_column_names.index(key)
        attributes[@columns[index].name]
      end
    end
227174
private final Object getObject(String name)
   {
      if (m_map.containsKey(name) == false)
      {
         throw new IllegalArgumentException("Invalid column name " + name);
      }

      Object result = m_map.get(name);

      return (result);
   }
294353
def attribute(name, options = {})
        return unless
          @_object &&
          attribute_present?(name) &&
          resolve_condition(options)

        attribute = data_object_attribute(name)
        name = create_key(options[:as] || name)
        @_result[name] = attribute
      end
1038278
def find(name)
      cache(name) { @children.find { |x| safe_find(x, name) } || failure }
    end
622620
function Table(name, db, options) {
  this.name = name;
  this.db = db; // the name of the database
  this.options = options || {};
  this.options.primaryKey = this.options.primary_key || "id";
  this.documents = {};
  this.indexes = {}; // String -> FUNC terms
  this.indexes[this.options.primaryKey] = {
    //TODO Make me use TERMS
    //fn: function(doc) { return doc[name] },
    // 69=FUNC, 2=MAKE_ARRAY, 31=GET_FIELD, 10=VAR, 1=ARGUMENT_INDEX
    //TODO Use a uuid to avoid collision
    fn: [ 69, [ [ 2, [ 1 ] ], [ 31, [ [ 10, [ 1 ] ], this.options.primaryKey ] ] ] ],
    function: { /* TODO */ },
    geo: false,
    outdated: false,
    ready: true,
    multi: false
  };
  this.id = util.uuid();
  if (options.meta === true) {
    // meta table
    this.meta = true;
  }
}
673939
function getFieldRow(name) {
    if (model.nest === null) return 0;
    const foundRow = model.nest.reduce((prev, item, i) => {
      const val = item.value.filter((def) => def.name === name);
      if (val.length > 0) {
        return item.key;
      }
      return prev;
    }, 0);
    return foundRow;
  }
597726
function(name) {
    var command;
    if (name) {
      command = this.commands[name] = {
        name: name,
        specs: {}
      };
    }
    else {
      command = this.fallback = {
        specs: {}
      };
    }

    // facilitates command('name').options().cb().help()
    var chain = {
      options : function(specs) {
        command.specs = specs;
        return chain;
      },
      opts : function(specs) {
        // old API
        return this.options(specs);
      },
      option : function(name, spec) {
        command.specs[name] = spec;
        return chain;
      },
      callback : function(cb) {
        command.cb = cb;
        return chain;
      },
      help : function(help) {
        command.help = help;
        return chain;
      },
      usage : function(usage) {
        command._usage = usage;
        return chain;
      }
    };
    return chain;
  }
215697
@SuppressWarnings("unchecked")
  public Blob getBlob(String name) {
    return ((Value<Blob>) getValue(name)).get();
  }
709796
def named(name)
      resource = all.detect { |resource| resource.name == name }
      if resource.nil?
        raise UnknownResource, "Resource named #{name} doesn't exist"
      else
        resource
      end
    end
1358332
function EventEmitter(name, node) {
        if ('string' !== typeof name) {
            throw new TypeError('EventEmitter constructor: name must be ' +
                                'string. Found: ' + name);
        }

        this.node = node;

        // ## Public properties

        this.name = name;

        /**
         * ### EventEmitter.listeners
         *
         * Event listeners collection
         */
        this.events = {};

        /**
         * ## EventEmitter.recordChanges
         *
         * If TRUE, keeps tracks of addition and deletion of listeners
         *
         * @see EventEmitter.changes
         */
        this.recordChanges = false;

        /**
         * ## EventEmitter.changes
         *
         * If TRUE, keeps tracks of addition and deletion of listeners
         *
         * @see EventEmitter.recordChanges
         */
        this.changes = {
            added: [],
            removed: []
        };

        /**
         * ## EventEmitter.labels
         *
         * List of labels associated to an event listener
         *
         * @see EventEmitter.on
         */
        this.labels = {};

        /**
         * ### EventEmitter.history
         *
         * Database of emitted events
         *
         * @experimental
         *
         * @see NDDB
         * @see EventEmitter.EventHistory
         * @see EventEmitter.store
         */
        this.history = new EventHistory(this.node);
    }
664275
function (name) {
        var children = this._children;
        for (var i = 0; i < children.length; i++) {
            if (children[i].name === name) {
                return children[i];
            }
        }
    }
1341543
def provide(name)
      return nil unless name.respond_to?(:to_sym)
      name = name.to_sym
      fields[name] || fields[aliases[name]]
    end
332781
function record(name, components, { ignoreExtraProps } = {}) {
  if (name != null && typeof name === 'object') {
    ({ ignoreExtraProps } = Object(components));
    components = name;
    name = `SomeRecord`;
  }

  const componentKeys = keysOf(components);

  /* istanbul ignore else */
  if (__DEV__) {
    assert(typeof name === 'string', `record()'s name must be a string`);
    assert(
      components != null && typeof components === 'object',
      `record()'s components must be an object`
    );
    for (const key of componentKeys) {
      assert(
        components[key][TYPICAL_TYPE],
        `record()'s component value must be a type`
      );
    }
  }

  const api = this;

  function Record(value, context) {
    if (Context.isRequired(context)) {
      return Context.with(value, Record, context, api);
    } else if (value == null || typeof value !== 'object') {
      return context.valueIsNotOfType(value, Record);
    }

    const result = forEachTypedProperty(
      value,
      componentKeys,
      k => components[k],
      context.validateAndCopy ? create(Record.prototype) : void 0,
      context
    );

    if (ignoreExtraProps === void 0) {
      ignoreExtraProps =
        context.ignoreExtraProps !== void 0 ? context.ignoreExtraProps : false;
    }

    if (!ignoreExtraProps) {
      const extras = keysOf(value).filter(k => !components[k]);
      if (extras.length) {
        if (!context.isErrorWrapper(result)) {
          return context.valueHasExtraProperties(value, extras);
        } else {
          return context.mergeWrappers(
            result,
            context.valueHasExtraProperties(value, extras)
          );
        }
      }
    }

    return result;
  }

  return decorate(Record, name, record, { ...components });
}
514304
function (name, options) {
            var _member = this.member(name);
            if(_member && _member.getter){
                return _member.getter.call(this, options);
            }

            return undefined;
        }