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

Mysql2 getProperties error #11

Open
kkn1125 opened this issue Jul 14, 2023 · 0 comments
Open

Mysql2 getProperties error #11

kkn1125 opened this issue Jul 14, 2023 · 0 comments

Comments

@kkn1125
Copy link

kkn1125 commented Jul 14, 2023

hello. While using the library, I felt uncomfortable and entered an issue.

The situation is as follows.

  • node 18.11.0
  • adminjs 7.0.9
  • @adminjs/sql 2.1.0
  • DB: mariadb
  • connect type: mysql2

This is the code I set up.

const PORT = 3000;

const start = async () => {
  const db = await new Adapter("mysql2", {
    user: "user",
    password: "my_db_password",
    host: "my_db_host",
    port: <my_db_port>,
    database: "db_name",
  }).init();

  AdminJS.registerAdapter({ Database, Resource });

  const app = Fastify();
  const admin = new AdminJS({
    resources: [
      {
        resource: db.table("user"),
        options: {},
      },
    ],

    rootPath: "/admin",
  });

  await AdminJSFastify.buildRouter(admin, app);

  app.listen({ port: PORT }, (err, addr) => {
    if (err) {
      console.error(err);
    } else {
      console.log(
        `AdminJS started on http://localhost:${PORT}${admin.options.rootPath}`
      );
    }
  });
};

start();

But here an error occurred. The error contents are as follows.

TypeError: Cannot read properties of undefined (reading 'toLowerCase')
    at getColumnInfo (file:///C:/kkn_folder/project/uglymews/node_modules/@adminjs/sql/lib/dialects/mysql.parser.j
s:5:35)
    at file:///C:/kkn_folder/project/uglymews/node_modules/@adminjs/sql/lib/dialects/mysql.parser.js:141:50
    at Array.map (<anonymous>)
    at MysqlParser.getProperties (file:///C:/kkn_folder/project/uglymews/node_modules/@adminjs/sql/lib/dialects/my
sql.parser.js:141:24)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///C:/kkn_folder/project/uglymews/node_modules/@adminjs/sql/lib/dialects/mysql.parser.js:117:138
    at async Promise.all (index 1)
    at async MysqlParser.getResources (file:///C:/kkn_folder/project/uglymews/node_modules/@adminjs/sql/lib/dialec
ts/mysql.parser.js:115:27)
    at async MysqlParser.parse (file:///C:/kkn_folder/project/uglymews/node_modules/@adminjs/sql/lib/dialects/mysq
l.parser.js:88:27)
    at async start (file:///C:/kkn_folder/project/uglymews/admin/admin.js:9:14)
file:///C:/kkn_folder/project/uglymews/node_modules/@adminjs/sql/lib/metadata/DatabaseMetadata.js:14
            throw new Error(`Table does not exist: "${this.database}.${tableName}"`);
                  ^

Error: Table does not exist: "my_db.user"
    at DatabaseMetadata.table (file:///C:/kkn_folder/project/uglymews/node_modules/@adminjs/sql/lib/metadata/Datab
aseMetadata.js:14:19)

I saw here why "toLowerCase" doesn't work. This happened because the field name of the variable obtained from "knex" is lowercase.

image image

So, I am currently using it only for the project I am using after partially modifying it.
The modified part is the part changed to "col.UPPERCASE" in the right image above. After making the changes, it worked fine.

I specified and used "mysql2" as the db type, but the actual DB being used is "MariaDB". If "mariadb" is not compatible, I think this part needs to be resolved.

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