Skip to content

Instantly share code, notes, and snippets.

@jschoch
Created July 31, 2013 16:28
Show Gist options
  • Save jschoch/6123631 to your computer and use it in GitHub Desktop.
Save jschoch/6123631 to your computer and use it in GitHub Desktop.
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