Current section
13 Versions
Jump to
Current section
13 Versions
Compare versions
4
files changed
+22
additions
-19
deletions
| @@ -32,7 +32,7 @@ Add `ecto_instashard` to your list of dependencies in `mix.exs`: | |
| 32 32 | |
| 33 33 | ```elixir |
| 34 34 | def deps do |
| 35 | - [{:ecto_instashard, "~> 0.3"}] |
| 35 | + [{:ecto_instashard, "~> 0.4"}] |
| 36 36 | end |
| 37 37 | ``` |
| 38 38 | |
| @@ -212,7 +212,7 @@ repository = ChatApp.Shards.Messages.repository(message.user_id) | |
| 212 212 | Use the helper functions included in the modules `Ecto.InstaShard.Shards.[Shard]` to perform operations in the correct shard for a user id. |
| 213 213 | |
| 214 214 | - add_query_prefix/2 (to add the related user_id sharded PostgreSQL schema name to the table name) |
| 215 | - - sharded_insert/3, sharded_query/3 |
| 215 | + - sharded_insert/3, sharded_select_query/3, sharded_query/2, sharded_query_all/2, sharded_query_one/2 |
| 216 216 | - insert_all/3, insert_all/4 (supports schemaless changesets: `embedded_schema`) |
| 217 217 | - update_all/4, update_all/5, update_with_query/4 |
| 218 218 | - delete_all/3, delete_all/4, delete_with_query/4 |
| @@ -30,4 +30,4 @@ | |
| 30 30 | {<<"optional">>,false}, |
| 31 31 | {<<"repository">>,<<"hexpm">>}, |
| 32 32 | {<<"requirement">>,<<">= 0.0.0">>}]]}. |
| 33 | - {<<"version">>,<<"0.3.5">>}. |
| 33 | + {<<"version">>,<<"0.4.0">>}. |
| @@ -169,11 +169,26 @@ defmodule Ecto.InstaShard.Sharding.Setup do | |
| 169 169 | insert_all(parent_id, table_name, [changeset], opts) |
| 170 170 | end |
| 171 171 | |
| 172 | - def sharded_query(parent_id, table_name, where) do |
| 172 | + def sharded_select_query(parent_id, table_name, where) do |
| 173 173 | from(m in table_name, where: ^where) |
| 174 174 | |> add_query_prefix(parent_id) |
| 175 175 | end |
| 176 176 | |
| 177 | + def sharded_query(parent_id, query) do |
| 178 | + query |
| 179 | + |> add_query_prefix(parent_id) |
| 180 | + end |
| 181 | + |
| 182 | + def sharded_query_all(parent_id, query) do |
| 183 | + sharded_query(parent_id, query) |
| 184 | + |> repository(parent_id).all() |
| 185 | + end |
| 186 | + |
| 187 | + def sharded_query_one(parent_id, query) do |
| 188 | + sharded_query(parent_id, query) |
| 189 | + |> repository(parent_id).one() |
| 190 | + end |
| 191 | + |
| 177 192 | def add_query_prefix(query, parent_id) do |
| 178 193 | %{query | prefix: shard_name(parent_id)} |
| 179 194 | end |
| @@ -241,7 +256,7 @@ defmodule Ecto.InstaShard.Sharding.Setup do | |
| 241 256 | end |
| 242 257 | |
| 243 258 | def update_all(parent_id, table_name, where, update, opts) do |
| 244 | - sharded_query(parent_id, table_name, where) |
| 259 | + sharded_select_query(parent_id, table_name, where) |
| 245 260 | |> repository(parent_id).update_all([set: update], opts) |
| 246 261 | end |
| 247 262 | |
| @@ -254,7 +269,7 @@ defmodule Ecto.InstaShard.Sharding.Setup do | |
| 254 269 | end |
| 255 270 | |
| 256 271 | def delete_all(parent_id, table_name, where, opts) do |
| 257 | - sharded_query(parent_id, table_name, where) |
| 272 | + sharded_select_query(parent_id, table_name, where) |
| 258 273 | |> repository(parent_id).delete_all(opts) |
| 259 274 | end |
| @@ -3,7 +3,7 @@ defmodule Ecto.InstaShard.Mixfile do | |
| 3 3 | |
| 4 4 | def project do |
| 5 5 | [app: :ecto_instashard, |
| 6 | - version: "0.3.5", |
| 6 | + version: "0.4.0", |
| 7 7 | elixir: "~> 1.3", |
| 8 8 | build_embedded: Mix.env == :prod, |
| 9 9 | start_permanent: Mix.env == :prod, |
| @@ -13,22 +13,10 @@ defmodule Ecto.InstaShard.Mixfile do | |
| 13 13 | deps: deps()] |
| 14 14 | end |
| 15 15 | |
| 16 | - # Configuration for the OTP application |
| 17 | - # |
| 18 | - # Type "mix help compile.app" for more information |
| 19 16 | def application do |
| 20 17 | [applications: [:logger]] |
| 21 18 | end |
| 22 19 | |
| 23 | - # Dependencies can be Hex packages: |
| 24 | - # |
| 25 | - # {:mydep, "~> 0.3.0"} |
| 26 | - # |
| 27 | - # Or git/path repositories: |
| 28 | - # |
| 29 | - # {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"} |
| 30 | - # |
| 31 | - # Type "mix help deps" for more examples and options |
| 32 20 | defp deps do |
| 33 21 | [{:postgrex, "~> 0.13"}, |
| 34 22 | {:ecto, "~> 2.2"}, |