ORM框架Ruby ActiveRecord詳細介紹
作者:佚名
Ruby ActiveRecord是一個以Martin Fowler定義的ORM框架。在編程人員眼中,這是一個非常有用的框架。下希望本文介紹的內容可以幫助大家充分掌握這一技巧。
在Ruby語言中,有一種ORM框架,為Ruby ActiveRecord。對于一個初學者來說可能對于這個框架還不是很了解,下面我們就為大家詳細介紹相關概念。#t#
Ruby ActiveRecord是以Martin Fowler所定義的ActiveRecord設計模式所命名的.每一個數據庫表,都是一個繼承ActiveRecord::Base的一個類.
- require 'active_record'
- ActiveRecord::Base.establish_
connection(:adapter =>"oci8", - :username =>"username",
- :password =>"password",
- :database => "mydb",
- :host => "myhost")
- class SomeTable < ActiveRecord::Base
- set_table_name "test_table"
- set_primary_key "some_id"
- end
- SomeTable.find(:all).each do |rec|
- # process rec as needed...
- end
- item = SomeTable.new
- item.id = 1001
- item.some_column = "test"
- item.save
以上就是對Ruby ActiveRecord的一些應用解析。
責任編輯:曹凱
來源:
ddvip.com