#How to get a value assosiated with the primary key (sqlite database)

18 messages · Page 1 of 1 (latest)

muted jay
#

i have a database which has chanelId as primary key and ownerId as unique i already know how to get the channel id but how do i get that chhanel id and then get the ownerId assosiated with that channelId?

cosmic thunderBOT
#
  • 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
muted jay
#

How to get a value assosiated with the primary key (sqlite database)

stoic vector
muted jay
#

ok, thanks. ill try it

#

also should have said this is in js

#

🤦

stoic vector
#

That query will work cross language - just pass channelId as a query param

muted jay
#

const ownerId = await voiceChannels.findOne({ where: { channelId: interaction.channelId } });
this is what i have as the line for getting the value tho so

stoic vector
muted jay
#

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

stoic vector
#

Got you, so your query would like something lol

const channel = await voiceChannels.findOne({ where: { channelId: interaction.channelId } });

console.log(channel.ownerId)
muted jay
#

oh so it quite literally is just a .[name]