zoukankan      html  css  js  c++  java
  • Sequelize的增删改查

    //启动mysql数据库

    net start mysql

    //新建index.js

    //建立连接
    var Sequelize=require("sequelize");
    var mysql=require("mysql");
    var sequelize=new Sequelize("h5ds",'root','YES',{
    host:'localhost',
    dialect:'mysql',
    port:3306,
    pool:{
    max:5,
    min:0,
    idle:10000
    },
    define:{
    'underscored':true
    }
    })

    var user=sequelize.define("h5ds_user",{
    id:{type:Sequelize.INTEGER,primaryKey:true,autoIncrement: true,field:"id"},
    username:{type:Sequelize.STRING,field:'username'},
    password:{type:Sequelize.STRING,field:'password'},
    email:{type:Sequelize.STRING,field:'email'},
    usertype:{type:Sequelize.INTEGER,field:'usertype'},
    tel:{type:Sequelize.STRING,field:'tel'}
    },
    {freezeTableName: true}
    )
    /*user.sync({force:false}).then(function(){
    return user.create({
    username:"liuhao",
    password:"123",
    email:"8888888",
    usertype:1,
    tel:"12334556"
    })
    }).then(function(res){
    console.log("@@@@@@@@@++++"+JSON.stringify(res))
    })*/
    /*user.sync({force:false}).then(function(){
    return user.update({
    username:"liuhao666",
    },{where:{
    id:1
    }})
    }).then(function(res){
    console.log("@@@@@@@@@++++"+JSON.stringify(res))
    })*/

    /*user.sync({force:false}).then(function(){
    return user.findAll({
    where:{
    username:'liuhao666'
    },
    })
    }).then(function(res){
    console.log("@@@@@@@@@++++"+JSON.stringify(res))
    })*/

    /*user.sync({force:false}).then(function(){
    return user.destroy({
    where:{
    username:'liuhao666'
    },
    })
    }).then(function(res){
    console.log("@@@@@@@@@++++"+JSON.stringify(res))
    })*/

  • 相关阅读:
    设计模式总结
    JWT、OAUTH2与SSO资料补充
    dajie项目的坑
    fw-cloud-framework项目配置、启动问题
    Shiro源码分析
    (转)JPA & Restful
    Spring Boot以War包启动
    (转)Spring & SpringMVC学习
    MySQL的数据类型(二)
    MySQL的数据类型(一)
  • 原文地址:https://www.cnblogs.com/liuhao-web/p/8530051.html
Copyright © 2011-2022 走看看