Packages
Spawn Statestores Native is a storage lib for the Spawn Actors System using Mnesia
Current section
25 Versions
Jump to
Current section
25 Versions
Compare versions
3
files changed
+190
additions
-29
deletions
| @@ -1,31 +1,32 @@ | |
| 1 | - {<<"app">>,<<"spawn_statestores_native">>}. |
| 2 | - {<<"build_tools">>,[<<"mix">>]}. |
| 3 | - {<<"description">>, |
| 4 | - <<"Spawn Statestores Native is a storage lib for the Spawn Actors System using Mnesia">>}. |
| 5 | - {<<"elixir">>,<<"~> 1.15">>}. |
| 6 | - {<<"files">>, |
| 7 | - [<<"lib">>,<<"lib/statestores">>,<<"lib/statestores/adapters">>, |
| 8 | - <<"lib/statestores/adapters/native_lookup_adapter.ex">>, |
| 9 | - <<"lib/statestores/adapters/native">>, |
| 10 | - <<"lib/statestores/adapters/native/snapshot_store.ex">>, |
| 11 | - <<"lib/statestores/adapters/native/custom_mnesiac_supervisor.ex">>, |
| 12 | - <<"lib/statestores/adapters/native/children.ex">>, |
| 13 | - <<"lib/statestores/adapters/native_snapshot_adapter.ex">>,<<"mix.exs">>, |
| 14 | - <<"README.md">>,<<"LICENSE">>]}. |
| 15 | - {<<"licenses">>,[<<"Apache-2.0">>]}. |
| 16 1 | {<<"links">>, |
| 17 2 | [{<<"GitHub">>, |
| 18 3 | <<"https://github.com/eigr/spawn/blob/main/spawn_statestores/statestores_native">>}]}. |
| 19 4 | {<<"name">>,<<"spawn_statestores_native">>}. |
| 5 | + {<<"version">>,<<"2.0.0-RC1">>}. |
| 6 | + {<<"description">>, |
| 7 | + <<"Spawn Statestores Native is a storage lib for the Spawn Actors System using Mnesia">>}. |
| 8 | + {<<"elixir">>,<<"~> 1.15">>}. |
| 9 | + {<<"app">>,<<"spawn_statestores_native">>}. |
| 10 | + {<<"files">>, |
| 11 | + [<<"lib">>,<<"lib/statestores">>,<<"lib/statestores/adapters">>, |
| 12 | + <<"lib/statestores/adapters/native_snapshot_adapter.ex">>, |
| 13 | + <<"lib/statestores/adapters/native_projection_adapter.ex">>, |
| 14 | + <<"lib/statestores/adapters/native_lookup_adapter.ex">>, |
| 15 | + <<"lib/statestores/adapters/native">>, |
| 16 | + <<"lib/statestores/adapters/native/children.ex">>, |
| 17 | + <<"lib/statestores/adapters/native/custom_mnesiac_supervisor.ex">>, |
| 18 | + <<"lib/statestores/adapters/native/snapshot_store.ex">>,<<"mix.exs">>, |
| 19 | + <<"README.md">>,<<"LICENSE">>]}. |
| 20 | + {<<"licenses">>,[<<"Apache-2.0">>]}. |
| 20 21 | {<<"requirements">>, |
| 21 | - [[{<<"app">>,<<"mnesiac">>}, |
| 22 | - {<<"name">>,<<"mnesiac">>}, |
| 22 | + [[{<<"name">>,<<"mnesiac">>}, |
| 23 | + {<<"app">>,<<"mnesiac">>}, |
| 23 24 | {<<"optional">>,false}, |
| 24 | - {<<"repository">>,<<"hexpm">>}, |
| 25 | - {<<"requirement">>,<<"~> 0.3">>}], |
| 26 | - [{<<"app">>,<<"spawn_statestores">>}, |
| 27 | - {<<"name">>,<<"spawn_statestores">>}, |
| 25 | + {<<"requirement">>,<<"~> 0.3">>}, |
| 26 | + {<<"repository">>,<<"hexpm">>}], |
| 27 | + [{<<"name">>,<<"spawn_statestores">>}, |
| 28 | + {<<"app">>,<<"spawn_statestores">>}, |
| 28 29 | {<<"optional">>,false}, |
| 29 | - {<<"repository">>,<<"hexpm">>}, |
| 30 | - {<<"requirement">>,<<"1.4.3">>}]]}. |
| 31 | - {<<"version">>,<<"1.4.3">>}. |
| 30 | + {<<"requirement">>,<<"2.0.0-RC1">>}, |
| 31 | + {<<"repository">>,<<"hexpm">>}]]}. |
| 32 | + {<<"build_tools">>,[<<"mix">>]}. |
| @@ -0,0 +1,160 @@ | |
| 1 | + defmodule Statestores.Adapters.NativeProjectionAdapter do |
| 2 | + @moduledoc """ |
| 3 | + Implements the ProjectionBehaviour for Mnesia, with dynamic table name support. |
| 4 | + """ |
| 5 | + use Statestores.Adapters.ProjectionBehaviour |
| 6 | + use GenServer |
| 7 | + |
| 8 | + alias Statestores.Schemas.Projection |
| 9 | + |
| 10 | + import Statestores.Util, only: [normalize_table_name: 1] |
| 11 | + |
| 12 | + @impl true |
| 13 | + def create_table(nil), do: {:error, "Projection name cannot be nil."} |
| 14 | + |
| 15 | + def create_table(projection_name) do |
| 16 | + table_name = normalize_table_name(projection_name) |
| 17 | + {:ok, "Table #{table_name} created or already exists."} |
| 18 | + end |
| 19 | + |
| 20 | + @impl true |
| 21 | + def get_last(nil), do: {:error, "No record found"} |
| 22 | + |
| 23 | + def get_last(projection_name) do |
| 24 | + nil |
| 25 | + end |
| 26 | + |
| 27 | + @impl true |
| 28 | + def get_last_by_projection_id(nil, _projection_id), do: {:error, "No record found"} |
| 29 | + def get_last_by_projection_id(_projection_name, nil), do: {:error, "No record found"} |
| 30 | + |
| 31 | + def get_last_by_projection_id(projection_name, projection_id) do |
| 32 | + nil |
| 33 | + end |
| 34 | + |
| 35 | + @impl true |
| 36 | + def get_all(nil, _page, _page_size), do: {:error, "No records found"} |
| 37 | + |
| 38 | + def get_all(projection_name, page \\ 1, page_size \\ 50) do |
| 39 | + nil |
| 40 | + end |
| 41 | + |
| 42 | + @impl true |
| 43 | + def get_all_by_projection_id(nil, _projection_id, _page, _page_size), |
| 44 | + do: {:error, "No records found"} |
| 45 | + |
| 46 | + def get_all_by_projection_id(_projection_name, nil, _page, _page_size), |
| 47 | + do: {:error, "No records found"} |
| 48 | + |
| 49 | + def get_all_by_projection_id(projection_name, projection_id, page \\ 1, page_size \\ 50) do |
| 50 | + nil |
| 51 | + end |
| 52 | + |
| 53 | + @impl true |
| 54 | + def get_by_interval(nil, _time_start, _time_end, _page, _page_size), |
| 55 | + do: {:error, "No records found"} |
| 56 | + |
| 57 | + def get_by_interval(_projection_name, nil, _time_end, _page, _page_size), |
| 58 | + do: {:error, "No records found"} |
| 59 | + |
| 60 | + def get_by_interval(_projection_name, _time_start, nil, _page, _page_size), |
| 61 | + do: {:error, "No records found"} |
| 62 | + |
| 63 | + def get_by_interval(projection_name, time_start, time_end, page \\ 1, page_size \\ 50) do |
| 64 | + nil |
| 65 | + end |
| 66 | + |
| 67 | + @impl true |
| 68 | + def get_by_projection_id_and_interval( |
| 69 | + nil, |
| 70 | + _projection_id, |
| 71 | + _time_start, |
| 72 | + _time_end, |
| 73 | + _page, |
| 74 | + _page_size |
| 75 | + ), |
| 76 | + do: {:error, "No records found"} |
| 77 | + |
| 78 | + def get_by_projection_id_and_interval( |
| 79 | + _projection_name, |
| 80 | + nil, |
| 81 | + _time_start, |
| 82 | + _time_end, |
| 83 | + _page, |
| 84 | + _page_size |
| 85 | + ), |
| 86 | + do: {:error, "No records found"} |
| 87 | + |
| 88 | + def get_by_projection_id_and_interval( |
| 89 | + _projection_name, |
| 90 | + _projection_id, |
| 91 | + nil, |
| 92 | + _time_end, |
| 93 | + _page, |
| 94 | + _page_size |
| 95 | + ), |
| 96 | + do: {:error, "No records found"} |
| 97 | + |
| 98 | + def get_by_projection_id_and_interval( |
| 99 | + _projection_name, |
| 100 | + _projection_id, |
| 101 | + _time_start, |
| 102 | + nil, |
| 103 | + _page, |
| 104 | + _page_size |
| 105 | + ), |
| 106 | + do: {:error, "No records found"} |
| 107 | + |
| 108 | + def get_by_projection_id_and_interval( |
| 109 | + projection_name, |
| 110 | + projection_id, |
| 111 | + time_start, |
| 112 | + time_end, |
| 113 | + page \\ 1, |
| 114 | + page_size \\ 50 |
| 115 | + ) do |
| 116 | + nil |
| 117 | + end |
| 118 | + |
| 119 | + @impl true |
| 120 | + def search_by_metadata( |
| 121 | + projection_name, |
| 122 | + metadata_key, |
| 123 | + metadata_value, |
| 124 | + page \\ 1, |
| 125 | + page_size \\ 50 |
| 126 | + ) do |
| 127 | + nil |
| 128 | + end |
| 129 | + |
| 130 | + @impl true |
| 131 | + def search_by_projection_id_and_metadata( |
| 132 | + projection_name, |
| 133 | + projection_id, |
| 134 | + metadata_key, |
| 135 | + metadata_value, |
| 136 | + page \\ 1, |
| 137 | + page_size \\ 50 |
| 138 | + ) do |
| 139 | + nil |
| 140 | + end |
| 141 | + |
| 142 | + @impl true |
| 143 | + def save(%Projection{} = projection) do |
| 144 | + {:ok, projection} |
| 145 | + end |
| 146 | + |
| 147 | + @impl true |
| 148 | + def default_port, do: "0000" |
| 149 | + |
| 150 | + def child_spec(_), |
| 151 | + do: %{ |
| 152 | + id: __MODULE__, |
| 153 | + start: {__MODULE__, :start_link, []} |
| 154 | + } |
| 155 | + |
| 156 | + def start_link, do: GenServer.start_link(__MODULE__, [], name: __MODULE__) |
| 157 | + |
| 158 | + @impl GenServer |
| 159 | + def init(_), do: {:ok, nil} |
| 160 | + end |
| @@ -2,7 +2,7 @@ defmodule StatestoresNative.MixProject do | |
| 2 2 | use Mix.Project |
| 3 3 | |
| 4 4 | @app :spawn_statestores_native |
| 5 | - @version "1.4.3" |
| 5 | + @version "2.0.0-RC1" |
| 6 6 | @source_url "https://github.com/eigr/spawn/blob/main/spawn_statestores/statestores_native" |
| 7 7 | |
| 8 8 | def project do |
| @@ -13,10 +13,10 @@ defmodule StatestoresNative.MixProject do | |
| 13 13 | "Spawn Statestores Native is a storage lib for the Spawn Actors System using Mnesia", |
| 14 14 | source_url: @source_url, |
| 15 15 | homepage_url: "https://eigr.io/", |
| 16 | - build_path: "../../_build", |
| 16 | + build_path: "./_build", |
| 17 17 | config_path: "../../config/config.exs", |
| 18 | - deps_path: "../../deps", |
| 19 | - lockfile: "../../mix.lock", |
| 18 | + deps_path: "./deps", |
| 19 | + lockfile: "./mix.lock", |
| 20 20 | elixir: "~> 1.15", |
| 21 21 | start_permanent: Mix.env() == :prod, |
| 22 22 | deps: deps(), |
| @@ -58,7 +58,7 @@ defmodule StatestoresNative.MixProject do | |
| 58 58 | [ |
| 59 59 | {:ex_doc, ">= 0.0.0", only: :dev, runtime: false}, |
| 60 60 | {:mnesiac, "~> 0.3"}, |
| 61 | - {:spawn_statestores, "1.4.3"} |
| 61 | + {:spawn_statestores, "2.0.0-RC1"} |
| 62 62 | ] |
| 63 63 | end |