「ORM無しにwavesを使う」の編集履歴(バックアップ)一覧はこちら

ORM無しにwavesを使う」(2008/04/30 (水) 18:53:45) の最新版変更点

追加された行は緑色になります。

削除された行は赤色になります。

= ORM無しにwavesを使う = Although Waves explicitly supports using the Sequel ORM for accessing a database, you aren’t required to, and if you don’t, you don’t have to load the Sequel codebase either. In fact, you can use any ORM you want (including ActiveRecord) or no ORM at all (Sequel, for example, makes it easy to leverage many of Sequel’s power without using their ORM). Waves の将来のリリースでは、超軽量のファイルベースのストレージを明確にサポートするつもりです。 Filebase (まだリリースされていませんが) は、コンテンツマネジメントのような文書指向アプリケーションに向いています。50行未満のコードを追加することで、 ORMや従来のデータベースを使用するオーバーヘッド無しにデータベースを使用する利益の多くを得られます。 とにかく Sequel を外すのは簡単です: * まずは models フォルダの default.rb を Sequel::Model から継承しないよう変更します。。 * そして、あなたのアプリケーションモジュールから(例えば blog.rb) Sequel を require しないよう記述します。 * 次に when :Models 句の autoload 初期化節をコメントアウトしてください。 * 最後に, アプリケーションで定義された database メソッドをコメントアウトしてください。(または、あなたの選んだ ORM に置き換えてください) これで完了です。あなたのアプリケーションの起動ファイルはこんな風になったことでしょう。: '' # require 'sequel' '' module Blog extend Autocreate; extend Autoload; extend Reloadable autoload true; directories :lib [ :Configurations, :Models, :Views, :Controllers, :Helpers ].each do | name | autocreate( name, Module.new ) do # dynamically access module constants def self.[]( cname ) eval("#{name}::#{cname.to_s.camel_case}") end # first try to load and only create if that fails # which means install autoload *after* autocreate extend Autocreate; extend Autoload # autoload any files in appropriately named directories # exampe: models/blog.rb for Blog autoload true; directories name.to_s.snake_case # autocreate declarations ... case name # don't autocreate configs when :Configurations then nil # set the dataset for Models # when :Models # autocreate true, eval("Blog::Models::Default") do # set_dataset Blog.database[ basename.snake_case.plural.intern ] # end # everything else just use the exemplar else autocreate true, eval("Blog::#{name}::Default") end end end # accessor methods for modules and other key application objects ... class << self def config ; Waves::Server.config rescue nil || Waves::Console.config ; end # def database ; @database ||= Sequel.mysql( config.database ) ; end def configurations ; Blog::Configurations ; end def controllers ; Blog::Controllers ; end def models ; Blog::Models ; end def helpers ; Blog::Helpers ; end def views ; Blog::Views ; end end end Of course, YMMV based on what database / ORM solution you prefer (if any).
= ORM無しにwavesを使う = Although Waves explicitly supports using the Sequel ORM for accessing a database, you aren’t required to, and if you don’t, you don’t have to load the Sequel codebase either. In fact, you can use any ORM you want (including ActiveRecord) or no ORM at all (Sequel, for example, makes it easy to leverage many of Sequel’s power without using their ORM). Waves の将来のリリースでは、超軽量のファイルベースのストレージを明確にサポートするつもりです。 Filebase (まだリリースされていませんが) は、コンテンツマネジメントのような文書指向アプリケーションに向いています。50行未満のコードを追加することで、 ORMや従来のデータベースを使用するオーバーヘッド無しにデータベースを使用する利益の多くを得られます。 とにかく Sequel を外すのは簡単です: * まずは models フォルダの default.rb を Sequel::Model から継承しないよう変更します。。 * そして、あなたのアプリケーションモジュールから(例えば blog.rb) Sequel を require しないよう記述します。 * 次に when :Models 句の autoload 初期化節をコメントアウトしてください。 * 最後に, アプリケーションで定義された database メソッドをコメントアウトしてください。(または、あなたの選んだ ORM に置き換えてください) これで完了です。あなたのアプリケーションの起動ファイルはこんな風になったことでしょう。: # require 'sequel' module Blog extend Autocreate; extend Autoload; extend Reloadable autoload true; directories :lib [ :Configurations, :Models, :Views, :Controllers, :Helpers ].each do | name | autocreate( name, Module.new ) do # dynamically access module constants def self.[]( cname ) eval("#{name}::#{cname.to_s.camel_case}") end # first try to load and only create if that fails # which means install autoload *after* autocreate extend Autocreate; extend Autoload # autoload any files in appropriately named directories # exampe: models/blog.rb for Blog autoload true; directories name.to_s.snake_case # autocreate declarations ... case name # don't autocreate configs when :Configurations then nil # set the dataset for Models # when :Models # autocreate true, eval("Blog::Models::Default") do # set_dataset Blog.database[ basename.snake_case.plural.intern ] # end # everything else just use the exemplar else autocreate true, eval("Blog::#{name}::Default") end end end # accessor methods for modules and other key application objects ... class << self def config ; Waves::Server.config rescue nil || Waves::Console.config ; end # def database ; @database ||= Sequel.mysql( config.database ) ; end def configurations ; Blog::Configurations ; end def controllers ; Blog::Controllers ; end def models ; Blog::Models ; end def helpers ; Blog::Helpers ; end def views ; Blog::Views ; end end end Of course, YMMV based on what database / ORM solution you prefer (if any).

表示オプション

横に並べて表示:
変化行の前後のみ表示:
記事メニュー
目安箱バナー