Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query always returns undefined. #354

Open
FinlayDaG33k opened this issue Jul 24, 2022 · 3 comments
Open

Query always returns undefined. #354

FinlayDaG33k opened this issue Jul 24, 2022 · 3 comments

Comments

@FinlayDaG33k
Copy link

Hii there,

When I try to run a query in my app, the ORM always returns a value of undefined, despite the entry existing in my database.
This is my Model:

import { Model, DataTypes } from "../../deps.ts";

export class GuildMember extends Model {
  static table = 'guild-members';

  static fields = {
    id: { primaryKey: true, autoIncrement: true },
    did: DataTypes.STRING,
    messages: DataTypes.BIG_INTEGER,
    last_seen: DataTypes.BIG_INTEGER,
  };

  static defaults = {
    messages: 0,
    last_seen: 0
  };
}

And the code I try to execute for the query:

const entry = await GuildMember.where('did', '=', author.id.toString()).first();
console.log(entry); // always returns "undefined"
if(!entry) {
  await GuildMember.create({
    did: author.id.toString(),
    messages: author.count,
    last_seen: author.last_seen,
  });
  return;
}

In the first pass, it creates the row just fine, however, in the second pass, it just tries to insert it again.
Am I doing something wrong or is this a bug?

@FinlayDaG33k
Copy link
Author

Tried using a "raw" query:

SELECT messages FROM guild_members WHERE did='91616138860978176';

This returns a big error, even though the query runs just fine in PhpMyAdmin.
Could this be the cause of this bug?

error: Uncaught (in promise) Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'function knex(tableName, options) {
    return createQueryBuilder(knex.contex...' at line 1
      throw new Error(error.message);
            ^
    at PoolConnection.nextPacket (https://deno.land/x/mysql@v2.10.2/src/connection.ts:185:13)
    at async PoolConnection.execute (https://deno.land/x/mysql@v2.10.2/src/connection.ts:268:21)
    at async https://deno.land/x/mysql@v2.10.2/src/client.ts:97:14
    at async Client.useConnection (https://deno.land/x/mysql@v2.10.2/src/client.ts:107:14)
    at async Client.execute (https://deno.land/x/mysql@v2.10.2/src/client.ts:96:12)
    at async MySQLConnector.query (https://raw.githubusercontent.com/joeldesante/denodb/master/lib/connectors/mysql-connector.ts:80:22)
    at async Database.query (https://raw.githubusercontent.com/joeldesante/denodb/master/lib/database.ts:240:21)
    at async file:///F:/repos/FinlayDaG33k/yukikaze/src/util/scan-messages.ts:195:2

@FinlayDaG33k
Copy link
Author

Appears this may be the same issue as #107.

@FinlayDaG33k
Copy link
Author

Tested with the SQLite3Connector as well, same problems arise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant