Skip to content

Commit be1ff2c

Browse files
committed
refactor(mysql-connector): Enhance type safety for raw statements
Introduce a `RawStatement` interface to explicitly define the expected methods on the underlying database driver's statement object. This improves type safety and clarity within the `BoundableStatement` wrapper. Also, make the `dialect` property's type a literal `'mysql'` to provide more precise type information.
1 parent 4740eca commit be1ff2c

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/runtime/server/utils/mysql-connector.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@ interface ConnectorOptions extends PoolOptions {
88
database?: string
99
}
1010

11+
interface RawStatement {
12+
all(...args: unknown[]): Promise<unknown[]>
13+
run(...args: unknown[]): Promise<{ success: boolean }>
14+
get(...args: unknown[]): Promise<unknown>
15+
}
16+
1117
class BoundableStatement {
12-
_statement: BoundableStatement | null
18+
_statement: RawStatement | null
1319

14-
constructor(rawStmt: BoundableStatement | null) {
20+
constructor(rawStmt: RawStatement | null) {
1521
this._statement = rawStmt
1622
}
1723

@@ -105,7 +111,7 @@ export default function mysqlPoolConnector(opts: ConnectorOptions) {
105111

106112
return {
107113
name: 'mysql',
108-
dialect: 'mysql',
114+
dialect: 'mysql' as const,
109115
getInstance: getPool,
110116
exec: (sql: string) => query(sql),
111117
prepare: (sql: string) => new StatementWrapper(sql, query),

0 commit comments

Comments
 (0)