복붙노트

[RUBY-ON-RAILS] 레일 열 유형에 대한이 문서인가?

RUBY-ON-RAILS

레일 열 유형에 대한이 문서인가?

나는이 페이지에서 발견되는 것을 나열하는 단순한 형식보다 더 찾고 있어요 :

그러나 실제로 이러한 필드를 정의하는 모든 문서가 있습니까?

구체적으로 특별히:

이러한 유형의 뉘앙스는 어디 문서화하고 있는가?

편집 : DB 플랫폼 구현의 포인트가 물어려고 질문에 무관하다. , 만약 말 : 날짜가없는 정의 레일 문서의 의미를 구성, 다음 DB-어댑터 작성자가 해당 열 유형을 선택할 때로 가서 무엇을?

해결법

  1. ==============================

    1.개인적인 경험에서 구축 가이드 라인 :

    개인적인 경험에서 구축 가이드 라인 :

    이러한 혼란은 종종 존재하는 대한 종류; 이게 도움이 되길 바란다. 이들에 대한 공식 문서가없는 이유를 난 정말 모르겠어요. 또한, 나는 그래서 그들은 아마도 그들이 어댑터를 작성할 때 지나는 모든 문서를 필요로하지 않았다, 당신은 레일을 쓴 같은 사람에 의해 작성되었습니다 언급이 데이터베이스 어댑터를 상상한다. 도움이 되었기를 바랍니다!

    참고 : 모두의 존재 : 날짜 시간과 : 타임 스탬프, 내가 무엇을 찾을 수에서를 대부분 데이터베이스 시스템과의 호환성을 위해 레일로 포함되어 있습니다. 예를 들어, MySQL을의 TIMESTAMP 데이터 타입은 유닉스 타임 스탬프로 저장됩니다. 그것의 유효 범위는 1970에서 2038로 이동, 시간은 아마도 표준 마지막 시대 이후 경과 한 시간 (초)로 저장되어 있지만 실제로 시스템에 따라 다를 수 있습니다. 상대 시간은 데이터베이스에있는 좋은 일이 아니라는 것을 인식하고, MySQL은 나중에 크기 증가의 비용으로, 두 번째 년, 월, 일,시, 분에있는 모든 숫자를 저장하고 DATETIME 데이터 형식을 도입했습니다. 타임 스탬프 데이터 형식은 이전 버전과의 호환성을 유지한다. 다른 데이터베이스 시스템과 유사한 진화를 통해 갔다. 레일은 여러 표준이 존재하는 것을 인식하고, 모두에 대한 인터페이스를 제공했다. 그러나, 레일 액티브 기본적으로 모두 : 타임 스탬프와 : 그것은 레일 프로그래머 기능적 차이가 없습니다 있도록 날짜 시간 UTC에 날짜, MySQL을의 DATETIME에 저장됩니다. 이 두 가지를 구별하고자하는 사용자가 그렇게 할 수 있도록 존재한다. (더 깊이있는 설명은,이 SO 응답 참조).

  2. ==============================

    2.레일 마스터 브랜치의 소스 코드에서 나는 발견

    레일 마스터 브랜치의 소스 코드에서 나는 발견

    추상적 인 mysql_adapter

    #activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
    
      NATIVE_DATABASE_TYPES = {
        primary_key: "bigint auto_increment PRIMARY KEY",
        string:      { name: "varchar", limit: 255 },
        text:        { name: "text", limit: 65535 },
        integer:     { name: "int", limit: 4 },
        float:       { name: "float" },
        decimal:     { name: "decimal" },
        datetime:    { name: "datetime" },
        timestamp:   { name: "timestamp" },
        time:        { name: "time" },
        date:        { name: "date" },
        binary:      { name: "blob", limit: 65535 },
        boolean:     { name: "tinyint", limit: 1 },
        json:        { name: "json" },
      }
    
      # Maps logical Rails types to MySQL-specific data types.
      def type_to_sql(type, limit = nil, precision = nil, scale = nil, unsigned = nil)
        sql = case type.to_s
        when 'integer'
          integer_to_sql(limit)
        when 'text'
          text_to_sql(limit)
        when 'blob'
          binary_to_sql(limit)
        when 'binary'
          if (0..0xfff) === limit
            "varbinary(#{limit})"
          else
            binary_to_sql(limit)
          end
        else
          super(type, limit, precision, scale)
        end
    
        sql << ' unsigned' if unsigned && type != :primary_key
        sql
      end    
    
    # and integer ...
    
      def integer_to_sql(limit) # :nodoc:
        case limit
        when 1; 'tinyint'
        when 2; 'smallint'
        when 3; 'mediumint'
        when nil, 4; 'int'
        when 5..8; 'bigint'
        else raise(ActiveRecordError, "No integer type has byte size #{limit}")
        end
      end
    
     # and text ..
    
      def text_to_sql(limit) # :nodoc:
        case limit
        when 0..0xff;               'tinytext'
        when nil, 0x100..0xffff;    'text'
        when 0x10000..0xffffff;     'mediumtext'
        when 0x1000000..0xffffffff; 'longtext'
        else raise(ActiveRecordError, "No text type has byte length #{limit}")
        end
      end
    
    # and binary ...
    
        def binary_to_sql(limit) # :nodoc:
          case limit
          when 0..0xff;               "tinyblob"
          when nil, 0x100..0xffff;    "blob"
          when 0x10000..0xffffff;     "mediumblob"
          when 0x1000000..0xffffffff; "longblob"
          else raise(ActiveRecordError, "No binary type has byte length #{limit}")
          end
        end
    

    type_to_sql 방법의 슈퍼

    #activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
      def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc:
        type = type.to_sym if type
        if native = native_database_types[type]
          column_type_sql = (native.is_a?(Hash) ? native[:name] : native).dup
    
          if type == :decimal # ignore limit, use precision and scale
            scale ||= native[:scale]
    
            if precision ||= native[:precision]
              if scale
                column_type_sql << "(#{precision},#{scale})"
              else
                column_type_sql << "(#{precision})"
              end
            elsif scale
              raise ArgumentError, "Error adding decimal column: precision cannot be empty if scale is specified"
            end
    
          elsif [:datetime, :time].include?(type) && precision ||= native[:precision]
            if (0..6) === precision
              column_type_sql << "(#{precision})"
            else
              raise(ActiveRecordError, "No #{native[:name]} type has precision of #{precision}. The allowed range of precision is from 0 to 6")
            end
          elsif (type != :primary_key) && (limit ||= native.is_a?(Hash) && native[:limit])
            column_type_sql << "(#{limit})"
          end
    
          column_type_sql
        else
          type.to_s
        end
      end
    
  3. from https://stackoverflow.com/questions/11889048/is-there-documentation-for-the-rails-column-types by cc-by-sa and MIT license