Skip to content

Commit f825953

Browse files
committed
feat(e2e): added initial draft for e2e feature
1 parent 229d47c commit f825953

File tree

6 files changed

+4366
-58
lines changed

6 files changed

+4366
-58
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,6 @@ sw.*
8888

8989
# Vim swap files
9090
*.swp
91+
92+
# Vercel cli
93+
.vercel

api/db/index.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { Client } from 'pg'
2+
3+
const DB_SCHEMA = process.env.DB_SCHEMA
4+
5+
const client = new Client({
6+
user: process.env.DB_USER,
7+
host: process.env.DB_HOST,
8+
database: process.env.DB_NAME,
9+
password: process.env.DB_PASSWORD,
10+
port: process.env.DB_PORT,
11+
})
12+
13+
export async function getTop10Records() {
14+
try {
15+
await client.connect()
16+
const res = await client.query(
17+
`SELECT data, id, "creationTimestamp" FROM "${DB_SCHEMA}".e2e_data limit 10;`
18+
)
19+
return res.rows
20+
} catch (error) {
21+
console.error(error)
22+
return null
23+
} finally {
24+
await client.end()
25+
}
26+
}
27+
28+
export async function getRecordById(id) {
29+
try {
30+
await client.connect()
31+
const res = await client.query(
32+
`SELECT data, "creationTimestamp" FROM "${DB_SCHEMA}".e2e_data WHERE id = ${id};`
33+
)
34+
return res.rows
35+
} catch (error) {
36+
console.error(error)
37+
return null
38+
} finally {
39+
await client.end()
40+
}
41+
}
42+
43+
export async function insertRecord({ data, id }) {
44+
try {
45+
await client.connect()
46+
await client.query(
47+
`INSERT INTO "${DB_SCHEMA}".e2e_data(data, id) VALUES ('${data}', '${id}');`
48+
)
49+
return true
50+
} catch (error) {
51+
console.error(error)
52+
return false
53+
} finally {
54+
await client.end()
55+
}
56+
}

api/ok.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// import { getTop10Records } from './db/index.js'
2+
3+
export const config = { runtime: 'nodejs' }
4+
5+
export default function handler(_req, res) {
6+
// const records = await getTop10Records()
7+
res.json({ message: 'Hello World' })
8+
}

0 commit comments

Comments
 (0)