Skip to content

Commit 236899b

Browse files
committed
up
1 parent ed09476 commit 236899b

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/DataAPI/DataBase.d.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ declare class DBSession {
107107
* @param sql 要准备的SQL语句
108108
* @returns DBStmt 预准备语句,失败抛出错误
109109
*/
110-
prepare(sql: string): DBStmt
110+
prepare<T extends Record<string, any>>(sql: string): DBStmt<T>
111111
}
112112

113113
/** SQL预准备语句 */
114-
declare class DBStmt {
114+
declare class DBStmt<T extends Record<string, any> = any> {
115115
/**
116116
* 获取该预准备语句执行后影响的行数 (仅对 `INSERT` `UPDATE` `DELETE` `REPLACE` 等语句生效)
117117
*/
@@ -127,35 +127,35 @@ declare class DBStmt {
127127
* @param val 要绑定的值
128128
* @tips 本重载将会将值绑定到第一个未绑定的参数上
129129
*/
130-
bind(val: any): void
130+
bind(val: T[keyof T]): void
131131

132132
/**
133133
* 绑定参数到一个SQL语句
134134
* @param val 要绑定的值
135135
* @tips 要绑定的对象,等同于遍历此对象并执行
136136
* @tips 对于Object:bind(val, key) 对于Array:bind(val)
137137
*/
138-
bind(val: any | any[]): void
138+
bind(val: T | T[keyof T][]): void
139139

140140
/**
141141
* 绑定参数到一个SQL语句
142142
* @param val 要绑定的值
143143
* @param index 要绑定到的参数索引(从`0`开始)
144144
*/
145-
bind(val: any, index: number): void
145+
bind(val: T[keyof T], index: number): void
146146

147147
/**
148148
* 绑定参数到一个SQL语句
149149
* @param val 要绑定的值
150150
* @param name 要绑定到的参数的参数名
151151
*/
152-
bind(val: any, name: string): void
152+
bind(val: T[keyof T], name: string): void
153153

154154
/**
155155
* 执行SQL但不获取结果
156156
* @returns DBSession 处理完毕的会话对象(便于连锁进行其他操作)
157157
*/
158-
execute(): DBStmt
158+
execute(): this
159159

160160
/**
161161
* 步进到下一行结果
@@ -173,32 +173,32 @@ declare class DBStmt {
173173
* 获取当前结果行
174174
* @returns Object 当前结果行,形如`{col1: "value", col2: 2333}`
175175
*/
176-
fetch(): { [key: string]: any }
176+
fetch(): T
177177

178178
/**
179179
* 获取所有结果行
180180
* @returns Array<Array>
181181
* @tips 返回数组的第1行(`result[0]`)为结果集的表头(列名),剩余行为结果数据
182182
*/
183-
fetchAll(): any[][]
183+
fetchAll(): [[keyof T], ...T[keyof T]]
184184

185185
/**
186186
* 重置当前语句状态至“待执行”
187187
* @returns DBStmt 处理完毕的语句对象(便于连锁进行其他操作)
188188
* @tips 本函数不会清除已绑定的参数
189189
*/
190-
reset(): DBStmt
190+
reset(): this
191191

192192
/**
193193
* 重新执行预准备语句
194194
* @returns DBStmt 处理完毕的语句对象(便于连锁进行其他操作)
195195
* @tips 本函数是一个便捷函数,等同于执行`stmt.reset()`和`stmt.execute()`
196196
*/
197-
reexec(): DBStmt
197+
reexec(): this
198198

199199
/**
200200
* 清除所有已绑定的参数
201201
* @returns DBStmt 处理完毕的语句对象(便于连锁进行其他操作)
202202
*/
203-
clear(): DBStmt
203+
clear(): this
204204
}

0 commit comments

Comments
 (0)