Class: Baza::Driver::Mysql::ForeignKeys

Inherits:
Object
  • Object
show all
Defined in:
lib/baza/driver/mysql/foreign_keys.rb

Direct Known Subclasses

Baza::Driver::Mysql2::ForeignKeys

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db:) ⇒ ForeignKeys

Returns a new instance of ForeignKeys.



4
5
6
# File 'lib/baza/driver/mysql/foreign_keys.rb', line 4

def initialize(db:)
  @db = db
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



2
3
4
# File 'lib/baza/driver/mysql/foreign_keys.rb', line 2

def db
  @db
end

Instance Method Details

#create(from:, to:) ⇒ Object



8
9
10
11
12
# File 'lib/baza/driver/mysql/foreign_keys.rb', line 8

def create(from:, to:)
  sql = "ALTER TABLE #{from[0]} ADD FOREIGN KEY (#{from[1]}) REFERENCES #{to[0]}(#{to[1]})"

  db.query(sql)
end