blob: f649d2dce8ce3d147139007f1d26221f59aff65e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
import {
createPool,
QueryResultType,
sql,
} from "slonik";
import config from "./config";
interface ActiveChat {
id: number;
}
interface PermittedUser {
id: number;
}
const connection = createPool(config.pgConnectionUri);
export const getActiveChats = async (): Promise<readonly ActiveChat[]> =>
connection.any(sql`
SELECT *
FROM active_chats
`);
export const addActiveChat = async (id: number): Promise<QueryResultType<void>> =>
connection.query<void>(sql`
INSERT INTO active_chats
(id) VALUES
(${id})
ON CONFLICT DO NOTHING
`);
export const removeActiveChat = async (id: number): Promise<QueryResultType<void>> =>
connection.query<void>(sql`
DELETE FROM active_chats
WHERE id = ${id}
`);
export const getPermittedUsers = async (): Promise<readonly PermittedUser[]> =>
connection.any(sql`
SELECT *
FROM permitted_users
`);
|