Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/koahubjs/koahub-mysql
KoaHub Mysql -- KoaHub.js mysql库
https://github.com/koahubjs/koahub-mysql
bookshelf koa koa2 koahub koahubjs mysql node node-mysql node-orm nodejs orm
Last synced: about 2 months ago
JSON representation
KoaHub Mysql -- KoaHub.js mysql库
- Host: GitHub
- URL: https://github.com/koahubjs/koahub-mysql
- Owner: koahubjs
- License: mit
- Created: 2017-03-20T14:14:09.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-07-25T09:04:00.000Z (over 2 years ago)
- Last Synced: 2023-12-16T06:34:04.275Z (about 1 year ago)
- Topics: bookshelf, koa, koa2, koahub, koahubjs, mysql, node, node-mysql, node-orm, nodejs, orm
- Language: JavaScript
- Homepage: http://js.koahub.com
- Size: 46.9 KB
- Stars: 4
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## 介绍
KoaHub Mysql -- KoaHub.js mysql库。
## 特性
1. 支持created_at, updated_at时间戳
2. 支持 `find`, `findPage`, `findAll`, `add`, `addAll` `save`, `saveAll`, `delete`, `deleteAll`
3. ...## 安装
```js
npm install koahubjs/koahub-mysql --save
```## 使用
```javascript
//创建app/middleware/mysql.middleware.js
module.exports = require('koahub-mysql');
//配置app/config/middleware.config.js
module.exports = {
mysql: {
"host": "127.0.0.1",
"user": "root",
"password": "",
"database": "koahub",
}
}
//配置app/config/default.config.js
module.exports = {
loader: {
"models": {
root: 'model',
suffix: '.model.js'
}
}
}
```### 入门
```js
// app/home/index.controller.js
module.exports = class extends koahub.controller {async _initialize() {
// 控制器初始化
}async index() {
const user = await this.model('user').findAll();
this.view(user);
}
}// app/model/user.model.js
module.exports = koahub.model.extend({
tableName: 'user',
hasTimestamps: true
});
```
### API
```
// 查询
this.model('user').find();
// 查询分页
this.model('user').findPage();
// 查询所有
this.model('user').findAll();
// 新增或者修改
this.model('user').add();
// 新增或者修改所有
this.model('user').addAll();
// 新增或者修改
this.model('user').save();
// 新增或者修改所有
this.model('user').saveAll();
// 删除
this.model('user').delete();
// 删除所有
this.model('user').deleteAll();// 更多方法请参考bookshelf
this.model('user').query();
this.model('user').count();
this.model('user').where();
...```
## KoaHub.js
[KoaHub.js框架](https://github.com/koahubjs/koahub)## 官网
[KoaHub.js官网](http://js.koahub.com)