summaryrefslogtreecommitdiff
path: root/lib/VNDB/DB
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-03-12 16:07:48 +0100
committerYorhel <git@yorhel.nl>2020-03-12 16:08:24 +0100
commit8fe95ae3c2119e5a5219ad072d441bac406ea547 (patch)
tree780090a7f0c402bb73eaf203f78271ff431a308b /lib/VNDB/DB
parent583ae868dfd3c882a8d2dd40b5d5ed099170c1c2 (diff)
SQL: Keep track of dimensions for all images in the DB
Ought to simplify the image flagging UI.
Diffstat (limited to 'lib/VNDB/DB')
-rw-r--r--lib/VNDB/DB/Chars.pm8
-rw-r--r--lib/VNDB/DB/Misc.pm10
-rw-r--r--lib/VNDB/DB/VN.pm15
3 files changed, 11 insertions, 22 deletions
diff --git a/lib/VNDB/DB/Chars.pm b/lib/VNDB/DB/Chars.pm
index 047f39b5..7ee6d86b 100644
--- a/lib/VNDB/DB/Chars.pm
+++ b/lib/VNDB/DB/Chars.pm
@@ -5,7 +5,7 @@ use strict;
use warnings;
use Exporter 'import';
-our @EXPORT = qw|dbCharFilters dbCharGet dbCharGetRev dbCharRevisionInsert dbCharImageId|;
+our @EXPORT = qw|dbCharFilters dbCharGet dbCharGetRev dbCharRevisionInsert|;
# Character filters shared by dbCharGet and dbVNGet
@@ -194,11 +194,5 @@ sub dbCharRevisionInsert {
}
-# fetches an ID for a new image
-sub dbCharImageId {
- return shift->dbRow(q|INSERT INTO images (id) VALUES (ROW('ch', nextval('charimg_seq'))::image_id) RETURNING (id).id|)->{id};
-}
-
-
1;
diff --git a/lib/VNDB/DB/Misc.pm b/lib/VNDB/DB/Misc.pm
index cd290d61..73e3e71f 100644
--- a/lib/VNDB/DB/Misc.pm
+++ b/lib/VNDB/DB/Misc.pm
@@ -6,7 +6,7 @@ use warnings;
use Exporter 'import';
our @EXPORT = qw|
- dbStats dbItemEdit dbRevisionGet dbWikidata
+ dbStats dbItemEdit dbRevisionGet dbWikidata dbImageAdd
|;
@@ -115,5 +115,13 @@ sub dbWikidata {
}
+# insert a new image and return its ID
+sub dbImageAdd {
+ my($s, $type, $width, $height) = @_;
+ my $seq = {qw/sf screenshots_seq cv covers_seq ch charimg_seq/}->{$type}||die;
+ return $s->dbRow(q|INSERT INTO images (id, width, height) VALUES (ROW(?, nextval(?))::image_id, ?, ?) RETURNING (id).id|, $type, $seq, $width, $height)->{id};
+}
+
+
1;
diff --git a/lib/VNDB/DB/VN.pm b/lib/VNDB/DB/VN.pm
index 3615d918..e8f3666e 100644
--- a/lib/VNDB/DB/VN.pm
+++ b/lib/VNDB/DB/VN.pm
@@ -8,7 +8,7 @@ use POSIX 'strftime';
use Exporter 'import';
use VNDB::Func 'normalize_query', 'gtintype';
-our @EXPORT = qw|dbVNGet dbVNGetRev dbVNRevisionInsert dbVNImageId dbScreenshotAdd dbScreenshotGet dbScreenshotRandom|;
+our @EXPORT = qw|dbVNGet dbVNGetRev dbVNRevisionInsert dbScreenshotGet dbScreenshotRandom|;
# Options: id, char, search, gtin, length, lang, olang, plat, tag_inc, tag_exc, tagspoil,
@@ -318,19 +318,6 @@ sub dbVNRevisionInsert {
}
-# fetches an ID for a new image
-sub dbVNImageId {
- return shift->dbRow(q|INSERT INTO images (id) VALUES (ROW('cv', nextval('covers_seq'))::image_id) RETURNING (id).id|)->{id};
-}
-
-
-# insert a new screenshot and return it's ID
-sub dbScreenshotAdd {
- my($s, $width, $height) = @_;
- return $s->dbRow(q|INSERT INTO images (id, width, height) VALUES (ROW('sf', nextval('screenshots_seq'))::image_id, ?, ?) RETURNING (id).id|, $width, $height)->{id};
-}
-
-
# arrayref of screenshot IDs as argument
sub dbScreenshotGet {
return shift->dbAll(q|SELECT (id).id, width, height FROM images WHERE id IN(SELECT ROW('sf', n::integer)::image_id FROM unnest(ARRAY[!l]) x(n))|, shift);