u
This commit is contained in:
@@ -440,11 +440,44 @@ SELECT
|
||||
FROM optionslistarticle ola
|
||||
WHERE ola.optionslist_id = a.optionslist_id
|
||||
) AS optionsCount,
|
||||
a.optionslist_id AS optionslistId,
|
||||
(
|
||||
SELECT
|
||||
ola.id,
|
||||
ola.article_id AS articleId,
|
||||
a_opt.sku,
|
||||
at_opt.name,
|
||||
ola.count,
|
||||
ola.sort,
|
||||
ola.mandated
|
||||
FROM optionslistarticle ola
|
||||
INNER JOIN article a_opt ON a_opt.id = ola.article_id
|
||||
LEFT JOIN articletext at_opt ON at_opt.article_id = a_opt.id AND at_opt.language_id = auth.languageId
|
||||
WHERE ola.optionslist_id = a.optionslist_id
|
||||
ORDER BY ola.sort ASC, ola.id ASC
|
||||
FOR JSON PATH
|
||||
) AS optionslistItemsJson,
|
||||
(
|
||||
SELECT COUNT(*)
|
||||
FROM articlelistarticle ala
|
||||
WHERE ala.articlelist_id = a.articlelist_id
|
||||
) AS articleListCount,
|
||||
a.articlelist_id AS articlelistId,
|
||||
(
|
||||
SELECT
|
||||
ala.id,
|
||||
ala.article_id AS articleId,
|
||||
a_item.sku,
|
||||
at_item.name,
|
||||
ala.count,
|
||||
ala.sort
|
||||
FROM articlelistarticle ala
|
||||
INNER JOIN article a_item ON a_item.id = ala.article_id
|
||||
LEFT JOIN articletext at_item ON at_item.article_id = a_item.id AND at_item.language_id = auth.languageId
|
||||
WHERE ala.articlelist_id = a.articlelist_id
|
||||
ORDER BY ala.sort ASC, ala.id ASC
|
||||
FOR JSON PATH
|
||||
) AS articlelistItemsJson,
|
||||
(
|
||||
SELECT COUNT(*)
|
||||
FROM article child
|
||||
|
||||
41
src/providers/mssql/queries/articlelist.js
Normal file
41
src/providers/mssql/queries/articlelist.js
Normal file
@@ -0,0 +1,41 @@
|
||||
export const CREATE_ARTICLELIST = `
|
||||
INSERT INTO articlelist OUTPUT INSERTED.id DEFAULT VALUES;
|
||||
`;
|
||||
|
||||
export const SET_ARTICLE_ARTICLELIST_ID = `
|
||||
UPDATE article
|
||||
SET articlelist_id = @articlelistId
|
||||
WHERE id = @articleId;
|
||||
`;
|
||||
|
||||
export const GET_ARTICLELIST_ITEMS = `
|
||||
SELECT
|
||||
ala.id,
|
||||
ala.articlelist_id AS articlelistId,
|
||||
ala.article_id AS articleId,
|
||||
a.sku,
|
||||
at.name,
|
||||
ala.count,
|
||||
ala.sort
|
||||
FROM articlelistarticle ala
|
||||
INNER JOIN article a ON a.id = ala.article_id
|
||||
LEFT JOIN articletext at ON at.article_id = a.id AND at.language_id = @languageId
|
||||
WHERE ala.articlelist_id = @articlelistId
|
||||
ORDER BY ala.sort ASC, ala.id ASC;
|
||||
`;
|
||||
|
||||
export const INSERT_ARTICLELIST_ARTICLE = `
|
||||
INSERT INTO articlelistarticle (articlelist_id, article_id, count, sort)
|
||||
OUTPUT INSERTED.id, INSERTED.articlelist_id AS articlelistId, INSERTED.article_id AS articleId, INSERTED.count, INSERTED.sort
|
||||
VALUES (@articlelistId, @articleId, @count, @sort);
|
||||
`;
|
||||
|
||||
export const DELETE_ARTICLELIST_ARTICLES = `
|
||||
DELETE FROM articlelistarticle
|
||||
WHERE articlelist_id = @articlelistId;
|
||||
`;
|
||||
|
||||
export const DELETE_ARTICLELIST = `
|
||||
DELETE FROM articlelist
|
||||
WHERE id = @id;
|
||||
`;
|
||||
42
src/providers/mssql/queries/optionslist.js
Normal file
42
src/providers/mssql/queries/optionslist.js
Normal file
@@ -0,0 +1,42 @@
|
||||
export const CREATE_OPTIONSLIST = `
|
||||
INSERT INTO optionslist OUTPUT INSERTED.id DEFAULT VALUES;
|
||||
`;
|
||||
|
||||
export const SET_ARTICLE_OPTIONSLIST_ID = `
|
||||
UPDATE article
|
||||
SET optionslist_id = @optionslistId
|
||||
WHERE id = @articleId;
|
||||
`;
|
||||
|
||||
export const GET_OPTIONSLIST_ITEMS = `
|
||||
SELECT
|
||||
ola.id,
|
||||
ola.optionslist_id AS optionslistId,
|
||||
ola.article_id AS articleId,
|
||||
a.sku,
|
||||
at.name,
|
||||
ola.count,
|
||||
ola.sort,
|
||||
ola.mandated
|
||||
FROM optionslistarticle ola
|
||||
INNER JOIN article a ON a.id = ola.article_id
|
||||
LEFT JOIN articletext at ON at.article_id = a.id AND at.language_id = @languageId
|
||||
WHERE ola.optionslist_id = @optionslistId
|
||||
ORDER BY ola.sort ASC, ola.id ASC;
|
||||
`;
|
||||
|
||||
export const INSERT_OPTIONSLIST_ARTICLE = `
|
||||
INSERT INTO optionslistarticle (optionslist_id, article_id, count, sort, mandated)
|
||||
OUTPUT INSERTED.id, INSERTED.optionslist_id AS optionslistId, INSERTED.article_id AS articleId, INSERTED.count, INSERTED.sort, INSERTED.mandated
|
||||
VALUES (@optionslistId, @articleId, @count, @sort, @mandated);
|
||||
`;
|
||||
|
||||
export const DELETE_OPTIONSLIST_ARTICLES = `
|
||||
DELETE FROM optionslistarticle
|
||||
WHERE optionslist_id = @optionslistId;
|
||||
`;
|
||||
|
||||
export const DELETE_OPTIONSLIST = `
|
||||
DELETE FROM optionslist
|
||||
WHERE id = @id;
|
||||
`;
|
||||
@@ -132,7 +132,34 @@ SELECT auth.*,
|
||||
'brandThumbW', bp.thumbw, 'brandThumbH', bp.thumbh,
|
||||
'brandThumbHash', bp.thumbhash,
|
||||
'optionsCount', (SELECT COUNT(*) FROM optionslistarticle WHERE optionslist_id = a.optionslist_id),
|
||||
'optionslistId', a.optionslist_id,
|
||||
'optionslistItemsJson', json((SELECT COALESCE(json_group_array(json_object(
|
||||
'id', ola.id,
|
||||
'articleId', ola.article_id,
|
||||
'sku', a_opt.sku,
|
||||
'name', at_opt.name,
|
||||
'count', ola.count,
|
||||
'sort', ola.sort,
|
||||
'mandated', ola.mandated
|
||||
)), '[]') FROM optionslistarticle ola
|
||||
INNER JOIN article a_opt ON a_opt.id = ola.article_id
|
||||
LEFT JOIN articletext at_opt ON at_opt.article_id = a_opt.id AND at_opt.language_id = auth.languageId
|
||||
WHERE ola.optionslist_id = a.optionslist_id
|
||||
ORDER BY ola.sort ASC, ola.id ASC)),
|
||||
'articleListCount', (SELECT COUNT(*) FROM articlelistarticle WHERE articlelist_id = a.articlelist_id),
|
||||
'articlelistId', a.articlelist_id,
|
||||
'articlelistItemsJson', json((SELECT COALESCE(json_group_array(json_object(
|
||||
'id', ala.id,
|
||||
'articleId', ala.article_id,
|
||||
'sku', a_item.sku,
|
||||
'name', at_item.name,
|
||||
'count', ala.count,
|
||||
'sort', ala.sort
|
||||
)), '[]') FROM articlelistarticle ala
|
||||
INNER JOIN article a_item ON a_item.id = ala.article_id
|
||||
LEFT JOIN articletext at_item ON at_item.article_id = a_item.id AND at_item.language_id = auth.languageId
|
||||
WHERE ala.articlelist_id = a.articlelist_id
|
||||
ORDER BY ala.sort ASC, ala.id ASC)),
|
||||
'childCount', (SELECT COUNT(*) FROM article WHERE fatherarticle_id = a.id),
|
||||
'isFather', a.is_father,
|
||||
'fatherAttributeNameId', a.fatherattributename_id,
|
||||
|
||||
14
src/providers/sqlite3/queries/articlelist.js
Normal file
14
src/providers/sqlite3/queries/articlelist.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import * as source from '../../mssql/queries/articlelist.js';
|
||||
import { translateQueries } from './translate.js';
|
||||
|
||||
const queries = translateQueries(source, 'articlelist');
|
||||
export const {
|
||||
CREATE_ARTICLELIST,
|
||||
SET_ARTICLE_ARTICLELIST_ID,
|
||||
GET_ARTICLELIST_ITEMS,
|
||||
INSERT_ARTICLELIST_ARTICLE,
|
||||
DELETE_ARTICLELIST_ARTICLES,
|
||||
DELETE_ARTICLELIST,
|
||||
} = queries;
|
||||
|
||||
export default queries;
|
||||
14
src/providers/sqlite3/queries/optionslist.js
Normal file
14
src/providers/sqlite3/queries/optionslist.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import * as source from '../../mssql/queries/optionslist.js';
|
||||
import { translateQueries } from './translate.js';
|
||||
|
||||
const queries = translateQueries(source, 'optionslist');
|
||||
export const {
|
||||
CREATE_OPTIONSLIST,
|
||||
SET_ARTICLE_OPTIONSLIST_ID,
|
||||
GET_OPTIONSLIST_ITEMS,
|
||||
INSERT_OPTIONSLIST_ARTICLE,
|
||||
DELETE_OPTIONSLIST_ARTICLES,
|
||||
DELETE_OPTIONSLIST,
|
||||
} = queries;
|
||||
|
||||
export default queries;
|
||||
@@ -3,7 +3,7 @@ function quoteIdentifiers(sql) {
|
||||
}
|
||||
|
||||
function moveReturning(sql) {
|
||||
const output = /\bOUTPUT\s+([\s\S]*?)(?=\bVALUES\b|\bWHERE\b)/i.exec(sql);
|
||||
const output = /\bOUTPUT\s+([\s\S]*?)(?=\bVALUES\b|\bWHERE\b|\bDEFAULT\b)/i.exec(sql);
|
||||
if (!output) return sql;
|
||||
|
||||
const columns = output[1]
|
||||
|
||||
Reference in New Issue
Block a user