Files
dashlibstorage/src/sql/pic.js

47 lines
1.0 KiB
JavaScript

export const CREATE = `
INSERT INTO pic (
w, h, size, hash, thumbw, thumbh, thumbhash, source, fullbinary, thumbbinary
)
OUTPUT INSERTED.id
VALUES (
@w, @h, @size, @hash, @thumbw, @thumbh, @thumbhash, @source, @fullbinary, @thumbbinary
)
`;
export const GET_CATEGORY_ID_BY_HASH = `
SELECT TOP 1 categoryId
FROM (
SELECT ca.category_id AS categoryId
FROM pic p
INNER JOIN articlepic ap ON ap.pic_id = p.id
INNER JOIN categoryarticle ca ON ca.article_id = ap.article_id
WHERE p.hash = @hash
UNION
SELECT cp.category_id AS categoryId
FROM pic p
INNER JOIN categorypic cp ON cp.pic_id = p.id
WHERE p.hash = @hash
) AS combined
`;
export const GET_FULL_BY_HASH = `
SELECT w, h, size, fullbinary AS buffer
FROM pic
WHERE hash = @hash
`;
export const GET_THUMB_BY_HASH = `
SELECT thumbw AS w, thumbh AS h, thumbbinary AS buffer
FROM pic
WHERE hash = @hash
`;
export const DELETE_BY_ARTICLE_AND_HASH = `
DELETE p
FROM pic p
INNER JOIN articlepic ap ON ap.pic_id = p.id AND ap.article_id = @articleId
WHERE p.hash = @fullHash
`;