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

  • 相关阅读:
    DFS 之 全排列
    蓝桥杯: 标题:第几个幸运数
    第K个幸运数字(4、7)
    C++将十进制数转化为二进制
    C++中数组声名后不初始化,数组里的值都是0吗?
    html和jsp区别
    中缀表达式转换为后缀表达式
    多个Activity之间共享数据的方式
    Jupyter Notebook入门教程
    Android之Activity生命周期详解
  • 原文地址:https://www.cnblogs.com/liuhao-web/p/8530051.html
Copyright © 2011-2022 走看看