Skip to content

Commit 5f84838

Browse files
authored
build(deps-dev): replace standard with neostandard (#188)
* build(deps-dev): replace standard with neostandard * chore: lint
1 parent d75b4f5 commit 5f84838

File tree

11 files changed

+137
-130
lines changed

11 files changed

+137
-130
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![CI](https://github.com/fastify/fastify-postgres/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/fastify-postgres/actions/workflows/ci.yml)
44
[![NPM version](https://img.shields.io/npm/v/@fastify/postgres.svg?style=flat)](https://www.npmjs.com/package/@fastify/postgres)
5-
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
5+
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)
66

77
Fastify PostgreSQL connection plugin; with this, you can share the same PostgreSQL connection pool in every part of your server.
88
Under the hood [node-postgres](https://github.com/brianc/node-postgres) is used, and the options that you pass to `register` will be passed to the PostgreSQL pool builder.

eslint.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict'
2+
3+
module.exports = require('neostandard')({
4+
ignores: require('neostandard').resolveIgnoresFromGitignore(),
5+
ts: true
6+
})
+14-14
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
import fastify from 'fastify';
1+
import fastify from 'fastify'
22

3-
import { fastifyPostgres } from '../../../index';
3+
import { fastifyPostgres } from '../../../index'
44

5-
const app = fastify();
5+
const app = fastify()
66

77
app.register(fastifyPostgres, {
88
name: 'sum',
99
connectionString: 'postgres://user:password@host:port/sub-db',
10-
});
10+
})
1111

1212
app.register(fastifyPostgres, {
1313
name: 'sub',
1414
connectionString: 'postgres://user:password@host:port/sub-db',
15-
});
15+
})
1616

1717
app.get('/calc', async () => {
18-
const sumClient = await app.pg.sum.connect();
19-
const subClient = await app.pg.sub.connect();
18+
const sumClient = await app.pg.sum.connect()
19+
const subClient = await app.pg.sub.connect()
2020

2121
const sumResult = await sumClient.query<{ sum: number }>(
2222
'SELECT 2 + 2 as sum'
23-
);
23+
)
2424
const subResult = await subClient.query<{ sub: number }>(
2525
'SELECT 6 - 3 as sub'
26-
);
26+
)
2727

28-
sumClient.release();
29-
subClient.release();
28+
sumClient.release()
29+
subClient.release()
3030

3131
return {
3232
sum: sumResult.rows,
3333
sub: subResult.rows,
34-
};
35-
});
34+
}
35+
})
3636

37-
export { app };
37+
export { app }

examples/typescript/single-db/app.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import fastify from 'fastify';
1+
import fastify from 'fastify'
22

3-
import { fastifyPostgres } from '../../../index';
3+
import { fastifyPostgres } from '../../../index'
44

5-
const app = fastify();
5+
const app = fastify()
66

77
app.register(fastifyPostgres, {
88
connectionString: 'postgres://user:password@host:port/db',
9-
});
9+
})
1010

1111
app.get('/calc', async () => {
12-
const client = await app.pg.connect();
12+
const client = await app.pg.connect()
1313

14-
const sumResult = await client.query<{ sum: number }>('SELECT 2 + 2 as sum');
14+
const sumResult = await client.query<{ sum: number }>('SELECT 2 + 2 as sum')
1515

16-
client.release();
16+
client.release()
1717

1818
return {
1919
sum: sumResult.rows,
20-
};
21-
});
20+
}
21+
})
2222

23-
export { app };
23+
export { app }
+23-23
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import fastify from 'fastify';
1+
import fastify from 'fastify'
22

3-
import { fastifyPostgres } from '../../../index';
3+
import { fastifyPostgres } from '../../../index'
44

5-
const app = fastify();
5+
const app = fastify()
66

77
app.register(fastifyPostgres, {
88
connectionString: 'postgres://user:password@host:port/db',
9-
});
9+
})
1010

1111
app.post('/init-async', async () => {
1212
const createTableQuery = `
@@ -15,14 +15,14 @@ app.post('/init-async', async () => {
1515
name varchar(80) NOT NULL,
1616
created_at timestamp default NULL
1717
);
18-
`;
18+
`
1919

2020
return app.pg.transact(async (client) => {
21-
const result = await client.query(createTableQuery);
21+
const result = await client.query(createTableQuery)
2222

23-
return result;
24-
});
25-
});
23+
return result
24+
})
25+
})
2626

2727
app.post('/init-cb', (_req, reply) => {
2828
const createTableQuery = `
@@ -31,22 +31,22 @@ app.post('/init-cb', (_req, reply) => {
3131
name varchar(80) NOT NULL,
3232
created_at timestamp default NULL
3333
);
34-
`;
34+
`
3535

3636
app.pg.transact(
3737
(client) => {
38-
return client.query(createTableQuery);
38+
return client.query(createTableQuery)
3939
},
4040
(error, result) => {
4141
if (error) {
42-
reply.status(500).send(error);
43-
return;
42+
reply.status(500).send(error)
43+
return
4444
}
4545

46-
reply.status(200).send(result);
46+
reply.status(200).send(result)
4747
}
48-
);
49-
});
48+
)
49+
})
5050

5151
app.post('/transact-route', { pg: { transact: true } }, async (req, _reply) => {
5252
const createTableQuery = `
@@ -55,10 +55,10 @@ app.post('/transact-route', { pg: { transact: true } }, async (req, _reply) => {
5555
name varchar(80) NOT NULL,
5656
created_at timestamp default NULL
5757
);
58-
`;
58+
`
5959

60-
return req.pg?.query(createTableQuery);
61-
});
60+
return req.pg?.query(createTableQuery)
61+
})
6262

6363
app.post(
6464
'/transact-route-alternate',
@@ -70,10 +70,10 @@ app.post(
7070
name varchar(80) NOT NULL,
7171
created_at timestamp default NULL
7272
);
73-
`;
73+
`
7474

75-
return req.pg?.query(createTableQuery);
75+
return req.pg?.query(createTableQuery)
7676
}
77-
);
77+
)
7878

79-
export { app };
79+
export { app }

index.d.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { FastifyPluginCallback } from 'fastify';
2-
import * as Pg from 'pg';
1+
import { FastifyPluginCallback } from 'fastify'
2+
import * as Pg from 'pg'
33

44
declare module 'fastify' {
55
export interface FastifyInstance {
@@ -15,7 +15,7 @@ declare module 'fastify' {
1515
}
1616
}
1717

18-
type FastifyPostgres = FastifyPluginCallback<fastifyPostgres.PostgresPluginOptions>;
18+
type FastifyPostgres = FastifyPluginCallback<fastifyPostgres.PostgresPluginOptions>
1919

2020
declare namespace fastifyPostgres {
2121
export type PostgresDb = {
@@ -24,11 +24,11 @@ declare namespace fastifyPostgres {
2424
query: Pg.Pool['query'];
2525
connect: Pg.Pool['connect'];
2626
transact: typeof transact;
27-
};
27+
}
2828

2929
export type FastifyPostgresRouteOptions = {
3030
transact: boolean | string;
31-
};
31+
}
3232

3333
export type PostgresPluginOptions = {
3434
/**
@@ -45,20 +45,20 @@ declare namespace fastifyPostgres {
4545
* Instance name of fastify-postgres
4646
*/
4747
name?: string;
48-
} & Pg.PoolConfig;
48+
} & Pg.PoolConfig
4949

50-
export function transact<TResult>(
50+
export function transact<TResult> (
5151
fn: (client: Pg.PoolClient) => Promise<TResult>
52-
): Promise<TResult>;
52+
): Promise<TResult>
5353

54-
export function transact<TResult>(
54+
export function transact<TResult> (
5555
fn: (client: Pg.PoolClient) => Promise<TResult>,
5656
cb: (error: Error | null, result?: TResult) => void
57-
): void;
57+
): void
5858

5959
export const fastifyPostgres: FastifyPostgres
6060
export { fastifyPostgres as default }
6161
}
6262

63-
declare function fastifyPostgres(...params: Parameters<FastifyPostgres>): ReturnType<FastifyPostgres>
64-
export = fastifyPostgres
63+
declare function fastifyPostgres (...params: Parameters<FastifyPostgres>): ReturnType<FastifyPostgres>
64+
export = fastifyPostgres

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"types": "index.d.ts",
88
"scripts": {
99
"check-examples": "tsc --build examples/typescript/*",
10-
"lint": "standard",
11-
"lint:fix": "standard --fix",
10+
"lint": "eslint",
11+
"lint:fix": "eslint --fix",
1212
"load-data": "docker exec -it fastify-postgres psql -c 'CREATE TABLE users(id serial PRIMARY KEY, username VARCHAR (50) NOT NULL);' -U postgres -d postgres",
1313
"postgres": "docker run -p 5432:5432 --name fastify-postgres -e POSTGRES_PASSWORD=postgres -d postgres:11-alpine",
1414
"test": "npm run test:unit && npm run test:typescript",
@@ -71,9 +71,9 @@
7171
"@types/pg": "^8.11.4",
7272
"c8": "^10.1.2",
7373
"fastify": "^5.0.0",
74+
"neostandard": "^0.12.0",
7475
"pg": "^8.11.3",
7576
"pg-native": "^3.0.1",
76-
"standard": "^17.1.0",
7777
"tsd": "^0.31.1",
7878
"typescript": "~5.7.2"
7979
},

test/types/imports.test-d.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import defaultPluginImport from '../../index';
2-
import {
3-
fastifyPostgres as namedPluginImport,
4-
PostgresDb,
5-
PostgresPluginOptions,
6-
} from '../../index';
1+
/* eslint-disable @typescript-eslint/no-unused-vars */
2+
import defaultPluginImport, {
3+
fastifyPostgres as namedPluginImport,
4+
PostgresDb,
5+
PostgresPluginOptions
6+
} from '../../index'

test/types/initialization.test-d.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import fastify from 'fastify';
2-
import * as pg from 'pg';
3-
import { expectAssignable, expectType } from 'tsd';
1+
import fastify from 'fastify'
2+
import * as pg from 'pg'
3+
import { expectAssignable, expectType } from 'tsd'
44

5-
import fastifyPostgres, { PostgresDb } from '../../index';
5+
import fastifyPostgres, { PostgresDb } from '../../index'
66

7-
const app = fastify();
7+
const app = fastify()
88

99
// Without parameters
10-
app.register(fastifyPostgres);
11-
app.register(fastifyPostgres, {});
10+
app.register(fastifyPostgres)
11+
app.register(fastifyPostgres, {})
1212

1313
// Own pg adapter
14-
app.register(fastifyPostgres, { pg });
14+
app.register(fastifyPostgres, { pg })
1515

1616
// Native libpq wrapper
17-
app.register(fastifyPostgres, { native: true });
17+
app.register(fastifyPostgres, { native: true })
1818

1919
// Multiple databases
20-
app.register(fastifyPostgres, { name: 'users' });
21-
app.register(fastifyPostgres, { name: 'posts' });
20+
app.register(fastifyPostgres, { name: 'users' })
21+
app.register(fastifyPostgres, { name: 'posts' })
2222

2323
// Pool options
2424
app.register(fastifyPostgres, {
@@ -27,13 +27,13 @@ app.register(fastifyPostgres, {
2727
database: 'mydb',
2828
password: 'secretpassword',
2929
port: 3211,
30-
});
30+
})
3131
app.register(fastifyPostgres, {
3232
connectionString: 'postgres://user:password@host:port/db',
33-
});
33+
})
3434

3535
// Plugin property available
3636
app.after(() => {
37-
expectAssignable<PostgresDb>(app.pg);
38-
expectType<PostgresDb>(app.pg.users);
39-
});
37+
expectAssignable<PostgresDb>(app.pg)
38+
expectType<PostgresDb>(app.pg.users)
39+
})

test/types/query.test-d.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
import fastify from 'fastify';
2-
import { Client, Pool, PoolClient, QueryResult } from 'pg';
3-
import { expectAssignable, expectType } from 'tsd';
1+
import fastify from 'fastify'
2+
import { Client, Pool, PoolClient, QueryResult } from 'pg'
3+
import { expectAssignable, expectType } from 'tsd'
44

5-
import fastifyPostgres, { PostgresDb } from '../../index';
5+
import fastifyPostgres, { PostgresDb } from '../../index'
66

7-
const app = fastify();
7+
const app = fastify()
88

99
app.register(fastifyPostgres, {
1010
connectionString: 'postgres://user:password@host:port/db',
11-
});
11+
})
1212

1313
app.get('/calc', async () => {
14-
expectAssignable<PostgresDb>(app.pg);
14+
expectAssignable<PostgresDb>(app.pg)
1515

16-
expectType<Pool>(app.pg.pool);
17-
expectType<Client>(app.pg.Client);
16+
expectType<Pool>(app.pg.pool)
17+
expectType<Client>(app.pg.Client)
1818

19-
const client = await app.pg.connect();
20-
expectType<PoolClient>(client);
19+
const client = await app.pg.connect()
20+
expectType<PoolClient>(client)
2121

22-
const sumResult = await client.query<{ sum: number }>('SELECT 2 + 2 as sum');
23-
expectType<QueryResult<{ sum: number }>>(sumResult);
22+
const sumResult = await client.query<{ sum: number }>('SELECT 2 + 2 as sum')
23+
expectType<QueryResult<{ sum: number }>>(sumResult)
2424

25-
client.release();
25+
client.release()
2626

2727
return {
2828
sum: sumResult.rows,
29-
};
30-
});
29+
}
30+
})

0 commit comments

Comments
 (0)