Starting post load
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @param {import('postgres').Sql} sql
|
||||
* @param {number | undefined} category
|
||||
* @param {number} limit
|
||||
* @param {number} offset
|
||||
* @returns {Promise<import('$types/base').Post[]>}
|
||||
*/
|
||||
export async function getPosts(sql, category = undefined, limit = 10, offset = 0) {
|
||||
let query;
|
||||
|
||||
if (category === undefined) {
|
||||
query = sql`
|
||||
SELECT name, latest_content
|
||||
FROM doki8902.message_post
|
||||
FETCH FIRST ${limit} ROWS ONLY
|
||||
OFFSET ${offset};`;
|
||||
} else {
|
||||
query = sql`
|
||||
SELECT name, latest_content
|
||||
FROM doki8902.message_post
|
||||
WHERE category_id = ${category}
|
||||
FETCH FIRST ${limit} ROWS ONLY
|
||||
OFFSET ${offset};`;
|
||||
}
|
||||
|
||||
let posts = await query;
|
||||
|
||||
/**
|
||||
* @type {import('$types/base').Post[]}
|
||||
*/
|
||||
let result = [];
|
||||
|
||||
posts.forEach(row => {
|
||||
result.push({
|
||||
name: row['name'],
|
||||
content: row['latest_content']
|
||||
});
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// export function runQuery(
|
||||
// /** @type {import('postgres').Sql} */ sql,
|
||||
// /** @type {string} */ query,
|
||||
// /** @type {any[]} */ args = []) {
|
||||
// sql`${query}`
|
||||
// }
|
||||
@@ -0,0 +1,8 @@
|
||||
import dotenv from 'dotenv';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
/**
|
||||
* @type {import('$types/env').Env}
|
||||
*/
|
||||
export const env = process.env;
|
||||
Reference in New Issue
Block a user