Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/styllloz/public_html/qa-include/qa-base.php on line 1175

Warning: session_start(): Cannot start session when headers already sent in /home/styllloz/public_html/qa-include/app/users.php on line 162

Warning: Cannot modify header information - headers already sent by (output started at /home/styllloz/public_html/qa-include/qa-base.php:1175) in /home/styllloz/public_html/qa-include/app/users.php on line 1267

Warning: Cannot modify header information - headers already sent by (output started at /home/styllloz/public_html/qa-include/qa-base.php:1175) in /home/styllloz/public_html/qa-include/app/page.php on line 356
That gives Sequelize? - code-flow.club | Q&A

That gives Sequelize?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
11 views
Good afternoon. Make a request to the database
User.findAll().then(users => { console.log(users) });


using sequelize, get a sheet in the console, including the database connection etc. Moreover, without stopping
_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'

and so on.

My code
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) });


What is there sequelize returns? This is because without the promise?
An example query taken from Getting Started
by | 11 views

2 Answers

0 like 0 dislike
Returns an object with its own implementation of the iterator, you can iterate over this object in it, each stack is wrapped in a data model. To output to the console, they can result in the readable view, like so:

console.log(users.map(user => user.toJSON()))

\rhttps://learn.javascript.ru/iterator
by
0 like 0 dislike
In findAll you can pass an optional object with options, one of which allows you to get only the data from the database: findAll.
In your case the query would look like this:
User.findAll({ raw: true }).then(users => { console.log(users) });
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
35,181 users