use Data::Dump 'pp';
if (my $lang = shift @ARGV) {
- say pp({ $db->select(word => "coalesce(ref, id), exportform(row(form,alt,lang,cat,ref,prio,source,thumb,wptitle,created,updated,CASE WHEN source IS NULL THEN ref ELSE id END,cover,grade,creator))", {lang => $lang})->map }) =~ s/\\x\{([0-9A-F]+)\}/chr hex $1/ger;
+ my %filter = (lang => $lang);
+ say pp({ $db->select('_word_ref w' => "ref, exportform(row(w.*))", \%filter)->map })
+ =~ s/\\x\{([0-9A-F]+)\}/chr hex $1/ger;
exit;
}
say pp { $db->select(_cat_words => "coalesce(id::text, ''), forms")->map };
);
$$ LANGUAGE SQL IMMUTABLE;
+CREATE OR REPLACE VIEW _word_ref AS
+ SELECT
+ r.form, r.alt, r.lang,
+ coalesce(r.cat, w.cat ) cat, --TODO translate w?
+ coalesce(r.ref, r.id ) "ref",
+ coalesce(r.prio, w.prio ) prio,
+ coalesce(r.source, w.source ) source,
+ coalesce(r.thumb, w.thumb ) thumb,
+ coalesce(r.wptitle, w.wptitle) wptitle,
+ r.created, r.updated,
+ CASE WHEN r.source IS NULL THEN w.id ELSE r.id END id, -- image id
+ coalesce(r.cover, w.cover ) cover,
+ coalesce(r.grade, w.grade ) grade,
+ r.creator
+ FROM word r
+ LEFT JOIN word w ON w.id = r.ref;
+
CREATE OR REPLACE VIEW _cat_words AS
SELECT exportform(word.*) form, sub.*, word.lang, word.ref
FROM word RIGHT JOIN (