kysely-org / kysely

A type-safe typescript SQL query builder
https://kysely.dev
MIT License
10.44k stars 267 forks source link

db.schema returns undefined #1045

Closed TusharWatts closed 3 months ago

TusharWatts commented 3 months ago

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 commented 3 months ago

Hey 👋

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

TusharWatts commented 3 months ago

@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 commented 3 months ago

How are you "checking, db.schema"?

TusharWatts commented 3 months ago

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