u
This commit is contained in:
@@ -6,6 +6,7 @@ export const TABLES = [
|
||||
'account',
|
||||
'articleattributevalue',
|
||||
'articleproperty',
|
||||
'attributevaluepic',
|
||||
'attributevalue',
|
||||
'attributename',
|
||||
'propertyname',
|
||||
|
||||
23
src/providers/mssql/queries/attributevaluepic.js
Normal file
23
src/providers/mssql/queries/attributevaluepic.js
Normal file
@@ -0,0 +1,23 @@
|
||||
export const GET_NEXT_SORT = `
|
||||
SELECT ISNULL(MAX(sort), -1) + 1 AS sort
|
||||
FROM attributevaluepic
|
||||
WHERE attributevalue_id = @attributeValueId
|
||||
`;
|
||||
|
||||
export const ADD = `
|
||||
INSERT INTO attributevaluepic (attributevalue_id, pic_id, sort)
|
||||
VALUES (@attributeValueId, @picId, @sort)
|
||||
`;
|
||||
|
||||
export const DELETE_BY_ATTRIBUTE_VALUE = `
|
||||
DELETE FROM attributevaluepic
|
||||
WHERE attributevalue_id = @attributeValueId
|
||||
`;
|
||||
|
||||
export const GET_FIRST_PIC_BY_ATTRIBUTE_VALUE = `
|
||||
SELECT TOP 1 p.id AS picId, p.thumbw AS thumbW, p.thumbh AS thumbH, p.thumbhash AS thumbHash
|
||||
FROM attributevaluepic avp
|
||||
INNER JOIN pic p ON p.id = avp.pic_id
|
||||
WHERE avp.attributevalue_id = @attributeValueId
|
||||
ORDER BY avp.sort ASC, avp.id ASC
|
||||
`;
|
||||
@@ -45,6 +45,16 @@ FROM (
|
||||
INNER JOIN brand b ON b.id = bp.brand_id
|
||||
INNER JOIN company c ON c.id = b.company_id
|
||||
WHERE p.hash = @hash
|
||||
|
||||
UNION
|
||||
|
||||
SELECT c.root_category_id AS categoryId
|
||||
FROM pic p
|
||||
INNER JOIN attributevaluepic avp ON avp.pic_id = p.id
|
||||
INNER JOIN attributevalue av ON av.id = avp.attributevalue_id
|
||||
INNER JOIN attributename an ON an.id = av.attribute_id
|
||||
INNER JOIN company c ON c.id = an.company_id
|
||||
WHERE p.hash = @hash
|
||||
) AS combined
|
||||
WHERE categoryId IS NOT NULL
|
||||
`;
|
||||
|
||||
@@ -463,6 +463,22 @@ BEGIN
|
||||
END
|
||||
`;
|
||||
|
||||
export const INIT_ATTRIBUTEVALUEPIC = `
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'attributevaluepic')
|
||||
BEGIN
|
||||
CREATE TABLE attributevaluepic (
|
||||
id INT IDENTITY(1,1) PRIMARY KEY,
|
||||
attributevalue_id INT NOT NULL,
|
||||
pic_id INT NOT NULL,
|
||||
sort INT NOT NULL CONSTRAINT DF_attributevaluepic_sort DEFAULT 0,
|
||||
CONSTRAINT FK_attributevaluepic_attributevalue FOREIGN KEY (attributevalue_id) REFERENCES attributevalue(id) ON DELETE CASCADE,
|
||||
CONSTRAINT FK_attributevaluepic_pic FOREIGN KEY (pic_id) REFERENCES pic(id) ON DELETE CASCADE,
|
||||
CONSTRAINT UQ_attributevaluepic_attributevalue_pic UNIQUE (attributevalue_id, pic_id),
|
||||
CONSTRAINT UQ_attributevaluepic_attributevalue_sort UNIQUE (attributevalue_id, sort)
|
||||
);
|
||||
END
|
||||
`;
|
||||
|
||||
export const INIT_ARTICLELISTARTICLE = `
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'articlelistarticle')
|
||||
BEGIN
|
||||
@@ -1183,6 +1199,7 @@ export const SCHEMA_SCRIPTS = [
|
||||
INIT_ARTICLEEAN,
|
||||
INIT_ARTICLEPIC,
|
||||
INIT_BRANDPIC,
|
||||
INIT_ATTRIBUTEVALUEPIC,
|
||||
INIT_ARTICLELISTARTICLE,
|
||||
INIT_OPTIONSLISTARTICLE,
|
||||
INIT_CATEGORYARTICLE,
|
||||
|
||||
5
src/providers/sqlite3/queries/attributevaluepic.js
Normal file
5
src/providers/sqlite3/queries/attributevaluepic.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import * as source from '../../mssql/queries/attributevaluepic.js';
|
||||
import { translateQueries } from './translate.js';
|
||||
|
||||
const queries = translateQueries(source, 'attributevaluepic');
|
||||
export const { ADD, DELETE_BY_ATTRIBUTE_VALUE, GET_FIRST_PIC_BY_ATTRIBUTE_VALUE, GET_NEXT_SORT } = queries;
|
||||
@@ -284,6 +284,19 @@ CREATE TABLE IF NOT EXISTS brandpic (
|
||||
);
|
||||
`;
|
||||
|
||||
export const INIT_ATTRIBUTEVALUEPIC = `
|
||||
CREATE TABLE IF NOT EXISTS attributevaluepic (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
attributevalue_id INTEGER NOT NULL,
|
||||
pic_id INTEGER NOT NULL,
|
||||
sort INTEGER NOT NULL DEFAULT 0,
|
||||
UNIQUE (attributevalue_id, pic_id),
|
||||
UNIQUE (attributevalue_id, sort),
|
||||
FOREIGN KEY (attributevalue_id) REFERENCES attributevalue(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (pic_id) REFERENCES pic(id) ON DELETE CASCADE
|
||||
);
|
||||
`;
|
||||
|
||||
export const INIT_ARTICLELISTARTICLE = `
|
||||
CREATE TABLE IF NOT EXISTS articlelistarticle (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
@@ -853,6 +866,7 @@ export const SCHEMA_SCRIPTS = [
|
||||
INIT_ARTICLEEAN,
|
||||
INIT_ARTICLEPIC,
|
||||
INIT_BRANDPIC,
|
||||
INIT_ATTRIBUTEVALUEPIC,
|
||||
INIT_ARTICLELISTARTICLE,
|
||||
INIT_OPTIONSLISTARTICLE,
|
||||
INIT_CATEGORYARTICLE,
|
||||
|
||||
Reference in New Issue
Block a user