Answer the question
In order to leave comments, you need to log in
What does Sequelize give?
Good afternoon. Making a request to the database
User.findAll().then(users => {
console.log(users)
});
_evictionIterator:
DequeIterator {
_list:
DoublyLinkedList {
head:
{ prev: null,
next:
{ prev: [Circular],
next: null,
data:
PooledResource {
creationTime: 1541403796957,
lastReturnTime: 1541403796967,
lastBorrowTime: 1541403796962,
lastIdleTime: 1541403796967,
obj:
Client {
domain: null,
_events:
[Object: null prototype] { end: [Function], error: [Function] },
_eventsCount: 2,
_maxListeners: undefined,
connectionParameters:
ConnectionParameters {
user: 'postgres',
import { Sequelize } from 'sequelize-typescript';
import * as express from 'express';
import { appconfig } from '../config/appconfig';
import app from "./app";
import {User } from "../modules/user/models/user.model";
const server = express();
// allow access from client server
server.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3000');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
next();
});
export const sequelize = new Sequelize({
database: appconfig.dbdatabase,
dialect: appconfig.dbdialect,
username: appconfig.dbusername,
password: appconfig.dbpassword,
host: appconfig.dbhost,
port: appconfig.dbport
});
sequelize.authenticate().then(() => {
console.log("Connected to DB");
})
.catch((err) => {
console.log(err);
})
app.listen(appconfig.port, () => {
console.log('Express server listening on port ' + appconfig.port);
})
sequelize.addModels([User]);
User.findAll().then(users => {
console.log(users)
});
Answer the question
In order to leave comments, you need to log in
Returns an object with its own iterator implementation, you can iterate over this object, each data stack is wrapped in a model in it. For output to the console, they can be brought into a readable form, for example, like this: https://learn.javascript.ru/iterator
You can pass an additional object with options to the findAll method, one of which allows you to get only data from the database: findAll .
In your case, the request will look like this:
User.findAll({ raw: true }).then(users => {
console.log(users)
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question