%3 ::xo::db::Attribute ::xo::db::Attribute attribute_reference column_spec create_attribute db_attribute_defined init ::xo::Attribute ::xo::Attribute init ::xo::db::Attribute->::xo::Attribute ::xotcl::Attribute ::xotcl::Attribute ::xo::Attribute->::xotcl::Attribute ::xo::db::CrAttribute ::xo::db::CrAttribute create_attribute ::xo::db::CrAttribute->::xo::db::Attribute

Class ::xo::db::Attribute

::xo::db::Attribute[i] create ... \
           [ -column_name column_name ] \
           [ -constraint_values constraint_values ] \
           [ -create_acs_attribute:substdefault (default "true") ] \
           [ -create_table_attribute:substdefault (default "true") ] \
           [ -datatype:substdefault (default "text") ] \
           [ -help_text help_text ] \
           [ -index index ] \
           [ -max_n_values:substdefault (default "1") ] \
           [ -min_n_values:substdefault (default "1") ] \
           [ -multivalued multivalued ] \
           [ -not_null not_null ] \
           [ -pretty_name pretty_name ] \
           [ -pretty_plural:substdefault (default "") ] \
           [ -references:substdefault (default "") ] \
           [ -required:substdefault (default "false") ] \
           [ -spec spec ] \
           [ -sqltype sqltype ] \
           [ -substdefault substdefault ] \
           [ -unique unique ] \
           [ -validator validator ]

ORM class representing an acs_attribute from and acs_object.
Defined in packages/xotcl-core/tcl/05-db-procs.tcl

Class Relations

  • class: ::xotcl::MetaSlot[i]
  • superclass: ::xo::Attribute[i]
  • subclass: ::xo::db::CrAttribute[i]
::xotcl::MetaSlot create ::xo::db::Attribute \
     -superclass ::xo::Attribute

Methods (to be applied on instances)

  • attribute_reference (scripted)

    if {${:column_name} ne ${:name}} {
      return "$tn.${:column_name} AS ${:name}"
    } else {
      return "$tn.${:name}"
    }
  • column_name (setter)

  • column_spec (scripted)

    set table_name [${:domain} table_name]
    set column_spec ""
    append column_spec " " [::xo::dc map_datatype ${:sqltype}]
    #
    # Default
    #
    if {[info exists :default]} {
      append column_spec " DEFAULT '${:default}' "
    }
    #
    # References
    #
    if {[info exists :references] && ${:references} ne ""} {
      append column_spec " REFERENCES ${:references}"
    } elseif {$id_column} {
      set sc [${:domain} info superclass]
      if {![$sc istype ::xo::db::Class]} {set sc ::xo::db::Object}
      append column_spec " REFERENCES [$sc table_name]([$sc id_column]) ON DELETE CASCADE "
    }
    #
    # Unique and Not NULL
    #
    if {[info exists :unique]}   {append column_spec " UNIQUE "  }
    if {[info exists :not_null]} {append column_spec " NOT NULL "}
    #
    # Primary key
    #
    if {$id_column} {
      # add automatically a constraint for the id_column
      append column_spec " PRIMARY KEY "
    }
    append column_spec [::xo::dc datatype_constraint ${:sqltype} $table_name ${:name}]
    return $column_spec
  • create_acs_attribute (setter)

  • create_attribute (scripted)

    if {!${:create_acs_attribute}} return
    
    set object_type [${:domain} object_type]
    #ns_log notice "::xo::db::Attribute create_attribute $object_type ${:column_name} epoch [ns_ictl epoch] [array get ::db_state_default]"
    
    if {![:db_attribute_defined -object_type $object_type -attribute_name ${:column_name} ]} {
    
      ns_log notice "GN: Attribute create_attribute flushes acs_attributes cache"
      nsv_unset -nocomplain acs_attributes acs_attributes
    
      if {![::xo::db::Class object_type_exists_in_db -object_type $object_type]} {
        ${:domain} create_object_type
      }
    
      ::acs::dc call acs_attribute create_attribute  -object_type    $object_type  -attribute_name ${:column_name}  -datatype       ${:datatype}  -pretty_name    ${:pretty_name}  -min_n_values   ${:min_n_values}  -max_n_values   ${:max_n_values}
    
      if {[::acs::icanuse "nsv_dict"]} {
        nsv_dict set acs_attributes $object_type ${:column_name} 1
      }
    }
  • create_table_attribute (setter)

  • db_attribute_defined (scripted)

    if {![nsv_get acs_attributes acs_attributes list]} {
      ns_log notice "GN: fetch all db_attributes"
      set list [xo::dc list get_all_attributes {
        select object_type || '-' || attribute_name from acs_attributes
      }]
      nsv_set acs_attributes acs_attributes $list
    }
    set key $object_type-$attribute_name
    #ns_log notice "GN: check is $object_type $attribute_name in list? [expr {$key in $list}]"
    expr {$key in $list}
  • index (setter)

  • init (scripted)

    next    ;# do first ordinary slot initialization
    if {![info exists :sqltype]}     {set :sqltype     ${:datatype}}
    if {![info exists :column_name]} {set :column_name ${:name}}
    
    :create_attribute
  • max_n_values (setter)

  • min_n_values (setter)

  • not_null (setter)

  • references (setter)

  • sqltype (setter)

  • unique (setter)