examples icon indicating copy to clipboard operation
examples copied to clipboard

Mysql2 type error when trying to query connection

Open Puetz opened this issue 1 year ago • 1 comments

Hi,

I want to use the mysql2 npm package with Deno 2.

I installed the package using the npm prefix and am able to import it just fine. When I try to run any query on my database connection I'm getting a typescript error "Property 'query' does not exist on type 'Connection'".

I looked at the example in this repo as well as the official mysql2 documentation and I can't figure out what I'm doing wrong.

deno.json

{
    "name": "@scope/deno-backend",
    "version": "0.1.0",
    "exports": "./main.ts",
    "tasks": {
        "dev": "deno run --watch main.ts"
    },
    "imports": {
        "mysql2": "npm:mysql2@^3.11.3"
    }
}

main.ts

import mysql from "mysql2/promise";

const connection = await mysql.createConnection({
    host: "localhost",
    user: "user",
    password: "password",
    database: "react19_db",
});

const results = await connection.query("SELECT * FROM `test`");

If I did something wrong during my setup, then I'm really sorry. It's my first time using Deno 2.

Cheers, Thomas

Puetz avatar Oct 18 '24 19:10 Puetz

Having the same issue. I believe it's because of version:

import mysql from "npm:mysql2@^2.3.3/promise";

Can the example use a newer version of mysql2 package? Version 2.3.3 is more than 5 years old.

acrodrig avatar Oct 25 '24 22:10 acrodrig