Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/inthepocket/fastify-typeorm-plugin
Fastify plugin for TypeORM
https://github.com/inthepocket/fastify-typeorm-plugin
fastify fastify-plugin typeorm
Last synced: 26 days ago
JSON representation
Fastify plugin for TypeORM
- Host: GitHub
- URL: https://github.com/inthepocket/fastify-typeorm-plugin
- Owner: inthepocket
- License: mit
- Created: 2019-12-19T12:47:18.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-08-04T08:48:06.000Z (over 2 years ago)
- Last Synced: 2024-10-08T15:10:59.924Z (about 1 month ago)
- Topics: fastify, fastify-plugin, typeorm
- Language: JavaScript
- Homepage:
- Size: 29.3 KB
- Stars: 24
- Watchers: 6
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fastify-typeorm
[![Package Version](https://img.shields.io/npm/v/fastify-typeorm-plugin.svg)](https://npm.im/fastify-typeorm-plugin)
[![Build Status](https://travis-ci.org/inthepocket/fastify-typeorm-plugin.svg?branch=master)](https://travis-ci.org/inthepocket/fastify-typeorm-plugin)
[![Greenkeeper badge](https://badges.greenkeeper.io/inthepocket/fastify-typeorm-plugin.svg)](https://greenkeeper.io/)
[![Coverage Status](https://coveralls.io/repos/github/inthepocket/fastify-typeorm-plugin/badge.svg?branch=master)](https://coveralls.io/github/inthepocket/fastify-typeorm-plugin?branch=master)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.## Install
```sh
npm install fastify-typeorm-plugin
```## Usage
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.```js
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;
});
```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:
```js
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
- Glenn Bostoen
- Jonas Goderis## License
Licensed under [MIT](./LICENSE).