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

db.schema returns undefined #1045

Closed
TusharWatts opened this issue Jun 19, 2024 · 4 comments
Closed

db.schema returns undefined #1045

TusharWatts opened this issue Jun 19, 2024 · 4 comments
Labels
duplicate This issue or pull request already exists invalid This doesn't seem right mysql Related to MySQL

Comments

@TusharWatts
Copy link

On initialization, db.schema returns undefined
Here is my code:

Database.ts

import { Database } from './types'; // this is the Database interface we defined earlier
import { createPool } from 'mysql'; // do not use 'mysql2/promises'!
import { Kysely, MysqlDialect } from 'kysely';

const dialect = new MysqlDialect({
  pool: createPool({
        database: 'my_db',
        host: '127.0.0.1',
        user: 'username',
        password: 'password',
        port: 3308,
        connectionLimit: 10
  })
});


export const db = new Kysely<Database>({
    dialect
});

On checking, db.schema gives me undefined
I'm using mysql as the dialect
And using the following versions for mysql and kysely:
"kysely": "^0.27.3",
"mysql": "^2.18.1"

@igalklebanov
Copy link
Member

Hey 👋

You're not supposed to use mysql2/promises, but mysql2.

@igalklebanov igalklebanov added duplicate This issue or pull request already exists invalid This doesn't seem right mysql Related to MySQL labels Jun 19, 2024
@TusharWatts
Copy link
Author

@igalklebanov , its the same issue with mysql2

I'm using
"mysql2": "^3.10.1"

database.ts file:-

import { Database } from './types'; // this is the Database interface we defined earlier
import { createPool } from 'mysql2'; // do not use 'mysql2/promises'!
import { Kysely, MysqlDialect } from 'kysely';

const dialect = new MysqlDialect({
  pool: createPool({
        database: 'my_db',
        host: '127.0.0.1',
        user: 'username',
        password: 'password',
        port: 3308,
        connectionLimit: 10
  })
});


export const db = new Kysely<Database>({
    dialect
});

@igalklebanov
Copy link
Member

How are you "checking, db.schema"?

@TusharWatts
Copy link
Author

Got it, the issue has been resolved. It was stupid issue from my end. I was importing the db from the database file as default import, hence it was not working. My bad!

Thanks anyway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists invalid This doesn't seem right mysql Related to MySQL
Projects
None yet
Development

No branches or pull requests

2 participants