• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

textbook / starter-kit / 21064057697

16 Jan 2026 10:46AM UTC coverage: 70.466% (-8.3%) from 78.788%
21064057697

push

github

textbook
Upgrade Prettier to v3.8

31 of 58 branches covered (53.45%)

Branch coverage included in aggregate %.

105 of 135 relevant lines covered (77.78%)

8.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.0
/api/db.js
1
import { basename } from "node:path";
2

3
import { runner } from "node-pg-migrate";
4
import pg from "pg";
5

6
import config from "./utils/config.js";
7
import logger from "./utils/logger.js";
8

9
/** @type {import("pg").Pool | null} */
10
let pool = null;
3✔
11

12
/**
13
 * Apply migrations to bring the database up-to-date.
14
 * @param {import("./utils/config.js").default["migrationConfig"]} migrationConfig
15
 * @returns {Promise<void>}
16
 */
17
export async function applyMigrations(migrationConfig) {
18
        await runner({ ...migrationConfig, direction: "up" });
×
19
}
20

21
export const connectDb = async () => {
3✔
22
        pool = new pg.Pool(config.dbConfig);
3✔
23
        pool.on("error", (err) => logger.error("%O", err));
3✔
24
        const client = await pool.connect();
3✔
25
        logger.info("connected to %s", databaseName());
3✔
26
        client.release();
3✔
27
};
28

29
export const disconnectDb = async () => {
3✔
30
        if (pool) {
3!
31
                logger.debug("disconnecting from %s", databaseName());
3✔
32
                await pool.end();
3✔
33
                pool = null;
3✔
34
        }
35
};
36

37
export const testConnection = async () => {
3✔
38
        await query("SELECT 1;");
3✔
39
};
40

41
function query(...args) {
42
        if (pool === null) {
6!
43
                throw new Error("cannot query without establishing connection");
×
44
        }
45
        logger.debug("Postgres query: %O", args);
6✔
46
        return pool.query.apply(pool, args);
6✔
47
}
48

49
export default { query };
50

51
/**
52
 * @returns {string}
53
 */
54
function databaseName() {
55
        const connectionUri = new URL(config.dbConfig.connectionString);
6✔
56
        return basename(connectionUri.pathname);
6✔
57
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc