Using Waves Without An ORM

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).

A future release of Waves will also include explicit support for a very lightweight file-based storage mechanism called Filebase. Filebase (itself unreleased) is well-suited for document-oriented applications, like content management applications. Weighing in at less than 50 lines of code, it gives you many of the benefits of using a database without the overhead of using an ORM and conventional database.

In any event, removing the Sequel dependencies is easy:

When you’re done, your application initialization file might something like:

# 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).