# admin-bro-mikroorm

> MikroORM adapter for AdminBro

Latest version **1.0.1** (published 2021-05-07) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install admin-bro-mikroorm
pnpm add admin-bro-mikroorm
yarn add admin-bro-mikroorm
bun add admin-bro-mikroorm
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-05-07 |
| First published | 2021-04-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 42.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Rafał Dzięgielewski |
| Maintainers | dziraf |
| Keywords | mikroorm, provider, admin-bro, orm admin, mikroorm admin, admin panel |

## Links

- npm: https://www.npmjs.com/package/admin-bro-mikroorm
- Repository: https://github.com/dziraf/admin-bro-mikroorm
- Homepage: https://github.com/dziraf/admin-bro-mikroorm#readme
- Issues: https://github.com/dziraf/admin-bro-mikroorm/issues
- npm.io page: https://npm.io/package/admin-bro-mikroorm

## Dependencies (1)

- [flat](https://npm.io/package/flat.md) ^5.0.2

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2021-05-07
- 1.0.0 — 2021-04-01

## README

## admin-bro-mikroorm

This is an *unofficial* [admin-bro](https://github.com/SoftwareBrothers/admin-bro) adapter which integrates [MikroORM](https://github.com/mikro-orm/mikro-orm) into admin-bro.

Note that this is a first release and it's currently tested using only the example setup found in this repository.

If you are having trouble integrating this adapter in your project, please open an issue and try to describe the problem with as many details as possible.

### Installation

yarn
```bash
$ yarn add admin-bro-mikroorm
```

npm
```bash
$ npm i admin-bro-mikroorm
```

## Usage

The plugin can be registered using standard `AdminBro.registerAdapter` method.

```typescript
import { Database, Resource } from 'admin-bro-mikroorm';
import AdminBro from 'admin-bro';
import { validate } from 'class-validator';

const setupAdminBro = async () => {
  const orm = await MikroORM.init({
    entities: [User],
    dbName: process.env.DATABASE_NAME,
    type: 'postgresql',
    clientUrl: process.env.DATABASE_URL,
  });

  // MikroORM exposes it's entity manager through created ORM instance (`orm.em`) and it's required for
  // the adapter to run database queries. The static method `Resource.setORM` extracts required properties from your
  // ORM instance.
  Resource.setORM(orm);
  // If your entities use `class-validator` to validate data, you can inject it's validate method into the resource.
  Resource.validate = validate;
  AdminBro.registerAdapter({ Database, Resource });

  // You can instantiate AdminBro either by specifying all resources separately:
  const adminBro = new AdminBro({
    resources: [{ resource: User, options: {} }],
  });

  // Or by passing your ORM instance into `databases` property.
  const adminBro = new AdminBro({
    databases: [orm],
  });
  // You should choose to use either `resources` or `databases`
};
```

## Example

An example project can be found in `example-app` directory.

## Associations

Currently only `ManyToOne` and `OneToOne` relationships are supported due to current AdminBro's core limitations
for adapter integrations. `OneToMany` and `ManyToMany` relationships can still be achieved through a combination of custom components and hooks.

## Contribution

### Running the example app

If you want to set this up locally this is the suggested process:

1. Fork the repo
2. Install dependencies

```
yarn install
```

3. Register this package as a (linked package)[https://classic.yarnpkg.com/en/docs/cli/link/]

```
yarn link
```

4. Setup example app

Install all dependencies and use previously linked version of `admin-bro-mikroorm`.

```
cd example-app
yarn install
yarn link admin-bro-mikroorm
```

Optionally you might want to link your local version of `admin-bro` package

5. Make sure you have all the envs set (see `./example-app/example.env` and create an `.env` file based on that)

6. Build the package in watch mode

(in the root folder)

```
yarn dev
```

6. Run the app in the dev mode

```
cd example-app
yarn dev
```

### Pull request

Before you make a PR make sure all tests pass and your code wont causes linter errors.
You can do this by running:

```
yarn lint
yarn test
```

Make sure you have an `.env` file in project's root directory for the test runner to use:
```
DATABASE_URL=postgres://postgres:@localhost:5433/mikroorm_test
DATABASE_NAME=mikroorm_test
```

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