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))
    })*/

  • 相关阅读:
    .NETCORE微服务架构--网关篇(Ocelot)
    Hangfire实战--添加DashBoard登录权限
    IIS发布-HTTP谓词限制访问
    基于Dapper的泛型Repository
    .Net Framework JWT验证
    .Net Framework swagger 进阶----头部参数
    .Net Framework下安装api swagger
    ErrorSet
    201907总结
    博客美化
  • 原文地址:https://www.cnblogs.com/liuhao-web/p/8530051.html
Copyright © 2011-2022 走看看