Erlang Mailing Lists

Author Message

<  Erlyweb mailing list  ~  creating a generic expand function

Guest
Posted: Wed Aug 22, 2007 12:14 am Reply with quote
Guest
I have several tables which includes table2_id which refer to an id in
another table table2. I which to walk the tree formed by these table
relationships and get back a list which is a zip of the form {name,
value}. That's not very clear let me try an example. Six tables,

person
id int
name varchar(20)
address_id int relation 1:N
position_id int relation N:1

address
id int
building varchar(200)
street_id int relation N:1

street
id int
street varchar(200)
locality_id int relation N:1

locality
id int
name varchar(200)
postcode varchar(20)
state_id int relation N:1

state
id int
name varchar(200)
abbrevation varchar(5)

position
id
title varchar(200)


may result in something along the lines of

[{name, "Fred"},
[
[{building, "The Block"},
{street, "Smith Drive"},
{locatity_name, "Jonesville"},
{locality_postcode, "2000"},
{state_name, "New South Wales"},
{state_abbrevation, "NSW"},
],
[.....]
],
{position_title, "Carpenter"}
]

For tables entries each field should be {Name, Value}
For subtables,
N:1 insert the tuple directly into the list
1:N insert a list where each entry is an expanded record.
N:N " " " " " " "

This is going to be passed to the view to render something similar to

Fred the Carpenter is location at the following locations

The Block,
Smith Drive
Jonesville
NSW 2000

.....

Is there already something floating around somewhere that can do this?
Is there a better way to accomplish this?

Also, is there a limited templating language or a safe mode to erltl so
that arbitrary functions cannot be called?


Jeff.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
Guest
Posted: Thu Aug 23, 2007 1:52 am Reply with quote
Guest
jm wrote:
> I have several tables which includes table2_id which refer to an id in
> another table table2. I which to walk the tree formed by these table
> relationships and get back a list which is a zip of the form {name,
> value}. That's not very clear let me try an example. Six tables,
....
> [{name, "Fred"},
> [
> [{building, "The Block"},
> {street, "Smith Drive"},
> {locatity_name, "Jonesville"},
> {locality_postcode, "2000"},
> {state_name, "New South Wales"},
> {state_abbrevation, "NSW"},
> ],
> [.....]
> ],
> {position_title, "Carpenter"}
> ]
>

I sent a few hours before sending this original message and a few hours
after attempting to solve it. It screams compile time to me, but as I
had no wish to go playing with erlyweb's internal for code generation
(is there a hook for this?) I attempted to solve it at run time and gave
up for the moment. Instead, hard coding a substitution for those models
that it will be needed in.

> Also, is there a limited templating language or a safe mode to erltl so
> that arbitrary functions cannot be called?

To word this another way: Is there a templating library that is safe to
be used by the general public?


Jeff.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
Guest
Posted: Thu Aug 23, 2007 3:09 am Reply with quote
Guest
On 8/22/07, jm <jeffm@ghostgun.com> wrote:
>
> jm wrote:
> > I have several tables which includes table2_id which refer to an id in
> > another table table2. I which to walk the tree formed by these table
> > relationships and get back a list which is a zip of the form {name,
> > value}. That's not very clear let me try an example. Six tables,
> ....
> > [{name, "Fred"},
> > [
> > [{building, "The Block"},
> > {street, "Smith Drive"},
> > {locatity_name, "Jonesville"},
> > {locality_postcode, "2000"},
> > {state_name, "New South Wales"},
> > {state_abbrevation, "NSW"},
> > ],
> > [.....]
> > ],
> > {position_title, "Carpenter"}
> > ]
> >
>
> I sent a few hours before sending this original message and a few hours
> after attempting to solve it. It screams compile time to me, but as I
> had no wish to go playing with erlyweb's internal for code generation
> (is there a hook for this?) I attempted to solve it at run time and gave
> up for the moment. Instead, hard coding a substitution for those models
> that it will be needed in.

You can do this at runtime. It's a bit tricky, but it can be done.
Every model has a relations() function. You can recursively scan the
result of relations() and build an in-memory graph of your tables and
their relations. Then you can write a function that takes this graph
and converts it into a SQL query. Using the model's db_field_names()
function, you can map the the result of this query to the nested
structure you have above. All this stuff can also be done in compile
time to remove the cost of building the graph and creating the
mapping, but that's an optimization you can worry about later.


>
> > Also, is there a limited templating language or a safe mode to erltl so
> > that arbitrary functions cannot be called?
>
> To word this another way: Is there a templating library that is safe to
> be used by the general public?

I know ErlHive does a parse transform that makes an Erlang module safe
to execute. Since ErlTL generates Erlang modules, those modules could
be "sanitized" by ErlHive before they are deployed. This feature isn't
built into ErlyWeb, but it wouldn't be that hard to add it.

Yariv

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum