On Jun 9, 11:42 pm, Jeremy Evans <[email protected]> wrote:
> On Jun 9, 10:59 pm, Hiten <[email protected]> wrote:
>
> > When a model instance is created with from(), is that table name kept
> > somewhere?
>
> > Ideally, I'd be able to do:
>
> > model_instance.server(:shard1).from(:table1).first.this.first_source
> > # => :table1 #(does not happen)
>
> > However, this seems to not be the case. It always returns the table
> > name of the model (i.e., what was defined in the class definition).
>
> Take a look at the implementation of server in the sharding plugin.
> The same approach would work for from.
>
> > This works though:
>
> > model_instance.server(:shard1).from(:table1).naked.first_source
> > # => :table1
>
> > What's the right way to proceed?
>
> Depends on your app. Instead of giving hypotheticals, can you
> describe the actual sharding you want to use in your app. If I knew
> that I could probably suggest something.
Sorry, I will be more clear.
I'm trying to encapsulate an existing database structure with Sequel:
A database of jobs is spread across 16 tables (Q00..Q15) and these
16 tables are split amongst 4 hosts (Host1..Host4) with Q00..Q03 on
Host1, Q04..Q07 on Host2, etc. The primary key in each table is an id
that is only unique to that table, and there is no way to determine
which table or host a row is on from the row itself.
So this is what I have:
class Job < Sequel::Model(:Q00)
plugin :sharding
def q(num)
# TABLES = { '0' => [:Host1, :Q00] ... }
shard, table = TABLES[num.to_s]
self.from(table).server(shard)
end
def this
super
# Not sure
end
end
I know that this should be overridden but am unsure how to move
forward as I'm a bit in over my head.
Thank you,
Hiten
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.