# fomex-sequelize

Latest version **0.0.39** (published 2020-08-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install fomex-sequelize
pnpm add fomex-sequelize
yarn add fomex-sequelize
bun add fomex-sequelize
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.39 |
| Published | 2020-08-17 |
| First published | 2020-05-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 10.13.0 |
| Dependencies | 10 |
| Unpacked size | 231.4 KB |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| Author | 范文华 |
| Maintainers | fwh1990 |

## Links

- npm: https://www.npmjs.com/package/fomex-sequelize
- Repository: https://github.com/fomex-ts/fomex-sequelize
- Homepage: https://github.com/fomex-ts/fomex-sequelize#readme
- Issues: https://github.com/fomex-ts/fomex-sequelize/issues
- npm.io page: https://npm.io/package/fomex-sequelize

## Dependencies (10)

- [glob](https://npm.io/package/glob.md) ^7.1.6
- [chalk](https://npm.io/package/chalk.md) ^4.0.0
- [tslib](https://npm.io/package/tslib.md) ^2.0.0
- [umzug](https://npm.io/package/umzug.md) 3.0.0-beta.5
- [mkdirp](https://npm.io/package/mkdirp.md) ^1.0.4
- [sequelize](https://npm.io/package/sequelize.md) 5.21.13
- [@types/bluebird](https://npm.io/package/@types/bluebird.md) ^3.5.32
- [@types/validator](https://npm.io/package/@types/validator.md) ^13.0.0
- [lodash.snakecase](https://npm.io/package/lodash.snakecase.md) ^4.1.1
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13

## Recent versions

- 0.0.39 (latest) — 2020-08-17
- 0.0.38 — 2020-08-13
- 0.0.37 — 2020-06-14
- 0.0.36 — 2020-06-14
- 0.0.35 — 2020-06-11
- 0.0.34 — 2020-06-10
- 0.0.33 — 2020-06-09
- 0.0.32 — 2020-06-05
- 0.0.31 — 2020-05-30
- 0.0.30 — 2020-05-29
- 0.0.28 — 2020-05-29
- 0.0.27 — 2020-05-29
- 0.0.26 — 2020-05-29
- 0.0.25 — 2020-05-27
- 0.0.24 — 2020-05-27
- … 23 more at https://npm.io/package/fomex-sequelize/versions

## README

# Fomex Sequelize


[![License](https://img.shields.io/github/license/fomex-ts/fomex-sequelize)](https://github.com/fomex-ts/fomex-sequelize/blob/master/LICENSE)
[![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/fomex-ts/fomex-sequelize/CI/master)](https://github.com/fomex-ts/fomex-sequelize/actions)
[![Codecov](https://img.shields.io/codecov/c/github/fomex-ts/fomex-sequelize)](https://codecov.io/gh/fomex-ts/fomex-sequelize)

# Installation

```bash
yarn add fomex-sequelize
```

# Initialization
```typescript
// src/bootstrap.ts

import { Sequelize } from 'fomex-sequelize';

export const sequelize = new Sequelize({
  // ...
});
```

# Register plugin
```typescript
// src/bootstrap.ts

import { baseWebRouter, baseConsoleCommander } from 'fomex';
import { PluginSequelize } from 'fomex-sequelize';

const sequelizePlugin = new PluginSequelize(sequelize);

export const webRouter = baseWebRouter.global(sequelizePlugin);

export const consoleCommander = baseConsoleCommander.global(sequelizePlugin);
```

# Register commands
```typescript
// src/console.ts

import { ConsoleApplication } from 'fomex';
import { getSequelizeCommandsPath } from 'fomex-sequelize';

const app = new ConsoleApplication({
  commandsPath: [
    getSequelizeCommandsPath(sequelize),
  ],
});

app.run();
```

Now, feel free to input command `npx fomex` in terminal and see what is shown.

# Define model
```typescript
// src/models/User.ts

import { Model, column } from 'fomex-sequelize';

export class User extends Model {
  id = column.int.primaryKey().autoIncrement();

  name = column.string.notNull();
}
```

Then, try to import model class into routes or commands
```typescript
// src/routes/user.ts

import { rule } from 'fomex';
import { webRouter } from '../bootstrap';
import { User } from '../models/User';

export default webRouter({
  routes() {
    this
      .get('/users')
      .action(async (ctx) => {
        const users = await User.findAll();

        ctx.send(200, users);
      });

    this
      .get('/users/:id')
      .params({
        id: rule.number,
      })
      .action(async (ctx) => {
        const user = await User.find({
          where: {
            id: ctx.request.params.id,
          },
        });

        if (user) {
          ctx.send(user);
        } else {
          ctx.send(404);
        }
      });
  }
});
```

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