-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (27 loc) · 1.05 KB
/
index.js
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
import serverless from 'serverless-http';
import express from 'express';
import cors from 'cors';
import * as db from './db.js';
const app = express();
app.use(cors());
app.get('/songsAmount', async (req, res) => {
await db.exec(async (client) => {
const result = await client.query('select max(numer) from koinonia.spis');
res.json({ max: result.rows[0].max });
});
});
app.get('/song', async (req, res) => {
await db.exec(async (client) => {
const result = await client.query('select numer, tekst, copyr, chwyt from koinonia.tekst left join koinonia.chwyty on koinonia.tekst.id = koinonia.chwyty .id where numer = $1 order by tekst.id', [req.query.songNo]);
console.log(result.rows);
res.json(result.rows);
});
});
app.get('/songsList', async (req, res) => {
await db.exec(async (client) => {
const result = await client.query('select * from koinonia.spis where numer between $1 and $2 order by numer', [req.query.startIndex, req.query.endIndex]);
res.json(result.rows);
});
});
const handler = serverless(app)
export { handler }