Skip to content
Fastify plugin for TypeORM
JavaScript Shell
Branch: master
Clone or download
gboston Merge pull request #5 from inthepocket/bug/connection-namespace
Remove connection on root when namespaced
Latest commit d5bae4c Dec 23, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Init TypeORM plugin for fastify Dec 19, 2019
.travis.yml Init TypeORM plugin for fastify Dec 19, 2019
LICENSE Init TypeORM plugin for fastify Dec 19, 2019
README.md Add coveralls badge Dec 23, 2019
index.d.ts Make use of type definitions Dec 21, 2019
index.js Remove connection on root when namespaced Dec 23, 2019
package.json Bump version to v2.1.0 Dec 21, 2019
pg-docker.sh
test.js Remove connection on root when namespaced Dec 23, 2019

README.md

fastify-typeorm-plugin

Package Version Build Status Greenkeeper badge Coverage Status

Fastify plugin for TypeORM for sharing the same TypeORM connection in every part of your server.
Under the hood the official TypeORM module is used.

Install

npm install fastify-typeorm-plugin

Usage

Add it to your project with register and you are done!
The plugin accepts the same connection options as the TypeORM client.

const fastify = require('fastify')();

const user = require('./entity/user');

fastify.register(require('fastify-typeorm-plugin'), {
  type: 'sqlite',
  database: './mydb.sql',
});

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:

const { createConnection } = require('typeorm');

const fastify = require('fastify')();
const connection = await createConnection({
  type: 'sqlite',
  database: './mydb.sql',
});
fastify.register(require('fastify-typeorm-plugin'), {
  connection,
});

Team

License

Licensed under MIT.

You can’t perform that action at this time.