Answer the question
In order to leave comments, you need to log in
How to get started with sequelize?
I can't figure out how to create a connection, where to start creating and using models.
An attempt to call User.findAll() crashes:
Unhandled rejection SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:8889
import * as DB from 'sequelize';
// import {connection} from "../db";
export const connection: DB.Sequelize = new DB('osbd', 'username', 'password', {
host: 'localhost',
port: 8889,
dialect: 'mysql',
pool: {
max: 5,
min: 0,
idle: 10000
},
});
export interface UserAttributes
{
login: string;
pass: string;
name: string;
}
export interface UserInstance extends DB.Instance<UserInstance>, UserAttributes {}
export interface UserModel extends DB.Model<UserInstance, UserAttributes> {}
export const User: UserModel = connection.define<UserInstance, UserAttributes>('User', {
login: {
type: DB.STRING(64),
unique: true,
},
pass: DB.STRING(32),
name: DB.STRING(64),
});
User.findAll().then(console.log);
Answer the question
In order to leave comments, you need to log in
The solution was here:
export const connection: DB.Sequelize = new DB('bd', 'username', 'password', {
...
dialectOptions: {
socketPath: '/Applications/MAMP/tmp/mysql/mysql.sock'
},
...
});
To start in the console
And then look at what structure he created and what lies inside. You can get away from this.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question