Add: Post Count API
This commit is contained in:
parent
d8b25b59dc
commit
22c841396a
@ -47,6 +47,29 @@ function parsePostFromRow(author, category, row, withMetrics = false) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {{
|
||||||
|
* category?: import('$types/base').Category | undefined
|
||||||
|
* }} opts
|
||||||
|
* @returns {Promise<number>}
|
||||||
|
*/
|
||||||
|
export async function getPostCount(opts = {}) {
|
||||||
|
const {
|
||||||
|
category = undefined
|
||||||
|
} = opts;
|
||||||
|
|
||||||
|
const filter = category ? sql`WHERE category_id = ${ category.id }` : sql``;
|
||||||
|
|
||||||
|
const query = sql`
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM doki8902.message_post
|
||||||
|
${ filter };`;
|
||||||
|
|
||||||
|
const count = await query;
|
||||||
|
|
||||||
|
return count[0]['count'];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {{
|
* @param {{
|
||||||
* category?: import('$types/base').Category | undefined,
|
* category?: import('$types/base').Category | undefined,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user