Sha256: fb52f58d5a828db908ddf30c572d3795267882fddda2f7f8fb444371f39c7a09
Contents?: true
Size: 1.86 KB
Versions: 2
Compression:
Stored size: 1.86 KB
Contents
module GreyscaleRecord module DataStore class Engine # A data store can only have one driver. # It's like a database connection. If you want models to connect to different # databases, you have them inherit from different base classes that specify # a db to connect to. # Pros: # * All the data in your store comes from the same place. Easy to reason about # * No chance of data source collisions. Can't populate tables from multiple sources # * Cleaner table-adding interface # store.add_table( name ) # vs # store.add_table( name, driver ) # # where does driver get initialized? # * Straight forward patching: one complete patch at a time # How do you patch across differntly driven tables? # Do you need a patch stack? # * Depending on how your remote is built, you can pull in all the data at once # # Cons: # * Limiting if you want to have some tables come from YAML and some from remote # # Yeah. OK. delegate :apply_patch, :remove_patch, :with_patch, :table, to: :store def initialize( driver ) @driver = driver @store = Store.new end # Read only store. No writes allowed. def find( options = {} ) table = store.table( options.delete(:_table) ) if GreyscaleRecord.live_reload load_table!( table ) end # TODO: this is where all the meat is table.find options end def add_table( name ) load_table! name end def add_index( name, column ) store.table( name ).add_index( column ) end private def store @store end def load_table!( name ) store.init_table name, @driver.load!( name ) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
greyscale_record-1.0.1 | lib/greyscale_record/data_store/engine.rb |
greyscale_record-1.0.0 | lib/greyscale_record/data_store/engine.rb |