Created
July 31, 2013 16:28
-
-
Save jschoch/6123631 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule DBT do | |
def get_by_key(module,key,value) do | |
s = Exquisite.match module, | |
where: key == value | |
Amnesia.transaction do | |
case apply(module,:select,[s]) do | |
nil -> [] | |
res -> res.values | |
end | |
end | |
end | |
# add or update | |
def aou(module,key,attributes) do | |
case get_by_key(module,key,value) do | |
[] -> | |
Amnesia.transaction do | |
apply(module,:new,[attributes]) | |
end | |
record -> | |
Amnesia.transaction do | |
record.update(attributes) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment