# loopback-typeorm

> Easy way to use TypeORM datasource in Loopback application.

Latest version **1.0.1** (published 2023-07-07) · Apache 2.0 license · 0 weekly downloads

## Install

```sh
npm install loopback-typeorm
pnpm add loopback-typeorm
yarn add loopback-typeorm
bun add loopback-typeorm
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2023-07-07 |
| First published | 2023-02-15 |
| Weekly downloads | 0 |
| License | Apache 2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | 16 \|\| 18 \|\| 19 |
| Dependencies | 3 |
| Unpacked size | 19.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | vpikachu |
| Maintainers | vpikachu |
| Keywords | loopback-extension, loopback-typeorm, loopback, typeorm |

## Links

- npm: https://www.npmjs.com/package/loopback-typeorm
- Repository: https://github.com/vpikachu/loopback-typeorm
- Homepage: https://github.com/vpikachu/loopback-typeorm#readme
- Issues: https://github.com/vpikachu/loopback-typeorm/issues
- npm.io page: https://npm.io/package/loopback-typeorm

## Dependencies (3)

- [tslib](https://npm.io/package/tslib.md) ^2.6.0
- [typeorm](https://npm.io/package/typeorm.md) ^0.3.17
- [@loopback/core](https://npm.io/package/@loopback/core.md) ^5.0.0

## Alternatives

- [@libsql/sqlite3](https://npm.io/package/@libsql/sqlite3.md) — 39.8K weekly downloads
- [@fortemi/core](https://npm.io/package/@fortemi/core.md) — 461 weekly downloads
- [cdb-converter](https://npm.io/package/cdb-converter.md) — 341 weekly downloads
- [@uplo/adapter-prisma](https://npm.io/package/@uplo/adapter-prisma.md) — 75 weekly downloads
- [typeorm-aios](https://npm.io/package/typeorm-aios.md) — 30 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2023-07-07
- 1.0.0 — 2023-02-15

## README

# loopback-typeorm

## Installation

Install packages using `npm`;

```sh
$ npm install loopback-typeorm reflect-metadata
```

Also you are required to install database drivers for your datasources. More info: https://typeorm.io/#installation

## Basic Use

Describe your entities. More info: https://typeorm.io/#step-by-step-guide

Create observer in `src/observers/my-typeorm.observer.ts`.

```ts
import {TypeOrmDataSource} from 'loopback-typeorm';

export class MyTypeOrmDataSource extends TypeOrmDataSource {}
```

If you have created your observer in different file like `src/observers/**.observer.ts`, be sure to manually register the observer in the application instance(https://loopback.io/doc/en/lb4/Life-cycle.html#register-a-life-cycle-observer).

Bind TypeORM connection options of your application instance:

```ts
//application.ts file...
import {MyTypeOrmDataSource} from 'observers/my-typeorm.observer';
//...
const myDSOptions: DataSourceOptions = {
  type: 'sqlite',
  database: ':memory:',
  dropSchema: false,
  entities: [
    //your entites...
  ],
  synchronize: true,
  logging: true,
};
this.bind(MyTypeOrmDataSource.OPTIONS_KEY).to(myDSOptions);
//app.bind(MyTypeOrmDataSource.OPTIONS_KEY).to(myDSOptions);
//...
```

Inject TypeORM datasource wherever you need using binding key `MyTypeOrmDataSource.DATASOURCE_KEY`. Controller example:

```ts
//...
export class MyController {
  constructor(
    @inject(MyTypeOrmDataSource.DATASOURCE_KEY)
    private myDatasource: DataSource,
  ) {}
//...
```

That's all. Now you are happy to play with TypeORM datasource ;)

## Examples

You can find examples of using this package in the source folder [/examples](https://github.com/vpikachu/loopback-typeorm/tree/main/examples)

## License

[Apache 2.0](https://github.com/vpikachu/loopback-typeorm/blob/main/LICENSE)

---
_Source: https://npm.io/package/loopback-typeorm · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
