Model with multiple repositories at the same time?

32 views
Skip to first unread message

Dan Kubb (dkubb)

unread,
Dec 8, 2009, 4:33:55 AM12/8/09
to DataMapper
Hi,

I was wondering how many people use the same model with different
repositories?

I know many people (myself included) use the same model with a
different repository for testing as opposed to development, but that's
not really what I mean. I mean do you persist/retrieve data from a
specific model using multiple repositories within the same context?

A good way to know if this applies to you is to ask yourself "Do I
have code that wraps finders or persistence methods in repository()
blocks?".

I'm just trying to get a handle on how people use DM "in the wild" and
make sure that the features DM provides are closer inline with
people's use cases, and gradually move away from approaches that
aren't being used at all yet clutter up the code to support. If I had
to guess I'd say that the ability for a single model to be accessible
by multiple repositories all at the *same time* is seldom -- if at all
-- used.

--

Thanks,

Dan
(dkubb)

Ashley Moran

unread,
Dec 8, 2009, 4:45:53 AM12/8/09
to datam...@googlegroups.com

On 8 Dec 2009, at 09:33, Dan Kubb (dkubb) wrote:

> If I had
> to guess I'd say that the ability for a single model to be accessible
> by multiple repositories all at the *same time* is seldom -- if at all
> -- used.


FWIW, I've never used it.

Ashley

--
http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran



MarkMT

unread,
Dec 8, 2009, 4:51:17 AM12/8/09
to DataMapper
I definitely use this feature. I use it for synching model data
between two different machines.

Mark.

Dirkjan Bussink

unread,
Dec 8, 2009, 6:27:00 AM12/8/09
to datam...@googlegroups.com
I definitely want to use this in the near future for a basic sharding
setup. The idea is very basic, I would just wrap each request in a
repository block to select the correct shard where the data is
available.

Determining which shard to select can also include querying for
certain objects. Basically something like the following in a really
simplified version, but it does bring across the point I think. What
it does is a simple sharding algorithm based on odd / even id's. In
real life I would use something like "the first 100 customers are in
shard 1", "second 100 in shard 2" etc. A default repository would
contain the actual customers and data that needs to be available over
all customers.

I think it's perfectly fine to have only one active repository at one
time, so if I would want to access the default repository again inside
the request, I would need to force that.

repository(:default) do
resource = SomeModel.get(id)
resource_repository = "resource_repo_#{resource.id % 2}".to_sym
repository(resource_repository) do
view_resources = OtherModel.all
end
end

If you want, I can write out the architecture more elaborately.

--
Regards,

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

Earle Clubb

unread,
Dec 8, 2009, 7:09:57 AM12/8/09
to datam...@googlegroups.com
> --
>
> You received this message because you are subscribed to the Google Groups "DataMapper" group.
> To post to this group, send email to datam...@googlegroups.com.
> To unsubscribe from this group, send email to datamapper+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
>
>
>
Dan,

I use this feature extensively. I have a central server that acts as a
failover for multiple other devices. Each device has its own database,
a copy of which is kept on the server. So the server has an arbitrary
number of databases, all of which have identical schema. Because the
server must be able to emulate multiple devices, I use a separate thread
for each device. Each thread accesses the database for a particular
device. "The
ability for a single model to be accessible by multiple repositories all
at the *same time*," along with good threading support, is the reason I
switched from AR to DM.

Earle

Reply all
Reply to author
Forward
0 new messages