Reputation: 377
I'm trying to fetch data from an existing postgres db which has a couple of tables in it. While the connection to the database is carried out successfully, I cannot seem to carry out any test queries for example
Model.findAll().then(table =>{ console.log(table)}
I have tried appending the Schema Name to the model definition like
const Model = sequelize.define('Schema.ABC', { ....}}
which throws the same error as the title suggests
I have also tried appending the Schema name to the query but it throws a syntax error and the code doesn't execute
Model.findAll().then('Schema.ABC' => { console.log(Schema.ABC)}
If the table does need to have Schema name appended to it, then I would also like to know how to achieve it.
Below is a fragment of my code
const Model = sequelize.define('ABC',{
CompanyName: Sequelize.STRING,
createdAt: Sequelize.DATE,
updatedAt: Sequelize.DATE
},
{
// tableName: `"Schema"."ABC"`,
freezeTableName: true
});
...
Model.removeAttribute('id');
Model.findAll().then(ABC => {
console.log(ABC)
})
Upvotes: 2
Views: 3054
Reputation: 803
You should define your schema like this, leaving the tableName
property uncommented:
const ABC = sequelize.define('ABC',{
CompanyName: Sequelize.STRING,
createdAt: Sequelize.DATE,
updatedAt: Sequelize.DATE
},
{
freezeTableName: true,
tableName: 'ABC',
});
And use this, inside of an asynchronous function:
async function findAllABC() {
await ABC.findAll().then((result) => {
console.log(`The result is: '${result}'`);
});
}
findAllABC();
Upvotes: 0