Module: DbAgile::SequelAdapter::Schema::Schema2SequelArgs

Included in:
ConcreteScript
Defined in:
lib/dbagile/adapter/sequel/schema/schema2sequel_args.rb

Instance Method Summary collapse

Instance Method Details

#attribute2column_args(attribute) ⇒ Object

Returns Sequel’s column argument from an Attribute instance



18
19
20
21
22
23
24
25
# File 'lib/dbagile/adapter/sequel/schema/schema2sequel_args.rb', line 18

def attribute2column_args(attribute)
  options = {:null => !attribute.mandatory?}
  unless (defa = attribute.default_value).nil?
    options[:default] = defa
  end
  domain = ruby_type2sequel_type(attribute.domain)
  [attribute.name, domain, options]
end

#candidate_key2primary_key_args(ckey) ⇒ Object

Returns Sequel’s primary_key arguments from a CandidateKey instance



31
32
33
34
35
# File 'lib/dbagile/adapter/sequel/schema/schema2sequel_args.rb', line 31

def candidate_key2primary_key_args(ckey)
  columns = ckey.key_attributes.collect{|c| c.name} 
  options = {:name => ckey.name}
  [ columns, options ]
end

#candidate_key2unique_args(ckey) ⇒ Object

Returns Sequel’s unique arguments from a CandidateKey instance



41
42
43
44
45
# File 'lib/dbagile/adapter/sequel/schema/schema2sequel_args.rb', line 41

def candidate_key2unique_args(ckey)
  columns = ckey.key_attributes.collect{|c| c.name} 
  options = {:name => ckey.name}
  [ columns, options ]
end

#foreign_key2foreign_key_args(fkey) ⇒ Object

Returns Sequel’s foreign_key arguments from a ForeignKey instance.



51
52
53
54
55
56
# File 'lib/dbagile/adapter/sequel/schema/schema2sequel_args.rb', line 51

def foreign_key2foreign_key_args(fkey)
  target_relvar = fkey.target_relvar.name
  source_names = fkey.source_attributes.collect{|a| a.name}
  target_names  = fkey.target_key.key_attributes.collect{|a| a.name}
  [source_names, target_relvar, { :key => target_names, :name => fkey.name }]
end

#index2index_args(index) ⇒ Object

Returns Sequel’s index arguments from an Index instance.



61
62
63
64
65
# File 'lib/dbagile/adapter/sequel/schema/schema2sequel_args.rb', line 61

def index2index_args(index)
  attr_names = index.indexed_attributes.collect{|a| a.name}
  options = {:name => index.name}
  [ attr_names, options ]
end

#ruby_type2sequel_type(type) ⇒ Object

Converts a Ruby type to a Sequel type



7
8
9
10
11
12
13
# File 'lib/dbagile/adapter/sequel/schema/schema2sequel_args.rb', line 7

def ruby_type2sequel_type(type)
  if type == SByC::TypeSystem::Ruby::Boolean
    TrueClass
  else
    type
  end
end