# koa-middleware-orm

> ## Install

Latest version **1.0.0** (published 2018-12-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-middleware-orm
pnpm add koa-middleware-orm
yarn add koa-middleware-orm
bun add koa-middleware-orm
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-12-13 |
| First published | 2018-12-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 3.5 KB |
| Known vulnerabilities | 0 (+12 in 2 direct dependencies) |
| Install scripts | no |
| Author | lijialiang@yy.com |
| Maintainers | yyued |

## Links

- npm: https://www.npmjs.com/package/koa-middleware-orm
- Repository: https://github.com/lilijialiang/koa-middleware-orm
- Homepage: https://github.com/lilijialiang/koa-middleware-orm#readme
- Issues: https://github.com/lilijialiang/koa-middleware-orm/issues
- npm.io page: https://npm.io/package/koa-middleware-orm

## Dependencies (2)

- [mysql2](https://npm.io/package/mysql2.md) ^1.6.4
- [sequelize](https://npm.io/package/sequelize.md) ^4.41.2

## Recent versions

- 1.0.0 (latest) — 2018-12-13

## README

# koa-middleware-orm

## Install

```sh
npm i koa-middleware-orm

# or

yarn add koa-middleware-orm
```

## How to use

```js
// user.js
const Sequelize = require('sequelize')

module.exports = function (sequelize) {
  const model = sequelize.define('user', {
    id: {
      field: 'id',
      type: Sequelize.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    name: {
      field: 'name',
      type: Sequelize.STRING
    }
  }, { freezeTableName: true, timestamps: false })

  return { name: 'user', model }
}
```

```js
// app.js
const Koa = require('koa')
const orm = require('koa-middleware-orm')

const app = new Koa()

app.use(orm({
  host: 'xxx',
  db: 'test',
  account: 'xxx',
  password: 'xxx'
}, ['./user.js']))

app.use(async ctx => {
  ctx.body = await ctx.models.user.findAll()
})

app.listen(3000)
```

## LICENSE

[MIT](./LICENSE)

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