change psql-lib from knex to postgres.js

This commit is contained in:
Flummi
2022-03-31 13:34:51 +02:00
parent f750a9a60f
commit c498a33cbe
20 changed files with 689 additions and 973 deletions

View File

@ -1,4 +1,4 @@
import sql from '../../sql.mjs';
import db from '../../sql.mjs';
import lib from '../../lib.mjs';
export default router => {
@ -13,11 +13,11 @@ export default router => {
const avatar = +req.post.avatar;
const itemid = (
await sql('items')
.select('id')
.where('id', avatar)
)?.[0]?.id;
const itemid = (await db`
select id
from "items"
where id = ${+avatar}
`)?.[0]?.id;
if(!itemid) {
return res.json({
@ -25,11 +25,14 @@ export default router => {
}, 404); // not found
}
const q = await sql('user_options')
.update({
avatar
})
.where('user_id', req.session.id);
const q = await db`
update "user_options" set ${
db({
avatar
}, 'avatar')
}
where user_id = ${+req.session.id}
`;
return res.json({
msg: q