module KSUID::ActiveRecord::TableDefinition
Extends ActiveRecord's table definition language for KSUIDs
Public Instance Methods
ksuid(*args, **options)
click to toggle source
Defines a field as a string-based KSUID
@example Define a KSUID
field as a non-primary key
ActiveRecord::Schema.define do create_table :events, force: true do |table| table.ksuid :ksuid, index: true, unique: true end end
@example Define a KSUID
field as a primary key
ActiveRecord::Schema.define do create_table :events, force: true, id: false do |table| table.ksuid :id, primary_key: true end end
@param args [Array<Symbol>] the list of fields to define as KSUIDs @param options [Hash] see {ActiveRecord::ConnectionAdapters::TableDefinition} @return [void]
# File lib/ksuid/activerecord/table_definition.rb, line 26 def ksuid(*args, **options) args.each { |name| column(name, :string, **options.merge(limit: 27)) } end
ksuid_binary(*args, **options)
click to toggle source
Defines a field as a binary-based KSUID
@example Define a KSUID
field as a non-primary key
ActiveRecord::Schema.define do create_table :events, force: true do |table| table.ksuid_binary :ksuid, index: true, unique: true end end
@example Define a KSUID
field as a primary key
ActiveRecord::Schema.define do create_table :events, force: true, id: false do |table| table.ksuid_binary :id, primary_key: true end end
@param args [Array<Symbol>] the list of fields to define as KSUIDs @param options [Hash] see {ActiveRecord::ConnectionAdapters::TableDefinition} @return [void]
# File lib/ksuid/activerecord/table_definition.rb, line 49 def ksuid_binary(*args, **options) args.each { |name| column(name, :binary, **options.merge(limit: 20)) } end