Created
August 23, 2022 22:28
-
-
Save rainrisa/17c3944c393eb59a5e43e319cb156170 to your computer and use it in GitHub Desktop.
learn sequelize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Sequelize, DataTypes } from "sequelize"; | |
const sequelize = new Sequelize("rainjn", "root", "", { | |
host: "localhost", | |
dialect: "mysql", | |
define: { | |
timestamps: false, | |
}, | |
}); | |
const queryInterface = sequelize.getQueryInterface(); | |
queryInterface.createTable("admins", { | |
id: { | |
type: DataTypes.INTEGER, | |
primaryKey: true, | |
autoIncrement: true, | |
}, | |
name: DataTypes.STRING, | |
age: DataTypes.INTEGER, | |
}); | |
const Admin = sequelize.define("admins", { | |
id: { | |
type: DataTypes.INTEGER, | |
primaryKey: true, | |
autoIncrement: true, | |
}, | |
name: DataTypes.STRING, | |
age: DataTypes.INTEGER, | |
}); | |
(async () => { | |
const admins = await Admin.findAll(); | |
console.log(admins); | |
await Admin.create({ | |
name: "javascript", | |
age: 73, | |
}); | |
const admins2 = await Admin.findAll(); | |
console.log(admins2); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment