eveningkid / denodb

MySQL, SQLite, MariaDB, PostgreSQL and MongoDB ORM for Deno

Home Page:https://eveningkid.com/denodb-docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Query always returns `undefined`.

FinlayDaG33k opened this issue · comments

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?

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

Appears this may be the same issue as #107.

Tested with the SQLite3Connector as well, same problems arise.