#How to get a value assosiated with the primary key (sqlite database)
18 messages · Page 1 of 1 (latest)
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
✅Marked as resolved by OP
How to get a value assosiated with the primary key (sqlite database)
SELECT ownerId FROM <your_table> WHERE channelId = ?
ok, thanks. ill try it
also should have said this is in js
🤦
That query will work cross language - just pass channelId as a query param
const ownerId = await voiceChannels.findOne({ where: { channelId: interaction.channelId } });
this is what i have as the line for getting the value tho so
This doesn't look like SQlite? More like MongoDB
it gets from an sqlite db
channelId: {
type: Sequelize.TEXT,
primaryKey: true
},
ownerId: {
type: Sequelize.TEXT,
unique: true
}
});```
thats the model file
and then this is the database.js
const sequelize = new Sequelize('database', 'user', 'password', {
host: 'localhost',
dialect: 'sqlite',
logging: false,
storage: 'database.sqlite'
});
module.exports = sequelize;```
its a multi file one
Got you, so your query would like something lol
const channel = await voiceChannels.findOne({ where: { channelId: interaction.channelId } });
console.log(channel.ownerId)
oh so it quite literally is just a .[name]