Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.
/ autochef Public archive

Commit c054248

Browse files
committed
Updated recipe imports
1 parent e86101c commit c054248

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

dbs/autochef/functions/feeds/fn_importrecipes.sql

+15-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ create or replace function fn_importrecipes
55
returns setof record as
66
'
77
begin
8+
create temporary table ingredients
9+
(
10+
ingredientid varchar(12),
11+
duration interval
12+
);
13+
14+
insert into ingredients (ingredientid, duration)
15+
select
16+
(xpath(''/ingredient/@ingredientid'', t.xml))[1],
17+
coalesce(nullif((xpath(''/ingredient/@duration'', t.xml))[1]::text, ''''), ''0'')::interval
18+
from unnest(xpath(''/xml/ingredients/ingredient'', input)) as t;
19+
820
create temporary table translations
921
(
1022
ingredientid varchar(12),
@@ -35,8 +47,9 @@ begin
3547
3648
return query
3749
select *
38-
from translations as t
39-
join dependencies as d on d.childid = t.ingredientid;
50+
from ingredients as i
51+
join dependencies as d on d.childid = i.ingredientid
52+
join translations as t on t.ingredientid = i.ingredientid;
4053
end;
4154
'
4255
language plpgsql;

idx/rdl/example.rdl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<recipes>
22

33
<!-- Spaghetti Bolognese -->
4-
<recipe>
4+
<recipe duration="10 minutes">
55

66
<locale languageid="en">
77
<name>spaghetti bolognese</name>

idx/rdl/example.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
psql autochef -c "select * from fn_importrecipes('`xsltproc flatten.xslt example.rdl`') as (ingredientid varchar(12), languageid char(2), name text, instructions text, parentid varchar(12), childid varchar(12))"
1+
psql autochef -c "select * from fn_importrecipes('`xsltproc flatten.xslt example.rdl`') as (ingredientid varchar(12), duration interval, parentid varchar(12), childid varchar(12), translationingredientid varchar(12), languageid char(2), name text, instructions text)"

idx/rdl/flatten.xslt

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,21 @@
55

66
<xsl:template match="recipes">
77
<xml>
8+
<ingredients><xsl:call-template name="ingredients" /></ingredients>
89
<translations><xsl:call-template name="translations" /></translations>
910
<dependencies><xsl:call-template name="dependencies" /></dependencies>
1011
</xml>
1112
</xsl:template>
1213

14+
<xsl:template name="ingredients">
15+
<xsl:for-each select="//recipe|//ingredient|//product">
16+
<xsl:element name="ingredient">
17+
<xsl:attribute name="ingredientid"><xsl:value-of select="generate-id()" /></xsl:attribute>
18+
<xsl:attribute name="duration"><xsl:value-of select="@duration" /></xsl:attribute>
19+
</xsl:element>
20+
</xsl:for-each>
21+
</xsl:template>
22+
1323
<xsl:template name="translations">
1424
<xsl:for-each select="//locale">
1525
<xsl:element name="translation">
@@ -29,8 +39,8 @@
2939
</xsl:for-each>
3040
<xsl:for-each select="//ingredient|//product">
3141
<xsl:element name="dependency">
32-
<xsl:attribute name="ingredientid"><xsl:value-of select="generate-id()" /></xsl:attribute>
3342
<xsl:attribute name="parentid"><xsl:value-of select="generate-id(../..)" /></xsl:attribute>
43+
<xsl:attribute name="ingredientid"><xsl:value-of select="generate-id()" /></xsl:attribute>
3444
</xsl:element>
3545
</xsl:for-each>
3646
</xsl:template>

0 commit comments

Comments
 (0)