Class: Rubernate::DBI::MySqlRuntime

Inherits:
Runtime
  • Object
show all
Defined in:
lib/rubernate/impl/dbi_mysql.rb

Constant Summary collapse

SELECT_NEXT_PK =
<<-SQL
SELECT LAST_INSERT_ID()
SQL
CREATE_PEER =
<<-SQL
INSERT INTO R_OBJECTS (OBJECT_CLASS) values (?)
SQL

Instance Method Summary collapse

Constructor Details

#initialize(dbh) ⇒ MySqlRuntime

Returns a new instance of MySqlRuntime.



15
16
17
18
# File 'lib/rubernate/impl/dbi_mysql.rb', line 15

def initialize dbh
  super
  dbh.do 'SET AUTOCOMMIT=0'
end

Instance Method Details

#create(object) ⇒ Object

Creates record in r_objects for specified object



21
22
23
24
25
26
27
# File 'lib/rubernate/impl/dbi_mysql.rb', line 21

def create object
  object.__peer = Rubernate::Peer.new unless object.__peer 
  @dbh.do CREATE_PEER, object.class.name
  object.primary_key = @dbh.select_one(SELECT_NEXT_PK)[0].to_i
  object.__peer.dirty = true
  object.primary_key
end