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

  • 相关阅读:
    MySQL 查询各科前三的数据
    MySQL 分时间段查询
    MySQL 查询同一字段中同时满足多个条件
    MySQL 分组累加
    快速搭建LNMP
    打开页面默认弹出软键盘,同时兼容iOS和Android
    linux 系统的ssh服务
    linux 磁盘
    linux系统基础网络配置
    discuz中方法
  • 原文地址:https://www.cnblogs.com/liuhao-web/p/8530051.html
Copyright © 2011-2022 走看看