-2
DATABASE
I have this database:
In it I have this table:
In it I have this data:
NODE
const express = require('express');
const app = express();
const cors = require('cors');
// cors config // origin: 'http://127.0.0.1:3000/'
app.use(cors({
origin: '*'
}));
// middlewares
app.use(express.json());
app.use(express.urlencoded({ extended: false }))
// Database
const { Pool } = require('pg');
const parse = require('pg-connection-string').parse;
var pool = null;
pool = new Pool({
host: 'localhost',
user: 'postgres',
password: 'admin',
database: 'exemplo',
port: '5432'
});
// Routes
const { Router } = require('express');
const routes = Router();
routes.get('/pessoas', async function(req, res) {
const response = await pool.query("select * from pessoas where disciplina = 'Matemática'");
res.status(200).json({response: response.rows});
},);
app.use(routes);
let port = process.env.PORT;
if (port == null || port == "") {
port = 3000;
}
app.listen(port);
PROBLEM
When executing, "SELECT * FROM people WHERE discipline = 'Mathematics', this appears:
That is, no problem so far worked perfectly. HOWEVER, when opening the route "/people" (Node code above):
no results are returned. But if I choose, for example, "Geography" instead of "Mathematics", that by chance the only difference is acute accent:
routes.get('/pessoas', async function(req, res) {
const response = await pool.query("SELECT * FROM pessoas WHERE disciplina = 'Geografia'");
res.status(200).json({response: response.rows});
},);
END
Please, if you can handle this, help me. I’ve looked for answers in places and tried several things (I changed the CLIENT_ENCODING, I changed the Ctype, I even touched the Collate, etc.). I believe it’s some silly detail I’m not aware of.
True, using queries without parameterizing the values is risky, but this example above is just a simplification of the actual design, in it I took this precaution. My problem has already been solved, I did not understand what happened, but when I deployed to the server the accents worked.
– Felipe Uchoa
Just locally it wasn’t working, but I’m still not sure I’ll perform some tests.
– Felipe Uchoa