[erlang-questions] Chicago Boss Array Fields in Models
Manuel A. Rubio "Bombadil"
bombadil@REDACTED
Tue May 27 12:32:30 CEST 2014
Hi Ivan,
I think arrays is not well supported for retrieve information from
postgres, I afraid, if you go to a psql terminal and run a simple:
SELECT emails FROM users;
You realise the output is the same that you get with boss_db. Perhaps
you should normalice the data, create another table for emails and
another model using -has or -belongs instead.
Another solution is create a parser for that and in the model, use a
specific function to get the data parsed. But I think this is more
complex to do.
Regards.
Manuel Rubio.
El 2014-05-23 23:03, Ivan Carmenates García escribió:
> Hi every one,
>
> I was wondering how CB treats the database array fields,
>
> If I have for example a postgres script like this one:
>
> CREATE TABLE users (
>
> id PRIMARY KEY,
>
> name varchar(50),
>
> emails varchar(50) []
>
> )
>
> In CB a model like this:
>
> -module(users, [Id, Name, Emails]).
>
> So I have inserted a record in the database and it looks as follow:
>
> Id name emails
>
> 1 Will {will@REDACTED, will89@REDACTED, will2014@REDACTED}
>
> When I do a bossdb:find(users, []) for the field emails I got <<"{will@REDACTED, will89@REDACTED, will2014@REDACTED}">>
>
> My question is obviously, WTF??? Sorry about that!! How can I parse that!!! To a nicely, normal, pretty, good syntax of CB.
>
> Even I tried from the view to get the value and the value I got is {will@REDACTED, will89@REDACTED, will2014@REDACTED} in the view
>
> test_array('GET', []) ->
>
> L = boss_db:find(test, []),
>
> [{_, _, Emails} | R] = L,
>
> {ok, [{emails, Emails}]}.
>
> For the view
>
> <ul>
>
> {% if emails %}
>
> {{ emails }}
>
> {% else %}
>
> <li>Nothing to do.</li>
>
> {% endif %}
>
> </ul>
>
> Best regards,
>
> Ivan.
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions [1]
Links:
------
[1] http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140527/66cc1867/attachment.htm>
More information about the erlang-questions
mailing list