zorn
Looking for advice on how best a module that manages a multi-tenant data backend should handle prefix values
I’m building a new module for my multi-tenant application and trying to come to terms how a prefix ideally be passed in. Here is a new style using an opts keyword list with a required prefix value. I like this since I could also use a preloads option for get style functions letting the caller decide which relationships should be preloaded; I think this preload style will come in handy for my GraphQL stuff. Anyways would love some API design feedback on this draft:
defmodule Guildflow.Invites do
@moduledoc """
Provides functions for creating invites that will be shared with prospective
members. Using an invite a `Member` account can be created.
"""
alias Guildflow.Invites.{Invite}
alias Guildflow.Repo
@expiration_length_in_seconds 60 * 60 * 24 * 7
@doc """
Generates and stores a fresh invite.
## Options
* `:prefix` - The database prefix to use for the insert. (required)
* `:preloads` - a list of relationships that will be preloaded on the
returned records. (demo of an option that would be on a get style
function)
"""
@spec create_invite(keyword) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
def create_invite(opts \\ []) do
expires_on =
DateTime.utc_now()
|> DateTime.add(@expiration_length_in_seconds, :second)
|> DateTime.truncate(:second)
changeset =
Invite.changeset(%Invite{}, %{
"token" => UUID.uuid4(),
"expires_on" => expires_on
})
Repo.insert(changeset, prefix: prefix_from_options(opts))
end
def register_member_from_invite(_invite) do
end
defp prefix_from_options(opts) do
case Keyword.get(opts, :prefix, []) do
nil ->
throw("required prefix missing")
prefix ->
prefix
end
end
end
Popular in Questions
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
Hi everyone,
I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
Hi there,
I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone.
What strikes me is th...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
Other popular topics
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Phoenix 1.4.0 released
Phoenix 1.4 is out! This release ships with exciting new features, most notably
with HTTP2 support, improved deve...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Hi everyone,
One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
Hello everyone,
Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance










