I'm trying to use Knexjs to handle my database in my application, but I'm not having as much success. He is not able to find the tables to make the inserts with the request and in fact the tables in pgadmin, are very strange ... has anyone been there?
knexfile.js
module.exports = {
development: {
client: 'pg',
connection: {
host : '127.0.0.1',
user : 'postgres',
password : 'admin123',
database : 'covid',
charset: 'utf8'
},
migrations: {
directory: './src/database/migrations',
},
seeds: {
directory: './src/database/seeds'
}
}};
create_casos.js (migrate)
exports.up = function(knex) {
knex.schema.createTable('casos', function(table){
table.string('titulo').notNullable()
table.string('email').notNullable()
})
};
exports.down = function(knex) {
knex.schema.dropTable('casos')
};
CasosController.js
module.exports = {
async create( request, response ){
try {
const { titulo, email } = request.body;
await connection('casos').insert({ titulo, email })
response.send(request.body)
} catch (err) {
return response.status(400).send(err)
}
}}

Aucun commentaire:
Enregistrer un commentaire