u
This commit is contained in:
@@ -13,6 +13,14 @@ OUTER APPLY (
|
||||
ORDER BY ap.sort ASC, ap.id ASC
|
||||
) first_pic
|
||||
LEFT JOIN pic ON pic.id = first_pic.pic_id
|
||||
LEFT JOIN brand b ON b.id = a.brand_id
|
||||
OUTER APPLY (
|
||||
SELECT TOP 1 bp.pic_id
|
||||
FROM brandpic bp
|
||||
WHERE bp.brand_id = b.id
|
||||
ORDER BY bp.sort ASC, bp.id ASC
|
||||
) first_brand_pic
|
||||
LEFT JOIN pic brand_pic ON brand_pic.id = first_brand_pic.pic_id
|
||||
LEFT JOIN article father ON father.id = a.fatherarticle_id
|
||||
`;
|
||||
|
||||
@@ -49,7 +57,13 @@ export const ARTICLE_LIST_COLUMNS = `
|
||||
pic.hash AS fullHash,
|
||||
pic.thumbw AS thumbW,
|
||||
pic.thumbh AS thumbH,
|
||||
pic.thumbhash AS thumbHash
|
||||
pic.thumbhash AS thumbHash,
|
||||
b.id AS brandId,
|
||||
b.name AS brandName,
|
||||
brand_pic.hash AS brandFullHash,
|
||||
brand_pic.thumbw AS brandThumbW,
|
||||
brand_pic.thumbh AS brandThumbH,
|
||||
brand_pic.thumbhash AS brandThumbHash
|
||||
`;
|
||||
|
||||
export const GET_CATEGORY_ID_BY_SKU = `
|
||||
@@ -362,7 +376,9 @@ SELECT
|
||||
u.basesifactor AS unitBasesifactor,
|
||||
ut.symbol AS unitSymbol,
|
||||
ut.name AS unitName,
|
||||
b.id AS brandId,
|
||||
b.name AS brandName,
|
||||
bp.hash AS brandFullHash,
|
||||
bp.thumbw AS brandThumbW,
|
||||
bp.thumbh AS brandThumbH,
|
||||
bp.thumbhash AS brandThumbHash,
|
||||
|
||||
@@ -10,7 +10,9 @@ export const ARTICLE_DETAIL_COLUMNS = `
|
||||
u.basesifactor AS unitBasesifactor,
|
||||
ut.symbol AS unitSymbol,
|
||||
ut.name AS unitName,
|
||||
b.id AS brandId,
|
||||
b.name AS brandName,
|
||||
brand_pic.hash AS brandFullHash,
|
||||
brand_pic.thumbw AS brandThumbW,
|
||||
brand_pic.thumbh AS brandThumbH,
|
||||
brand_pic.thumbhash AS brandThumbHash,
|
||||
|
||||
@@ -1,21 +1,49 @@
|
||||
export const LIST_BY_COMPANY = `
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
gsprpinfo
|
||||
FROM brand
|
||||
WHERE company_id = @companyId
|
||||
ORDER BY name
|
||||
b.id,
|
||||
b.name,
|
||||
b.gsprpinfo,
|
||||
(
|
||||
SELECT
|
||||
bp.id,
|
||||
bp.sort,
|
||||
p.hash AS fullHash,
|
||||
p.thumbw AS thumbW,
|
||||
p.thumbh AS thumbH,
|
||||
p.thumbhash AS thumbHash
|
||||
FROM brandpic bp
|
||||
INNER JOIN pic p ON p.id = bp.pic_id
|
||||
WHERE bp.brand_id = b.id
|
||||
ORDER BY bp.sort ASC, bp.id ASC
|
||||
FOR JSON PATH
|
||||
) AS picsJson
|
||||
FROM brand b
|
||||
WHERE b.company_id = @companyId
|
||||
ORDER BY b.name
|
||||
`;
|
||||
|
||||
export const GET_BY_COMPANY_AND_NAME = `
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
gsprpinfo
|
||||
FROM brand
|
||||
WHERE company_id = @companyId
|
||||
AND name = @name
|
||||
b.id,
|
||||
b.name,
|
||||
b.gsprpinfo,
|
||||
(
|
||||
SELECT
|
||||
bp.id,
|
||||
bp.sort,
|
||||
p.hash AS fullHash,
|
||||
p.thumbw AS thumbW,
|
||||
p.thumbh AS thumbH,
|
||||
p.thumbhash AS thumbHash
|
||||
FROM brandpic bp
|
||||
INNER JOIN pic p ON p.id = bp.pic_id
|
||||
WHERE bp.brand_id = b.id
|
||||
ORDER BY bp.sort ASC, bp.id ASC
|
||||
FOR JSON PATH
|
||||
) AS picsJson
|
||||
FROM brand b
|
||||
WHERE b.company_id = @companyId
|
||||
AND b.name = @name
|
||||
`;
|
||||
|
||||
export const CREATE = `
|
||||
@@ -34,3 +62,13 @@ export const DELETE_BY_COMPANY_AND_ID = `
|
||||
DELETE FROM brand
|
||||
WHERE id = @id AND company_id = @companyId
|
||||
`;
|
||||
|
||||
export const GET_BY_ID_AND_COMPANY = `
|
||||
SELECT
|
||||
b.id,
|
||||
b.company_id,
|
||||
b.name,
|
||||
b.gsprpinfo
|
||||
FROM brand b
|
||||
WHERE b.id = @id AND b.company_id = @companyId
|
||||
`;
|
||||
|
||||
23
src/providers/mssql/queries/brandpic.js
Normal file
23
src/providers/mssql/queries/brandpic.js
Normal file
@@ -0,0 +1,23 @@
|
||||
export const GET_NEXT_SORT = `
|
||||
SELECT ISNULL(MAX(sort), -1) + 1 AS sort
|
||||
FROM brandpic
|
||||
WHERE brand_id = @brandId
|
||||
`;
|
||||
|
||||
export const ADD = `
|
||||
INSERT INTO brandpic (brand_id, pic_id, sort)
|
||||
VALUES (@brandId, @picId, @sort)
|
||||
`;
|
||||
|
||||
export const DELETE_BY_BRAND = `
|
||||
DELETE FROM brandpic
|
||||
WHERE brand_id = @brandId
|
||||
`;
|
||||
|
||||
export const GET_FIRST_PIC_BY_BRAND = `
|
||||
SELECT TOP 1 p.id AS picId, p.thumbw AS thumbW, p.thumbh AS thumbH, p.thumbhash AS thumbHash
|
||||
FROM brandpic bp
|
||||
INNER JOIN pic p ON p.id = bp.pic_id
|
||||
WHERE bp.brand_id = @brandId
|
||||
ORDER BY bp.sort ASC, bp.id ASC
|
||||
`;
|
||||
@@ -23,6 +23,15 @@ FROM (
|
||||
FROM pic p
|
||||
INNER JOIN categorypic cp ON cp.pic_id = p.id
|
||||
WHERE p.hash = @hash
|
||||
|
||||
UNION
|
||||
|
||||
SELECT c.category_id AS categoryId
|
||||
FROM pic p
|
||||
INNER JOIN brandpic bp ON bp.pic_id = p.id
|
||||
INNER JOIN brand b ON b.id = bp.brand_id
|
||||
INNER JOIN company c ON c.id = b.company_id
|
||||
WHERE p.hash = @hash
|
||||
) AS combined
|
||||
`;
|
||||
|
||||
|
||||
@@ -24,6 +24,11 @@ LEFT JOIN pic ON pic.id = (
|
||||
SELECT ap.pic_id FROM articlepic ap
|
||||
WHERE ap.article_id = a.id ORDER BY ap.sort, ap.id LIMIT 1
|
||||
)
|
||||
LEFT JOIN brand b ON b.id = a.brand_id
|
||||
LEFT JOIN pic brand_pic ON brand_pic.id = (
|
||||
SELECT bp.pic_id FROM brandpic bp
|
||||
WHERE bp.brand_id = b.id ORDER BY bp.sort, bp.id LIMIT 1
|
||||
)
|
||||
LEFT JOIN article father ON father.id = a.fatherarticle_id
|
||||
`;
|
||||
|
||||
@@ -119,7 +124,9 @@ SELECT auth.*,
|
||||
'unitamount', a.unitamount, 'weight', a.weight,
|
||||
'unitSi', u.si, 'unitBasesi', u.basesi,
|
||||
'unitBasesifactor', u.basesifactor, 'unitSymbol', ut.symbol,
|
||||
'unitName', ut.name, 'brandName', b.name,
|
||||
'unitName', ut.name,
|
||||
'brandId', b.id, 'brandName', b.name,
|
||||
'brandFullHash', bp.hash,
|
||||
'brandThumbW', bp.thumbw, 'brandThumbH', bp.thumbh,
|
||||
'brandThumbHash', bp.thumbhash,
|
||||
'optionsCount', (SELECT COUNT(*) FROM optionslistarticle WHERE optionslist_id = a.optionslist_id),
|
||||
|
||||
@@ -3,6 +3,59 @@ import { translateQueries } from './translate.js';
|
||||
|
||||
const queries = translateQueries(source, 'brand');
|
||||
export const {
|
||||
CREATE, DELETE_BY_COMPANY_AND_ID, GET_BY_COMPANY_AND_NAME,
|
||||
LIST_BY_COMPANY, UPDATE_BY_ID,
|
||||
} = queries;
|
||||
CREATE, DELETE_BY_COMPANY_AND_ID, UPDATE_BY_ID, GET_BY_ID_AND_COMPANY,
|
||||
} = queries;
|
||||
|
||||
export const LIST_BY_COMPANY = `
|
||||
SELECT
|
||||
b.id,
|
||||
b.name,
|
||||
b.gsprpinfo,
|
||||
(
|
||||
SELECT COALESCE(json_group_array(json_object(
|
||||
'id', id,
|
||||
'sort', sort,
|
||||
'fullHash', hash,
|
||||
'thumbW', thumbw,
|
||||
'thumbH', thumbh,
|
||||
'thumbHash', thumbhash
|
||||
)), '[]')
|
||||
FROM (
|
||||
SELECT bp.id, bp.sort, p.hash, p.thumbw, p.thumbh, p.thumbhash
|
||||
FROM brandpic bp
|
||||
INNER JOIN pic p ON p.id = bp.pic_id
|
||||
WHERE bp.brand_id = b.id
|
||||
ORDER BY bp.sort, bp.id
|
||||
)
|
||||
) AS picsJson
|
||||
FROM brand b
|
||||
WHERE b.company_id = @companyId
|
||||
ORDER BY b.name
|
||||
`;
|
||||
|
||||
export const GET_BY_COMPANY_AND_NAME = `
|
||||
SELECT
|
||||
b.id,
|
||||
b.name,
|
||||
b.gsprpinfo,
|
||||
(
|
||||
SELECT COALESCE(json_group_array(json_object(
|
||||
'id', id,
|
||||
'sort', sort,
|
||||
'fullHash', hash,
|
||||
'thumbW', thumbw,
|
||||
'thumbH', thumbh,
|
||||
'thumbHash', thumbhash
|
||||
)), '[]')
|
||||
FROM (
|
||||
SELECT bp.id, bp.sort, p.hash, p.thumbw, p.thumbh, p.thumbhash
|
||||
FROM brandpic bp
|
||||
INNER JOIN pic p ON p.id = bp.pic_id
|
||||
WHERE bp.brand_id = b.id
|
||||
ORDER BY bp.sort, bp.id
|
||||
)
|
||||
) AS picsJson
|
||||
FROM brand b
|
||||
WHERE b.company_id = @companyId
|
||||
AND b.name = @name
|
||||
`;
|
||||
5
src/providers/sqlite3/queries/brandpic.js
Normal file
5
src/providers/sqlite3/queries/brandpic.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import * as source from '../../mssql/queries/brandpic.js';
|
||||
import { translateQueries } from './translate.js';
|
||||
|
||||
const queries = translateQueries(source, 'brandpic');
|
||||
export const { ADD, DELETE_BY_BRAND, GET_FIRST_PIC_BY_BRAND, GET_NEXT_SORT } = queries;
|
||||
Reference in New Issue
Block a user