Git Product home page Git Product logo

koahub-mysql's Introduction

介绍

KoaHub Mysql -- KoaHub.js mysql库。

特性

  1. 支持created_at, updated_at时间戳
  2. 支持 find, findPage, findAll, add, addAll save, saveAll, delete, deleteAll
  3. ...

安装

npm install koahubjs/koahub-mysql --save

使用

//创建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'
        }
    }
}

入门

// 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框架

官网

KoaHub.js官网

koahub-mysql's People

Contributors

einsqing avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.