word: translations from _word_ref view coalescing parent values
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 2 Jul 2021 15:56:16 +0000 (17:56 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 5 Jul 2021 01:54:37 +0000 (03:54 +0200)
tools/mkwordlist
tools/word.pg.sql

index 9076a09546bc6c80e5b267b915099b7de70731b3..3c5aac907ecc69b0fcaf46d97314d95176080599 100755 (executable)
@@ -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 };
index 1bc5dffcc78e25f5dea4d0dee6164a6069f71ef9..7aacfa88d5cfb8f76fba04699e9ea87df8adc692 100644 (file)
@@ -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 (