Genesis
This commit is contained in:
18
src/queries/category-count.js
Normal file
18
src/queries/category-count.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import sql from 'mssql';
|
||||
import { getPool } from '../db.js';
|
||||
import { CATEGORY_TREE_CTE, categoryTreeRequest, getRootCategoryId } from './category-tree.js';
|
||||
|
||||
const CATEGORY_COUNT_SQL = `
|
||||
${CATEGORY_TREE_CTE}
|
||||
SELECT COUNT(*) AS CategoryCount
|
||||
FROM dbo.tKategorie k
|
||||
WHERE k.kKategorie IN (SELECT kKategorie FROM CategoryTree)
|
||||
AND CONVERT(BIGINT, k.bRowversion) > @cursor;
|
||||
`;
|
||||
|
||||
export async function getCategoryCount({ cursor = 0, rootCategoryId = getRootCategoryId() } = {}) {
|
||||
const result = await categoryTreeRequest(getPool(), rootCategoryId)
|
||||
.input('cursor', sql.BigInt, cursor)
|
||||
.query(CATEGORY_COUNT_SQL);
|
||||
return result.recordset[0]?.CategoryCount ?? 0;
|
||||
}
|
||||
Reference in New Issue
Block a user