Skip to content

Instantly share code, notes, and snippets.

@rainrisa
Created August 23, 2022 22:28
Show Gist options
  • Save rainrisa/17c3944c393eb59a5e43e319cb156170 to your computer and use it in GitHub Desktop.
Save rainrisa/17c3944c393eb59a5e43e319cb156170 to your computer and use it in GitHub Desktop.
learn sequelize
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