On Jun 2, 6:29 pm, Hiten <hrpar...@gmail.com> wrote:
> There is a way to know which table to query.
>
> Sure. Say 4 hosts with 4 tables each. Every item has an id. The last
> digit (hex) signifies the table and host.

In the Sequel model, you'd probably want to override this:

  TABLES = {'0'=>[:shard_a, :table_a],
  '1'=>[:shard_a, :table_b],
  ...
  'e'=>[:shard_d, table_c],
  'f'=>[:shard_d, :table_d]}
  def this
    shard, table = TABLES[id[-1..-1]]
    super.from(table).server(shard)
  end

For creating entries, something similar for _insert_dataset should
work, assuming you know the id before saving.

> Some queries are going to need go across all tables. Is that possible
> at all?

Queries on the same database could use union:

 
MyModel.server(:shard_a).from(:table_a).union(DB[:table_b]).union(DB[:table_c]).union(DB[:table_d])

For queries that need access multiple databases, you'd obviously have
to use separate queries.  I'd probably do separate queries for each
table and server, and combine the results together:

  rows = []
  tables = [:table_a, :table_b, :table_c, :table_d]
  shards = [:shard_a, :shard_b, :shard_c, :shard_d]
  tables.each do |t|
    shards.each do |s|
      rows.concat DB[t].server(s).all
    end
  end
  rows

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to sequel-t...@googlegroups.com.
To unsubscribe from this group, send email to 
sequel-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to