# @clusic/mysql-orm

> The mysql orm plugin of clusic

Latest version **1.0.5** (published 2019-01-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install @clusic/mysql-orm
pnpm add @clusic/mysql-orm
yarn add @clusic/mysql-orm
bun add @clusic/mysql-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.5 |
| Published | 2019-01-10 |
| First published | 2018-12-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 10.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | evio |
| Keywords | mysql, clusic, orm |

## Links

- npm: https://www.npmjs.com/package/@clusic/mysql-orm
- Repository: https://github.com/clusic/mysql-orm
- Homepage: https://github.com/clusic/mysql-orm#readme
- Issues: https://github.com/clusic/mysql-orm/issues
- npm.io page: https://npm.io/package/@clusic/mysql-orm

## Dependencies (1)

- [mysql](https://npm.io/package/mysql.md) ^2.16.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.5 (latest) — 2019-01-10
- 1.0.4 — 2018-12-30
- 1.0.3 — 2018-12-30
- 1.0.2 — 2018-12-30
- 1.0.1 — 2018-12-30
- 1.0.0 — 2018-12-30

## README

# @clusic / mysql-orm

mysql数据库操作类

## Install

```shell
# common use
npm i @clusic/mysql-orm

# or use in clusic/rex
clusic add @clusic/mysql-orm --plugin
```

## Usage

```javascript
const MySQL = require('@clusic/mysql-orm');
const mysql = new MySQL(options);
const ctx = mysql.thread();
await ctx.begin();
await ctx.exec(sql, ...conditions);
await ctx.commit();
await ctx.rollback();
await ctx[table_name].grep(data);
await ctx[table_name].insert(data);
await ctx[table_name].update(data, where, ...wheres);
await ctx[table_name].delete(where, ...wheres);
await ctx[table_name].exec(columns, where, wheres);
ctx.release();
```

## Events

- beforeBegin 事务开启前
- begin 事务开启后
- beforeCommit 提交前
- commit 提交后
- beforeRollback 回滚前
- rollback 回滚后
- beforeExec 执行SQL语句前
- exec 执行SQL语句后

```javascript
mysql.on('begin', (sql, ...args) => console.log('事务开始了'));
mysql.on('exec', (res) => console.log(res));
```

## Use in Clusic

在worker中，ctx上会存在一个你在配置[database]属性名的对象，指向当前mysql操作对象。

```javascript
await ctx[database].begin();
await ctx[database].commit();
```

在agent中，全局app[database]指向对应的操作对象。

```javascript
app.feed(name, async () => {
  await app.mysql.begin();
  await app.mysql.commit();
})
```

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