fastify-typeorm-plugin
Advanced tools
Sorry, the diff of this file is not supported yet
+2
-11
@@ -21,7 +21,3 @@ import * as http from 'http'; | ||
| declare module 'fastify' { | ||
| interface FastifyInstance< | ||
| HttpServer = http.Server, | ||
| HttpRequest = http.IncomingMessage, | ||
| HttpResponse = http.ServerResponse | ||
| > { | ||
| export interface FastifyInstance { | ||
| orm: typeorm.Connection & fastifyTypeorm.FastifyTypeormNestedObject; | ||
@@ -31,9 +27,4 @@ } | ||
| declare let fastifyTypeorm: fastify.Plugin< | ||
| http.Server, | ||
| http.IncomingMessage, | ||
| http.ServerResponse, | ||
| fastifyTypeorm.FastifyTypeormOptions | ||
| >; | ||
| declare const fastifyTypeorm: fastify.FastifyPluginCallback<fastifyTypeorm.FastifyTypeormOptions>; | ||
| export = fastifyTypeorm; |
+8
-1
@@ -10,3 +10,10 @@ 'use strict' | ||
| const connection = options.connection || await createConnection(options) | ||
| let connection | ||
| if (options.connection) { | ||
| connection = options.connection | ||
| } else if (Object.keys(options).length) { | ||
| connection = await createConnection(options) | ||
| } else { | ||
| connection = await createConnection() | ||
| } | ||
@@ -13,0 +20,0 @@ if (namespace) { |
+4
-4
| { | ||
| "name": "fastify-typeorm-plugin", | ||
| "version": "2.1.3", | ||
| "version": "2.2.0", | ||
| "description": "Fastify plugin for typeorm", | ||
@@ -33,6 +33,6 @@ "main": "index.js", | ||
| "pre-commit": "^1.2.2", | ||
| "snazzy": "^8.0.0", | ||
| "standard": "^15.0.0", | ||
| "tap": "^14.2.0" | ||
| "snazzy": "^9.0.0", | ||
| "standard": "^16.0.3", | ||
| "tap": "^15.0.9" | ||
| } | ||
| } |
+25
-2
@@ -8,3 +8,3 @@ # fastify-typeorm | ||
| Fastify plugin for TypeORM for sharing the same TypeORM connection in every part of your server. | ||
| Fastify plugin for TypeORM for sharing the same TypeORM connection in every part of your server. | ||
| Under the hood the official [TypeORM](https://www.npmjs.com/package/typeorm) module is used. | ||
@@ -20,3 +20,3 @@ | ||
| Add it to your project with `register` and you are done! | ||
| Add it to your project with `register` and you are done! | ||
| The plugin accepts the [same connection options](https://typeorm.io/#/connection-options) as the TypeORM client. | ||
@@ -48,2 +48,25 @@ | ||
| If you won't pass config, it will use `typeorm` default [createConnection](https://typeorm.io/#/connection/creating-a-new-connection) mechanism: | ||
| ```js | ||
| const fastify = require('fastify')(); | ||
| const user = require('./entity/user'); | ||
| fastify.register(require('fastify-typeorm-plugin')); | ||
| fastify.get('/users', async function(req, reply) { | ||
| const users = await this.orm | ||
| .getRepository(User) | ||
| .createQueryBuilder('user') | ||
| .getMany(); | ||
| return users; | ||
| }); | ||
| fastify.listen(3000, err => { | ||
| if (err) throw err; | ||
| }); | ||
| ``` | ||
| You can also pass in an existing connection: | ||
@@ -50,0 +73,0 @@ |
+14
-0
@@ -24,2 +24,16 @@ 'use strict' | ||
| test('Postgres available through env variables', async t => { | ||
| process.env.TYPEORM_CONNECTION = 'postgres' | ||
| process.env.TYPEORM_HOST = 'localhost' | ||
| process.env.TYPEORM_USERNAME = 'postgres' | ||
| process.env.TYPEORM_DATABASE = 'postgres' | ||
| process.env.TYPEORM_PORT = '5432' | ||
| const fastify = Fastify() | ||
| fastify.register(fastifyORM) | ||
| await fastify.ready() | ||
| t.strictEqual(fastify.orm.name, 'default') | ||
| await fastify.close() | ||
| }) | ||
| test('with unreachable db', async t => { | ||
@@ -26,0 +40,0 @@ const fastify = Fastify() |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 5 instances in 1 package
9143
11.77%9
12.5%154
6.94%92
33.33%5
Infinity%