[erlang-questions] How best to return db query

Bernard Duggan bernard@REDACTED
Mon Feb 8 03:32:31 CET 2016


Sure, but who's to say get_note is intended as "just" a db interface
function? That was my point in saying that it depends on the intended
semantics of that function.The fact that he was considering giving the
empty case an 'error' tag suggests that perhaps there's more to it. But
there's not enough information in the original question to make a judgement
either way.

B

On Mon, Feb 8, 2016 at 1:21 PM, Sergej Jurečko <sergej.jurecko@REDACTED>
wrote:

> I disagree. That kind of logic does not belong in a db interface function.
>
> Sergej
> On Feb 8, 2016 1:25 AM, "Bernard Duggan" <bernard@REDACTED> wrote:
>
>> >An empty result to a db query is not an error.
>> That rather depends on the semantics of your program. In the general
>> case, you're absolutely right, of course - that's why mnesia:read() doesn't
>> return an error in that case. However, perhaps in the case of Lloyd's
>> application, there should always be something in that particular table -
>> maybe something populated at startup that nothing should ever delete. In
>> that case it would be perfectly reasonable to not just produce an error,
>> but in fact to crash.
>> So I guess what I'm saying is that my answer would be "it depends on what
>> you want the semantics of get_note to be". Is it expected to always return
>> one or more values? Is it an error if it doesn't, and if so, is that error
>> sensibly recoverable by the caller?
>>
>> Cheers,
>>
>> B
>>
>> On Mon, Feb 8, 2016 at 5:45 AM, Sergej Jurečko <sergej.jurecko@REDACTED>
>> wrote:
>>
>>> An empty result to a db query is not an error.
>>>
>>> Sergej
>>> On Feb 7, 2016 7:38 PM, <lloyd@REDACTED> wrote:
>>>
>>>> Hello,
>>>>
>>>> I have this mnesia query:
>>>>
>>>>
>>>> get_note(ID) ->
>>>>     Query =
>>>>         fun() ->
>>>>             mnesia:read({?TABLE, ID})
>>>>         end,
>>>>     {atomic, Results} = mnesia:transaction(Query),
>>>>     Results.
>>>>
>>>> It returns either a list containing one or more valid records or an
>>>> empty list.
>>>>
>>>> Would it be better to return something like:
>>>>
>>>> {ok, Records} | {error, data_not_found}
>>>>
>>>> Thanks,
>>>>
>>>> LRP
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> erlang-questions mailing list
>>>> erlang-questions@REDACTED
>>>> http://erlang.org/mailman/listinfo/erlang-questions
>>>>
>>>
>>> _______________________________________________
>>> erlang-questions mailing list
>>> erlang-questions@REDACTED
>>> http://erlang.org/mailman/listinfo/erlang-questions
>>>
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160208/4a75f261/attachment.htm>


More information about the erlang-questions mailing list