condo v0.2.4 Condo.Repo View Source

This repo is very similar to Ecto.Repo but instead of being a module to be extended, it's a module meant to be used to map tenants to database instances in case you are sharding tenants. It also provides feature parity with Ecto.Repo by using meta-programming and adding the prefix into the options.

A Note on Replicas

Please note that we did not include some functions in the tenant to repo mapper since they tend to map to different server instances. If you have a repo and different DB instances which are replicated, then you could risk starting a transaction on one server and closing it on another. To avoid this, we simply do not allow you (it's a sneaky problem) and instead recommend to use a little less sugar. Here's an example if Ecto.Repo.stream/3 and Ecto.Repo.transaction/2 were implemented:

# Grab a stream from `Repo.Foo.Replica1`
stream = Condo.Repo.stream(User, :foo)

# Start a transaction on `Repo.Foo.Replica2`
Condo.Repo.transaction(fn -> Enum.to_list(stream) end, :foo)

Instead, Condo recommends that you lookup the repo first and then run your transactions:

repo = Condo.Repo.repo(:foo)
stream = repo.stream(User, prefix: Condo.prefix(:foo))
repo.transaction(fn -> Enum.to_list(stream) end, prefix: Condo.prefix(:foo))

This is far more safe and allows you to scale to read replicas in the future. Functions from Ecto.Repo not implemented:

  • checkout/2
  • in_transaction?/0
  • rollback/1
  • stream/2
  • transaction/2

Link to this section Summary

Link to this section Functions

Link to this function

aggregate(first_arg, second_arg, third_arg, tenant, opts \\ [])

View Source
Link to this function

all(first_arg, tenant, opts \\ [])

View Source
Link to this function

delete(first_arg, tenant, opts \\ [])

View Source
Link to this function

delete!(first_arg, tenant, opts \\ [])

View Source
Link to this function

delete_all(first_arg, tenant, opts \\ [])

View Source
Link to this function

exists?(first_arg, tenant, opts \\ [])

View Source
Link to this function

get(first_arg, second_arg, tenant, opts \\ [])

View Source
Link to this function

get!(first_arg, second_arg, tenant, opts \\ [])

View Source
Link to this function

get_by(first_arg, second_arg, tenant, opts \\ [])

View Source
Link to this function

get_by!(first_arg, second_arg, tenant, opts \\ [])

View Source
Link to this function

insert(first_arg, tenant, opts \\ [])

View Source
Link to this function

insert!(first_arg, tenant, opts \\ [])

View Source
Link to this function

insert_all(first_arg, second_arg, tenant, opts \\ [])

View Source
Link to this function

insert_or_update(first_arg, tenant, opts \\ [])

View Source
Link to this function

insert_or_update!(first_arg, tenant, opts \\ [])

View Source
Link to this function

one(first_arg, tenant, opts \\ [])

View Source
Link to this function

one!(first_arg, tenant, opts \\ [])

View Source
Link to this function

preload(first_arg, second_arg, tenant, opts \\ [])

View Source
Link to this function

prepare_query(first_arg, second_arg, tenant, opts \\ [])

View Source
Link to this function

update(first_arg, tenant, opts \\ [])

View Source
Link to this function

update!(first_arg, tenant, opts \\ [])

View Source
Link to this function

update_all(first_arg, second_arg, tenant, opts \\ [])

View Source