[erlang-questions] Chicago Boss Array Fields in Models

Ivan Carmenates García co7eb@REDACTED
Fri May 30 16:21:13 CEST 2014

Hi David, thanks for answer me.

Okay, in the case of arrays maybe I could normalize even more the database
to include new tables for the arrayed fields, but what about execute? I
mean, when I need to make more complex queries to the database like using
many tables in the query with many filters, then I will have in the result
all the records of all the tables mixed, that is fine for me still, because
I can intentionality extract the values from the result and make a proplist
with the values to pass it to the template like this: {ok, [{result, [{name,
Name}, {post, Post }]}]}, to access from the template in this way:
result.name, result.post.

But still it is a little bit awkward to extract the nice values from the
result of an execute, could be over there a function that translate that
result to a nice proplist? Ex: if boss_db:execute/1 returns a list of
columns with its names and types and a list of values, a proplist could be
made as a kind of return value from execute, the proplist will have the
following structure, from the execute result: 

      <<"2014-05-26 15:09:34">>}]}

Second value of each line tuple is the field name and the key in the
And the corresponded value is the value of the key in the proplist.

[{id, "2"},
 {username, "john"},
 {email, " john@REDACTED"},
 {password , "55f5d08a12e5c9857c45c05be7ae468a"},
 {password_old, "55f5d08a12e5c9857c45c05be7ae468a"},
 {activated, "true"},
 {activation_token, "97cc79a8ea3d1ddbcc35dd82016056359b489412"},
 {activation_token_created_date, "2014-05-26 15:09:34"}]

Of cource the proplist values and keys without any ugly binary format.

Best regards,

-----Mensaje original-----
De: erlang-questions-bounces@REDACTED
[mailto:erlang-questions-bounces@REDACTED] En nombre de David Welton
Enviado el: viernes, 30 de mayo de 2014 04:57 a.m.
Para: Manuel A. Rubio Bombadil
CC: Erlang Questions
Asunto: Re: [erlang-questions] Chicago Boss Array Fields in Models

> 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 can get the raw data out without much trouble:

create table foo (emails varchar[]);

insert into foo (emails) values ('{"a", "b", "c"}');

boss_db:execute("select * from foo", []).

Keep in mind that, with Chicago Boss and Postgres

boss_db:execute("select * from foo", []).

uses a different underlying function than

boss_db:execute("select * from foo")

With the latter returning mostly binaries.

> 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.

Normalizing the data might be a good idea in any case.

David N. Welton


erlang-questions mailing list

More information about the erlang-questions mailing list