Allow more than one tag, fix listing tags
This commit is contained in:
parent
f43c1d433a
commit
f02133d6ab
11
database.sql
11
database.sql
|
@ -10,12 +10,11 @@ CREATE TABLE IF NOT EXISTS "files" (
|
|||
PRIMARY KEY("id" AUTOINCREMENT)
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS "tags_ties" (
|
||||
"id" INTEGER,
|
||||
"tid" INTEGER,
|
||||
"fid" INTEGER,
|
||||
PRIMARY KEY("id" AUTOINCREMENT),
|
||||
FOREIGN KEY("tid") REFERENCES "tags"("id"),
|
||||
FOREIGN KEY("fid") REFERENCES "files"("id")
|
||||
"fid" INTEGER NOT NULL,
|
||||
"tid" INTEGER NOT NULL,
|
||||
PRIMARY KEY("fid", "tid"),
|
||||
FOREIGN KEY("fid") REFERENCES "files"("id"),
|
||||
FOREIGN KEY("tid") REFERENCES "tags"("id")
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS "hashes" (
|
||||
"id" INTEGER,
|
||||
|
|
9
tag.sh
9
tag.sh
|
@ -13,9 +13,6 @@ set -ueo pipefail
|
|||
# - tag $FILENAME $TAG - tag $FILENAME with $TAG, $TAG can be repeated
|
||||
# - listtags $FILENAME - list all tags for $FILENAME
|
||||
|
||||
# TODO: when tagging, allow more than one tag
|
||||
# FIXME: adding tags doesn't work
|
||||
|
||||
SCRIPT_DIR=$(dirname $(readlink "$0"))
|
||||
SCRIPT_NAME=$(basename "$0")
|
||||
|
||||
|
@ -68,8 +65,8 @@ listtags() {
|
|||
|
||||
sqlite_query \
|
||||
"SELECT filename, label from files \
|
||||
INNER JOIN tags_ties ON tags_ties.id = files.id \
|
||||
INNER JOIN tags ON tags.id = tags_ties.id \
|
||||
INNER JOIN tags_ties ON tags_ties.fid = files.id \
|
||||
INNER JOIN tags ON tags.id = tags_ties.tid \
|
||||
WHERE filename = \"$FILENAME\"\
|
||||
$ADDITIONAL_QUERY"
|
||||
}
|
||||
|
@ -244,7 +241,7 @@ main() {
|
|||
LABEL="$1"
|
||||
! tag_exists_in_db "$LABEL" && fail "Tag '$TAG' does not exist in database."
|
||||
shift
|
||||
sqlite3 -table "$DB_FILE" "INSERT INTO tags_ties (id, id) VALUES ((SELECT id FROM files WHERE filename = \"$FILENAME\"),(SELECT id FROM tags WHERE label = \"$LABEL\"))"
|
||||
sqlite_query "INSERT INTO tags_ties (fid, tid) VALUES ((SELECT id FROM files WHERE filename = \"$FILENAME\"),(SELECT id FROM tags WHERE label = \"$LABEL\"))"
|
||||
COUNTER=$((COUNTER++))
|
||||
[ -z "${1:-}" ] && break
|
||||
done
|
||||
|
|
Loading…
Reference in New Issue