lib/base/attributes.js
function(name, type, options) {
    const Store = require('../store')
    options = options || {}
    type = type || String

    if (typeof type === 'string') {
      type = type.toLowerCase()
    }

    var fieldType = this.store.getType(type)
    if (!fieldType) {
      throw new Store.UnknownAttributeTypeError(type)
    }

    Object.assign(options, fieldType.defaults)

    options.name = this.store.toExternalAttributeName(name)
    options.type = fieldType
    options.writable =
      options.writable === undefined ? true : !!options.writable
    options.readable =
      options.readable === undefined ? true : !!options.readable
    options.track_object_changes =
      options.track_object_changes === undefined
        ? false
        : !!options.track_object_changes
    options.notifications = []

    this.attributes[name] = options

    this.setter(
      name,
      options.setter ||
        function(value) {
          this.set(options.name, value)
        }
    )

    if (options.readable || options.getter) {
      this.getter(
        name,
        options.getter ||
          function() {
            return this.get(name)
          },
        true
      )
    }

    return this
  }
function(name, type, options) {
    const Store = require('../store')
    options = options || {}
    type = type || String

    if (typeof type === 'string') {
      type = type.toLowerCase()
    }

    var fieldType = this.store.getType(type)
    if (!fieldType) {
      throw new Store.UnknownAttributeTypeError(type)
    }

    Object.assign(options, fieldType.defaults)

    options.name = this.store.toExternalAttributeName(name)
    options.type = fieldType
    options.writable =
      options.writable === undefined ? true : !!options.writable
    options.readable =
      options.readable === undefined ? true : !!options.readable
    options.track_object_changes =
      options.track_object_changes === undefined
        ? false
        : !!options.track_object_changes
    options.notifications = []

    this.attributes[name] = options

    this.setter(
      name,
      options.setter ||
        function(value) {
          this.set(options.name, value)
        }
    )

    if (options.readable || options.getter) {
      this.getter(
        name,
        options.getter ||
          function() {
            return this.get(name)
          },
        true
      )
    }

    return this
  }
function ( name , type , options ) { const Store = require ( '../store' ) options = options || { } type = type || String if ( typeof type === 'string' ) { type = type . toLowerCase ( ) } var fieldType = this . store . getType ( type ) if ( ! fieldType ) { throw new Store . UnknownAttributeTypeError ( type ) } Object . assign ( options , fieldType . defaults ) options . name = this . store . toExternalAttributeName ( name ) options . type = fieldType options . writable = options . writable === undefined ? true : ! ! options . writable options . readable = options . readable === undefined ? true : ! ! options . readable options . track_object_changes = options . track_object_changes === undefined ? false : ! ! options . track_object_changes options . notifications = [ ] this . attributes [ name ] = options this . setter ( name , options . setter || function ( value ) { this . set ( options . name , value ) } ) if ( options . readable || options . getter ) { this . getter ( name , options . getter || function ( ) { return this . get ( name ) } , true ) } return this }
Add a new attribute to your Model

@public
@memberof Definition
@method attribute
@param {string} name - The attribute name
@param {string} type - The attribute type (e.g. `text`, `integer`, or sql language specific. e.g. `blob`)
@param {object} [options] - Optional options
@param {boolean} [options.writable=true] - make it writeable
@param {boolean} [options.readable=true] - make it readable
@param {any} [options.default=null] - Default value
@param {boolean} [options.emit_events=false] - emit change events `name_changed`

@return {Definition}
Add a new attribute to your Model