Class: ActiveRecord::ConnectionAdapters::Clickhouse::TableDefinition
- Inherits:
-
TableDefinition
- Object
- TableDefinition
- ActiveRecord::ConnectionAdapters::Clickhouse::TableDefinition
- Defined in:
- lib/active_record/connection_adapters/clickhouse/schema_definitions.rb
Instance Attribute Summary collapse
-
#if_not_exists ⇒ Object
readonly
Returns the value of attribute if_not_exists.
-
#materialized ⇒ Object
readonly
Returns the value of attribute materialized.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Instance Method Summary collapse
- #datetime(*args, **options) ⇒ Object
- #enum(*args, **options) ⇒ Object
-
#initialize(conn, name, temporary: false, if_not_exists: false, options: nil, as: nil, comment: nil, view: false, materialized: false, to: nil) ⇒ TableDefinition
constructor
A new instance of TableDefinition.
- #integer(*args, **options) ⇒ Object
- #uuid(*args, **options) ⇒ Object
Constructor Details
#initialize(conn, name, temporary: false, if_not_exists: false, options: nil, as: nil, comment: nil, view: false, materialized: false, to: nil) ⇒ TableDefinition
Returns a new instance of TableDefinition.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/active_record/connection_adapters/clickhouse/schema_definitions.rb', line 10 def initialize( conn, name, temporary: false, if_not_exists: false, options: nil, as: nil, comment: nil, view: false, materialized: false, to: nil, ** ) @conn = conn @columns_hash = {} @indexes = [] @foreign_keys = [] @primary_keys = nil @temporary = temporary @if_not_exists = if_not_exists @options = @as = as @name = name @comment = comment @view = view || materialized @materialized = materialized @to = to end |
Instance Attribute Details
#if_not_exists ⇒ Object (readonly)
Returns the value of attribute if_not_exists.
8 9 10 |
# File 'lib/active_record/connection_adapters/clickhouse/schema_definitions.rb', line 8 def if_not_exists @if_not_exists end |
#materialized ⇒ Object (readonly)
Returns the value of attribute materialized.
8 9 10 |
# File 'lib/active_record/connection_adapters/clickhouse/schema_definitions.rb', line 8 def materialized @materialized end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
8 9 10 |
# File 'lib/active_record/connection_adapters/clickhouse/schema_definitions.rb', line 8 def to @to end |
#view ⇒ Object (readonly)
Returns the value of attribute view.
8 9 10 |
# File 'lib/active_record/connection_adapters/clickhouse/schema_definitions.rb', line 8 def view @view end |
Instance Method Details
#datetime(*args, **options) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/active_record/connection_adapters/clickhouse/schema_definitions.rb', line 66 def datetime(*args, **) kind = :datetime if [:precision] kind = :datetime64 end args.each { |name| column(name, kind, **) } end |
#enum(*args, **options) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/active_record/connection_adapters/clickhouse/schema_definitions.rb', line 80 def enum(*args, **) kind = :enum8 unless [:value].is_a? Hash raise ArgumentError, "Column #{args.first}: option 'value' must be Hash, got: #{[:value].class}" end [:value] = [:value].each_with_object([]) { |(k, v), arr| arr.push("'#{k}' = #{v}") }.join(', ') if [:limit] kind = :enum8 if [:limit] == 1 kind = :enum16 if [:limit] == 2 end args.each { |name| column(name, kind, **.except(:limit)) } end |
#integer(*args, **options) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/active_record/connection_adapters/clickhouse/schema_definitions.rb', line 39 def integer(*args, **) # default to unsigned unsigned = [:unsigned] unsigned = true if unsigned.nil? kind = :uint32 # default if [:limit] if unsigned kind = :uint8 if [:limit] == 1 kind = :uint16 if [:limit] == 2 kind = :uint32 if [3,4].include?([:limit]) kind = :uint64 if [5,6,7].include?([:limit]) kind = :big_integer if [:limit] == 8 kind = :uint256 if [:limit] > 8 else kind = :int8 if [:limit] == 1 kind = :int16 if [:limit] == 2 kind = :int32 if [3,4].include?([:limit]) kind = :int64 if [:limit] > 5 && [:limit] <= 8 kind = :int128 if [:limit] > 8 && [:limit] <= 16 kind = :int256 if [:limit] > 16 end end args.each { |name| column(name, kind, **.except(:limit, :unsigned)) } end |
#uuid(*args, **options) ⇒ Object
76 77 78 |
# File 'lib/active_record/connection_adapters/clickhouse/schema_definitions.rb', line 76 def uuid(*args, **) args.each { |name| column(name, :uuid, **) } end |