@@ -107,11 +107,11 @@ declare class DBSession {
107
107
* @param sql 要准备的SQL语句
108
108
* @returns DBStmt 预准备语句,失败抛出错误
109
109
*/
110
- prepare ( sql : string ) : DBStmt
110
+ prepare < T extends Record < string , any > > ( sql : string ) : DBStmt < T >
111
111
}
112
112
113
113
/** SQL预准备语句 */
114
- declare class DBStmt {
114
+ declare class DBStmt < T extends Record < string , any > = any > {
115
115
/**
116
116
* 获取该预准备语句执行后影响的行数 (仅对 `INSERT` `UPDATE` `DELETE` `REPLACE` 等语句生效)
117
117
*/
@@ -127,35 +127,35 @@ declare class DBStmt {
127
127
* @param val 要绑定的值
128
128
* @tips 本重载将会将值绑定到第一个未绑定的参数上
129
129
*/
130
- bind ( val : any ) : void
130
+ bind ( val : T [ keyof T ] ) : void
131
131
132
132
/**
133
133
* 绑定参数到一个SQL语句
134
134
* @param val 要绑定的值
135
135
* @tips 要绑定的对象,等同于遍历此对象并执行
136
136
* @tips 对于Object:bind(val, key) 对于Array:bind(val)
137
137
*/
138
- bind ( val : any | any [ ] ) : void
138
+ bind ( val : T | T [ keyof T ] [ ] ) : void
139
139
140
140
/**
141
141
* 绑定参数到一个SQL语句
142
142
* @param val 要绑定的值
143
143
* @param index 要绑定到的参数索引(从`0`开始)
144
144
*/
145
- bind ( val : any , index : number ) : void
145
+ bind ( val : T [ keyof T ] , index : number ) : void
146
146
147
147
/**
148
148
* 绑定参数到一个SQL语句
149
149
* @param val 要绑定的值
150
150
* @param name 要绑定到的参数的参数名
151
151
*/
152
- bind ( val : any , name : string ) : void
152
+ bind ( val : T [ keyof T ] , name : string ) : void
153
153
154
154
/**
155
155
* 执行SQL但不获取结果
156
156
* @returns DBSession 处理完毕的会话对象(便于连锁进行其他操作)
157
157
*/
158
- execute ( ) : DBStmt
158
+ execute ( ) : this
159
159
160
160
/**
161
161
* 步进到下一行结果
@@ -173,32 +173,32 @@ declare class DBStmt {
173
173
* 获取当前结果行
174
174
* @returns Object 当前结果行,形如`{col1: "value", col2: 2333}`
175
175
*/
176
- fetch ( ) : { [ key : string ] : any }
176
+ fetch ( ) : T
177
177
178
178
/**
179
179
* 获取所有结果行
180
180
* @returns Array<Array>
181
181
* @tips 返回数组的第1行(`result[0]`)为结果集的表头(列名),剩余行为结果数据
182
182
*/
183
- fetchAll ( ) : any [ ] [ ]
183
+ fetchAll ( ) : [ [ keyof T ] , ... T [ keyof T ] ]
184
184
185
185
/**
186
186
* 重置当前语句状态至“待执行”
187
187
* @returns DBStmt 处理完毕的语句对象(便于连锁进行其他操作)
188
188
* @tips 本函数不会清除已绑定的参数
189
189
*/
190
- reset ( ) : DBStmt
190
+ reset ( ) : this
191
191
192
192
/**
193
193
* 重新执行预准备语句
194
194
* @returns DBStmt 处理完毕的语句对象(便于连锁进行其他操作)
195
195
* @tips 本函数是一个便捷函数,等同于执行`stmt.reset()`和`stmt.execute()`
196
196
*/
197
- reexec ( ) : DBStmt
197
+ reexec ( ) : this
198
198
199
199
/**
200
200
* 清除所有已绑定的参数
201
201
* @returns DBStmt 处理完毕的语句对象(便于连锁进行其他操作)
202
202
*/
203
- clear ( ) : DBStmt
203
+ clear ( ) : this
204
204
}
0 commit comments