title: MySQL with Typescript doesn't store multiple data - discord.js
body: <ul>
  <li><strong>Query</strong></li>
  </ul>
  <p>I'm working on a messages tracking discord bot using <strong>typescript</strong> with <strong>discord.js</strong>. I've provided my code below. The issue here, is that it doesn't save the data. When a user sends messages, it stores his message count, but when another user sends messages in the same channel, the database stores his messages, and makes the first user's count as <code>0</code>.</p>
  <ul>
  <li><strong>Code</strong></li>
  </ul>
  <pre><code>// user-Schema.ts
  import type { SapphireClient } from '@sapphire/framework';
  import type { ModelStatic, Model } from 'sequelize';
  import Sequelize from 'sequelize';
  
  interface UserAttributes {
      guild: string;
      user: string;
      msgs: number;
  }
  
  interface UserInstance extends Model&lt;UserAttributes, UserAttributes&gt;, UserAttributes {}
  
  export class UserModel {
      client: SapphireClient;
      raw!: ModelStatic&lt;UserInstance&gt;;
  
      constructor(client: SapphireClient) {
          this.client = client;
      }
  
      async init() {
          const db = this.client.sql.define&lt;UserInstance&gt;('electra.users', {
              guild: {
                  type: Sequelize.STRING,
                  primaryKey: true,
                  unique: true
              },
              user: {
                  type: Sequelize.STRING,
                  primaryKey: true
              },
              msgs: {
                  type: Sequelize.INTEGER
              }
          });
          this.raw = db;
          await this.raw.sync();
          this.client.logger.info(`Synced UserModel`);
      }
  }
  </code></pre>
  <pre><code>// messageCreate.ts
  const data = await this.container.client.userDB.raw.findOne({
              where: {
                  guild: msg.guildId,
                  user: msg.author.id
              }
          });
  
  const msgs = data === null ? 0 : data.msgs;
  
  await this.container.client.userDB.raw.upsert({
      guild: msg.guildId as string,
      user: msg.author.id,
      msgs: msgs + 1
  });
  </code></pre>
  <pre><code>// index.ts
  import { UserModel } from './models/user-Schema';
  const sequelize = new sql.Sequelize(process.env.DB_NAME!, process.env.DB_USER!, process.env.DB_PASS!, {
      logging: false,
      dialect: 'mysql'
  });
  
  client.sql = sequelize;
  client.userDB = new UserModel(client);
  </code></pre>
  <pre><code>// ready.ts
  await this.container.client.userDB.init()
  </code></pre>
  <ul>
  <li><strong>Info</strong></li>
  </ul>
  <p>I'm using <a href="https://github.com/sapphiredev/framework" rel="nofollow noreferrer">@sapphire/framework</a> as my bot's framework. I'd be happy for any sort of help, and I'm ready to provide more information if asked.</p>
  <p>Thanks.</p>