From: Mischa POSLAWSKY Date: Fri, 2 Jul 2021 15:56:16 +0000 (+0200) Subject: word: translations from _word_ref view coalescing parent values X-Git-Tag: v1.13~187 X-Git-Url: http://git.shiar.net/sheet.git/commitdiff_plain/9ddf2e9a6173fcb1649ab9dd72ded3896195c83f word: translations from _word_ref view coalescing parent values --- diff --git a/tools/mkwordlist b/tools/mkwordlist index 9076a09..3c5aac9 100755 --- a/tools/mkwordlist +++ b/tools/mkwordlist @@ -11,7 +11,9 @@ say 'use utf8;'; 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 }; diff --git a/tools/word.pg.sql b/tools/word.pg.sql index 1bc5dff..7aacfa8 100644 --- a/tools/word.pg.sql +++ b/tools/word.pg.sql @@ -48,6 +48,23 @@ CREATE OR REPLACE FUNCTION exportform(word) RETURNS text AS $$ ); $$ 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 (