OK, the problem is that the Postgres adapter returns {ok,0} from the update
attempt, instead of the expected {ok, _, _, [0]}. It's not clear to me
whether the adapter should be changed, or if the change should happen in
boss_db:incr(). For now, I've implemented a local function to do the job.
incr(Name) ->
Res = boss_db:execute("UPDATE counters SET value = value + 1 WHERE name
= $1 RETURNING value;", [Name]),
case Res of
{ok, 0} ->
Res1 = boss_db:execute("INSERT INTO counters (name, value)
VALUES ($1, 1) RETURNING value;",
[Name]),
case Res1 of
{ok, _, _, [{Value}]} -> Value;
{error, Reason} -> {error, Reason}
end;
{ok, Value} -> Value;
{ok, _, _, [{Value}]} -> Value
end.
I'd be happy to do a patch for boss_db:incr, if that's the right way. I'm
less sure about the Postgres adapter.
- ken
--
You received this message because you are subscribed to the Google Groups
"ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at http://groups.google.com/group/chicagoboss.
To view this discussion on the web visit
https://groups.google.com/d/msgid/chicagoboss/12e5772d-5631-4e6e-81ed-355d686753c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.