Skip to content
Permalink
Browse files

initial commit

  • Loading branch information...
Qqwy committed Mar 13, 2019
0 parents commit b63dd4858370e136860eb4106e47ab50a618b13f
Showing with 187 additions and 0 deletions.
  1. +4 −0 .formatter.exs
  2. +24 −0 .gitignore
  3. +21 −0 README.md
  4. +30 −0 config/config.exs
  5. +60 −0 lib/riak_ecto3.ex
  6. +30 −0 mix.exs
  7. +9 −0 mix.lock
  8. +8 −0 test/riak_ecto3_test.exs
  9. +1 −0 test/test_helper.exs
@@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
@@ -0,0 +1,24 @@
# The directory Mix will write compiled artifacts to.
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover/

# The directory Mix downloads your dependencies sources to.
/deps/

# Where 3rd-party dependencies like ExDoc output generated docs.
/doc/

# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Ignore package tarball (built via "mix hex.build").
riak_ecto3-*.tar

@@ -0,0 +1,21 @@
# RiakEcto3

**TODO: Add description**

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `riak_ecto3` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[
{:riak_ecto3, "~> 0.1.0"}
]
end
```

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/riak_ecto3](https://hexdocs.pm/riak_ecto3).

@@ -0,0 +1,30 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config

# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
# file won't be loaded nor affect the parent project. For this reason,
# if you want to provide default values for your application for
# 3rd-party users, it should be done in your "mix.exs" file.

# You can configure your application as:
#
# config :riak_ecto3, key: :value
#
# and access this configuration in your application as:
#
# Application.get_env(:riak_ecto3, :key)
#
# You can also configure a 3rd-party app:
#
# config :logger, level: :info
#

# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
#
# import_config "#{Mix.env()}.exs"
@@ -0,0 +1,60 @@
defmodule RiakEcto3 do
@moduledoc """
Riak KV 2.0 adapter for Ecto 3.
Works by mapping Ecto Schemas to Riak Map-CRDTs.
"""

@behaviour Ecto.Adapter

@impl Ecto.Adapter
defmacro __before_compile__(env) do
IO.puts "Before Compile of RiakEcto3"

quote do
def get(struct_name, id, opts \\ []) do
IO.puts "TODO: Implement Repo.get for Riak: (1) struct_name -> Riak bucket name. (2) id -> Riak key name!"
end
end
end

@impl Ecto.Adapter
@doc """
NOTE: Currently we are not using the connection pool to keep the implementation simple.
This could be changed later since `Riak` provides one.
"""
def checkout(adapter_meta, config, fun) do
fun.()
end

@impl Ecto.Adapter
@doc """
TODO Properly implement
"""
def dumpers(primitive_type, ecto_type)
def dumpers(:binary_id, type), do: [type, Ecto.UUID]
def dumpers(_primitive, type), do: [type]

@impl Ecto.Adapter
@doc """
TODO double-check implementation
"""
def ensure_all_started(config, app_restart_type) do
{:ok, []}
end

@impl Ecto.Adapter
@doc """
TODO double-check implementation
"""
def init(config) do
{:ok, Supervisor.child_spec(Riak.Connection, [])}
end

@impl Ecto.Adapter
@doc """
TODO Properly implement
"""
def loaders(primitive_type, ecto_type)
def loaders(:binary_id, type), do: [Ecto.UUID, type]
def loaders(_primitive, type), do: [type]
end
30 mix.exs
@@ -0,0 +1,30 @@
defmodule RiakEcto3.MixProject do
use Mix.Project

def project do
[
app: :riak_ecto3,
version: "0.1.0",
elixir: "~> 1.7",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end

# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end

# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:ecto, "~> 3.0"},
{:riak, "~> 1.0"}
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"},
]
end
end
@@ -0,0 +1,9 @@
%{
"decimal": {:hex, :decimal, "1.7.0", "30d6b52c88541f9a66637359ddf85016df9eb266170d53105f02e4a67e00c5aa", [:mix], [], "hexpm"},
"ecto": {:hex, :ecto, "3.0.7", "44dda84ac6b17bbbdeb8ac5dfef08b7da253b37a453c34ab1a98de7f7e5fec7f", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm"},
"hamcrest": {:hex, :basho_hamcrest, "0.4.1", "fb7b2c92d252a1e9db936750b86089addaebeb8f87967fb4bbdda61e8863338e", [:make, :mix, :rebar3], [], "hexpm"},
"pooler": {:hex, :pooler, "1.5.3", "898cd1fa301fc42d4a8ed598ce139b71ca85b54c16ab161152b5cc5fbdcfa1a8", [:rebar3], [], "hexpm"},
"riak": {:hex, :riak, "1.1.6", "e69c48ef5c19b98484ac9dc5ee84a414f676bdceb55ffd5fa9e0fbbad4842fb5", [:mix], [{:pooler, "~> 1.5.3", [hex: :pooler, repo: "hexpm", optional: false]}, {:riakc, "~> 2.5.3", [hex: :riakc, repo: "hexpm", optional: false]}], "hexpm"},
"riak_pb": {:hex, :riak_pb, "2.3.2", "48ffbf66dbb3f136ab9a7134bac4e496754baa5ef58c4f50a61326736d996390", [:make, :mix, :rebar3], [{:hamcrest, "~> 0.4.1", [hex: :basho_hamcrest, repo: "hexpm", optional: false]}], "hexpm"},
"riakc": {:hex, :riakc, "2.5.3", "6132d9e687a0dfd314b2b24c4594302ca8b55568a5d733c491d8fb6cd4004763", [:make, :mix, :rebar3], [{:riak_pb, "~> 2.3", [hex: :riak_pb, repo: "hexpm", optional: false]}], "hexpm"},
}
@@ -0,0 +1,8 @@
defmodule RiakEcto3Test do
use ExUnit.Case
doctest RiakEcto3

test "greets the world" do
assert RiakEcto3.hello() == :world
end
end
@@ -0,0 +1 @@
ExUnit.start()

0 comments on commit b63dd48

Please sign in to comment.
You can’t perform that action at this time.