Skip to content

Commit

Permalink
tables: move transaction function
Browse files Browse the repository at this point in the history
  • Loading branch information
ProducerMatt committed Mar 22, 2024
1 parent d666a6c commit 38260d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
11 changes: 1 addition & 10 deletions lib/stampede/interact.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule Stampede.Interact do
require Logger
alias Stampede, as: S
alias S.Tables.{Ids, Interactions, ChannelLocks}
import S.Tables, only: [transaction!: 1]
use TypeCheck
use TypeCheck.Defstruct

Expand Down Expand Up @@ -303,16 +304,6 @@ defmodule Stampede.Interact do
end)
end

@spec! transaction!((... -> any())) :: any()
def transaction!(f) do
Memento.Transaction.execute!(f, 10)
end

@spec! transaction_sync!((... -> any())) :: any()
def transaction_sync!(f) do
Memento.Transaction.execute_sync!(f, 10)
end

@spec! id_exists?(S.interaction_id()) :: boolean()
def id_exists?(id) do
transaction!(fn ->
Expand Down
13 changes: 13 additions & 0 deletions lib/stampede/tables.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
defmodule Stampede.Tables do
@moduledoc """
Manage various Mnesia tables.
"""
require Logger
use TypeCheck
alias Stampede, as: S
Expand All @@ -24,6 +27,16 @@ defmodule Stampede.Tables do
:ok
end

@spec! transaction!((... -> any())) :: any()
def transaction!(f) do
Memento.Transaction.execute!(f, 10)
end

@spec! transaction_sync!((... -> any())) :: any()
def transaction_sync!(f) do
Memento.Transaction.execute_sync!(f, 10)
end

def clear_all_tables() do
Logger.info("Tables: clearing all tables for #{Mix.env()}")

Expand Down

0 comments on commit 38260d2

Please sign in to comment.