change psql-lib from knex to postgres.js
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import cfg from "../config.mjs";
|
||||
import sql from "../sql.mjs";
|
||||
import db from "../sql.mjs";
|
||||
import lib from "../lib.mjs";
|
||||
import f0cklib from "../routeinc/f0cklib.mjs";
|
||||
|
||||
@ -49,37 +49,52 @@ export default (router, tpl) => {
|
||||
referer = referertmp.split("/").slice(3).join("/");
|
||||
|
||||
if(cfg.allowedModes[mode]) {
|
||||
await sql("user_options")
|
||||
.insert({
|
||||
user_id: req.session.id,
|
||||
mode: mode,
|
||||
theme: req.theme ?? "f0ck"
|
||||
})
|
||||
.onConflict("user_id")
|
||||
.merge();
|
||||
const blah = {
|
||||
user_id: req.session.id,
|
||||
mode: mode,
|
||||
theme: req.theme ?? "f0ck"
|
||||
};
|
||||
|
||||
await db`
|
||||
insert into "user_options" ${
|
||||
db(blah, 'user_id', 'mode', 'theme')
|
||||
}
|
||||
on conflict ("user_id") do update set
|
||||
mode = excluded.mode,
|
||||
theme = excluded.theme,
|
||||
user_id = excluded.user_id
|
||||
`;
|
||||
}
|
||||
res.redirect(`/${referer}`);
|
||||
});
|
||||
|
||||
router.get(/^\/ranking$/, async (req, res) => {
|
||||
try {
|
||||
const list = await sql('tags_assign')
|
||||
.select('user.user', sql.raw('coalesce(user_options.avatar, 47319) as avatar'))
|
||||
.leftJoin('user', 'user.id', 'tags_assign.user_id')
|
||||
.leftJoin('user_options', 'user_options.user_id', 'user.id')
|
||||
.groupBy('user.user', 'user_options.avatar')
|
||||
.orderBy('count', 'desc')
|
||||
.countDistinct('tag_id', 'item_id', { as: 'count' });
|
||||
|
||||
const list = await db`
|
||||
select
|
||||
"user".user,
|
||||
coalesce("user_options".avatar, 47319) as avatar,
|
||||
count(distinct(tag_id, item_id)) as count
|
||||
from "tags_assign"
|
||||
left join "user" on "user".id = "tags_assign".user_id
|
||||
left join "user_options" on "user_options".user_id = "user".id
|
||||
group by "user".user, "user_options".avatar
|
||||
order by count desc
|
||||
`;
|
||||
const stats = await lib.countf0cks();
|
||||
|
||||
const hoster = await sql.with('t', sql.raw("select split_part(substring(src, position('//' in src)+2), '/', 1) part from items"))
|
||||
.from('t')
|
||||
.select('t.part')
|
||||
.count('t.part as c')
|
||||
.groupBy('t.part')
|
||||
.orderBy('c', 'desc')
|
||||
.limit(20);
|
||||
const hoster = await db`
|
||||
with t as (
|
||||
select
|
||||
split_part(substring(src, position('//' in src)+2), '/', 1) part
|
||||
from items
|
||||
)
|
||||
select t.part, count(t.part) as c
|
||||
from t
|
||||
group by t.part
|
||||
order by c desc
|
||||
limit 20
|
||||
`;
|
||||
|
||||
res.reply({
|
||||
body: tpl.render('ranking', {
|
||||
|
Reference in New Issue
Block a user