Spec-Zone.ru › Ruby on Rails 5.1

модуль ActiveRecord::ConnectionAdapters::PostgreSQL::ColumnMethods

Методы публичного экземпляра

bigserial(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 59
def bigserial(*args, **options)
  args.each { |name| column(name, :bigserial, options) }
end
bit(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 63
def bit(*args, **options)
  args.each { |name| column(name, :bit, options) }
end
bit_varying(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 67
def bit_varying(*args, **options)
  args.each { |name| column(name, :bit_varying, options) }
end
box(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 143
def box(*args, **options)
  args.each { |name| column(name, :box, options) }
end
cidr(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 71
def cidr(*args, **options)
  args.each { |name| column(name, :cidr, options) }
end
circle(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 155
def circle(*args, **options)
  args.each { |name| column(name, :circle, options) }
end
citext(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 75
def citext(*args, **options)
  args.each { |name| column(name, :citext, options) }
end
daterange(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 79
def daterange(*args, **options)
  args.each { |name| column(name, :daterange, options) }
end
hstore(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 83
def hstore(*args, **options)
  args.each { |name| column(name, :hstore, options) }
end
inet(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 87
def inet(*args, **options)
  args.each { |name| column(name, :inet, options) }
end
int4range(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 95
def int4range(*args, **options)
  args.each { |name| column(name, :int4range, options) }
end
int8range(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 99
def int8range(*args, **options)
  args.each { |name| column(name, :int8range, options) }
end
interval(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 91
def interval(*args, **options)
  args.each { |name| column(name, :interval, options) }
end
json(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 103
def json(*args, **options)
  args.each { |name| column(name, :json, options) }
end
jsonb(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 107
def jsonb(*args, **options)
  args.each { |name| column(name, :jsonb, options) }
end
line(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 135
def line(*args, **options)
  args.each { |name| column(name, :line, options) }
end
lseg(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 139
def lseg(*args, **options)
  args.each { |name| column(name, :lseg, options) }
end
ltree(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 111
def ltree(*args, **options)
  args.each { |name| column(name, :ltree, options) }
end
macaddr(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 115
def macaddr(*args, **options)
  args.each { |name| column(name, :macaddr, options) }
end
money(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 119
def money(*args, **options)
  args.each { |name| column(name, :money, options) }
end
numrange(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 123
def numrange(*args, **options)
  args.each { |name| column(name, :numrange, options) }
end
oid(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 127
def oid(*args, **options)
  args.each { |name| column(name, :oid, options) }
end
path(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 147
def path(*args, **options)
  args.each { |name| column(name, :path, options) }
end
point(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 131
def point(*args, **options)
  args.each { |name| column(name, :point, options) }
end
polygon(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 151
def polygon(*args, **options)
  args.each { |name| column(name, :polygon, options) }
end
primary_key(name, type = :primary_key, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 44
def primary_key(name, type = :primary_key, **options)
  options[:auto_increment] = true if [:integer, :bigint].include?(type) && !options.key?(:default)
  if type == :uuid
    options[:default] = options.fetch(:default, "gen_random_uuid()")
  elsif options.delete(:auto_increment) == true && %(integer bigint).include?(type)
    type = if type == :bigint || options[:limit] == 8
      :bigserial
    else
      :serial
    end
  end

  super
end

Определяет поле первичного ключа. Поддерживается использование родного типа PostgreSQL UUID, и его можно использовать, определяя ваши таблицы следующим образом:

create_table :stuffs, id: :uuid do |t|
  t.string :content
  t.timestamps
end

По умолчанию, для этого будет использована функция +gen_random_uuid()+ из расширения pgcrypto. Поскольку это расширение доступно только в PostgreSQL 9.4+ для более ранних версий, можно явно установить значение по умолчанию для использования +uuid_generate_v4()+ из расширения uuid-ossp вместо этого:

create_table :stuffs, id: false do |t|
  t.primary_key :id, :uuid, default: "uuid_generate_v4()"
  t.uuid :foo_id
  t.timestamps
end

Для включения соответствующего расширения, что является требованием, используйте метод enable_extension в своих миграциях.

Чтобы использовать первичный ключ UUID без каких-либо расширений, установите опцию :default в nil.

create_table :stuffs, id: false do |t|
  t.primary_key :id, :uuid, default: nil
  t.uuid :foo_id
  t.timestamps
end

Вы также можете передать пользовательскую хранимую процедуру, возвращающую UUID, или использовать другую функцию генерации UUID из другой библиотеки.

Обратите внимание, что установка значения по умолчанию для первичного ключа UUID в nil потребует от вас гарантировать, что вы всегда предоставляете значение UUID перед сохранением записи (поскольку первичные ключи не могут быть nil). Это можно сделать, например, с помощью метода SecureRandom.uuid и обратного вызова before_save.

Вызов метода суперкласса
serial(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 159
def serial(*args, **options)
  args.each { |name| column(name, :serial, options) }
end
tsrange(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 163
def tsrange(*args, **options)
  args.each { |name| column(name, :tsrange, options) }
end
tstzrange(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 167
def tstzrange(*args, **options)
  args.each { |name| column(name, :tstzrange, options) }
end
END_OF_DOCUMENT_MARKER
tsvector(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 171
def tsvector(*args, **options)
  args.each { |name| column(name, :tsvector, options) }
end
uuid(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 175
def uuid(*args, **options)
  args.each { |name| column(name, :uuid, options) }
end
xml(*args, **options) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 179
def xml(*args, **options)
  args.each { |name| column(name, :xml, options) }
end

© 2004–2018 David Heinemeier Hansson
Licensed under the MIT License.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API