drizzle-team / drizzle-team/drizzle-orm
[BUG]: drizzle execute is not behaving as expected
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### What version of `drizzle-orm` are you using?
0.26.2
### What version of `drizzle-kit` are you using?
0.18.1
### Describe the Bug
The types returned by the execute node-mysql2 and execute of drizzle seems to be different. See below.
node-mysql2 driver
```ts
import mysql from 'mysql2';
export type DbDefaults =
| RowDataPacket[]
| RowDataPacket[][]
| OkPacket[]
| OkPacket;
export type DbQueryResult = TData & DbDefaults;
export interface User {
email: string;
}
const config = {
host: env.DB_HOST,
port: env.DB_PORT,
database: env.DB_NAME,
user: env.DB_UID,
password: env.DB_PID,
multipleStatements: true,
};
const migrationClient = mysql.createConnection(config);
const queryClient = mysql.createPool({
...config,
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0,
enableKeepAlive: true,
keepAliveInitialDelay: 0,
});
const rows = await qclient.promise().execute('SELECT * FROM users'); // type of rows is "any"
const [rows] = await qclient.promise().execute('SELECT * FROM users'); // type of rows is "mysql.ResultSetHeader | mysql.RowDataPacket[] | mysql.RowDataPacket[][] | mysql.OkPacket | mysql.OkPacket[]"
const [rows] = await qclient.promise().execute>('SELECT * FROM users'); // type of rows is "DbQueryResult"
rows[0].email
```
vs drizzle
```ts
import mysql from 'mysql2';
import { sql } from 'drizzle-orm';
import { drizzle } from 'drizzle-orm/mysql2';
export type DbDefaults =
| RowDataPacket[]
| RowDataPacket[][]
| OkPacket[]
| OkPacket;
export type DbQueryResult = TData & DbDefaults;
export interface User {
email: string;
}
const config = {
host: env.DB_HOST,
port: env.DB_PORT,
database: env.DB_NAME,
user: env.DB_UID,
password: env.DB_PID,
multipleStatements: true,
};
const migrationClient = mysql.createConnection(config);
const queryClient = mysql.createPool({
...config,
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0,
enableKeepAlive: true,
keepAliveInitialDelay: 0,
});
const mconn = drizzle(migrationClient)
const qconn = drizzle(queryClient)
const rows = await qconn.execute(sql`SELECT * FROM users`); // type of rows is "MySqlRawQueryResult"
const [rows] = await qconn.execute('SELECT * FROM users'); // type of rows is "mysql.ResultSetHeader"
const [rows] = await qconn.execute>('SELECT * FROM users'); // type of rows is "mysql.ResultSetHeader". No change in type. Unable to type as in when using the node-mysql2 driver
rows[0].email // cannot do this since unable to type the above
```
### Expected behavior
I had expected to be able to type the return of execute in drizzle as in the native driver
### Environment & setup
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.