Skip to content

Commit e33d6bd

Browse files
committed
DataBase sync docs and source code
changde DataBase_Params add execute to DBStmt
1 parent ce65643 commit e33d6bd

File tree

1 file changed

+41
-38
lines changed

1 file changed

+41
-38
lines changed

src/DataAPI/DataBase.d.ts

+41-38
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
/** 创建 / 打开一个键值对数据库 */
2-
declare class KVDatabase{
3-
constructor(dir:string);
2+
declare class KVDatabase {
3+
constructor(dir: string);
44

55
/** 数据库的储存目录路径,以BDS根目录为基准 */
6-
dir: string
6+
dir: string;
77

88
/**
99
* 写入数据项
1010
* @param name 数据项名字
1111
* @param data 要写入的数据
1212
* @returns boolean 是否写入成功
1313
*/
14-
set(name:string,data:any): boolean;
14+
set(name: string, data: any): boolean;
1515

1616
/**
1717
* 读取数据项
1818
* @param name 数据项名字
1919
* @returns any|null 数据库中储存的这个项的数据
2020
*/
21-
get(name:string): any|null;
21+
get(name: string): any | null;
2222

2323
/**
2424
* 删除数据项
2525
* @param name 数据库名字
2626
*/
27-
delete(name:string): boolean;
27+
delete(name: string): boolean;
2828

2929
/**
3030
* 获取所有数据项名字
@@ -39,153 +39,156 @@ declare class KVDatabase{
3939
close(): boolean;
4040
}
4141

42-
declare class DataBase_Params{
42+
declare class DataBase_Params {
4343
/** 指定数据库所在路径 */
44-
path:string;
44+
path: string;
4545

46-
/** 数据库不存在是否自动创建 */
47-
create:boolean;
46+
/** 数据库不存在是否自动创建(默认true) */
47+
create?: boolean;
4848

49-
/** 以只读模式打开 */
50-
readonly:boolean;
49+
/** 以只读模式打开(默认false) */
50+
readonly?: boolean;
5151

52-
/** 以读写模式打开 */
53-
readwrite:boolean;
52+
/** 以读写模式打开(默认true) */
53+
readwrite?: boolean;
5454
}
5555

5656
/** 打开一个SQL数据库会话 */
57-
declare class DBSession{
57+
declare class DBSession {
5858
/**
5959
* 打开一个SQL数据库会话
6060
* @param type 数据库的类型,目前仅支持
6161
* @param params DataBase_Params 连接参数
6262
*/
63-
constructor(type:"sqlite3",params:DataBase_Params);
63+
constructor(type: "sqlite3", params: DataBase_Params);
6464

6565
/**
6666
* 打开一个SQL数据库会话
6767
* @param str 形如file:///mydb.db?k=v, mysql://root:password@localhost:3306/db的连接字符串
6868
*/
69-
constructor(str:string);
69+
constructor(str: string);
7070

7171
/**
7272
* 执行SQL并获取结果集
7373
* @param sql 要查询的SQL语句
7474
* @returns Array<Array> 查询的结果(结果集)
7575
* @tips 返回数组的第1行(`result[0]`)为结果集的表头(列名),剩余行为结果数据
7676
*/
77-
query(sql:string):Array<Array<any>>
77+
query(sql: string): Array<Array<any>>;
7878

7979
/**
8080
* 执行SQL但不获取结果
8181
* @param sql 要执行的SQL语句
8282
* @returns DBSession 处理完毕的会话对象(便于连锁进行其他操作)
8383
*/
84-
exec(sql:string):DBSession;
84+
exec(sql: string): DBSession;
8585

8686
/**
8787
* 执行SQL但不获取结果
8888
* @param sql 要执行的SQL语句
8989
* @returns DBSession 处理完毕的会话对象(便于连锁进行其他操作)
9090
*/
91-
execute(sql:string):DBSession;
91+
execute(sql: string): DBSession;
9292

9393
/**
9494
* 获取当前会话是否为打开状态
9595
* @returns boolean 是否为打开状态
9696
*/
97-
isOpen():boolean;
97+
isOpen(): boolean;
9898

9999
/**
100100
* 关闭数据库会话
101101
* @returns boolean 是否成功关闭
102102
*/
103-
close():boolean;
103+
close(): boolean;
104104

105105
/**
106106
* 准备一个预准备语句
107107
* @param sql 要准备的SQL语句
108108
* @returns DBStmt 预准备语句,失败抛出错误
109109
*/
110-
prepare(sql:string):DBStmt
110+
prepare(sql: string): DBStmt;
111111
}
112112

113-
114-
115113
/** SQL预准备语句 */
116-
declare class DBStmt{
114+
declare class DBStmt {
117115
/**
118116
* 绑定参数到一个SQL语句
119117
* @param val 要绑定的值
120118
* @tips 本重载将会将值绑定到第一个未绑定的参数上
121119
*/
122-
bind(val:any): void;
120+
bind(val: any): void;
123121

124122
/**
125123
* 绑定参数到一个SQL语句
126124
* @param val 要绑定的值
127125
* @tips 要绑定的对象,等同于遍历此对象并执行
128126
* @tips 对于Object:bind(val, key) 对于Array:bind(val)
129127
*/
130-
bind(val:any|Array<any>): void;
128+
bind(val: any | Array<any>): void;
131129

132130
/**
133131
* 绑定参数到一个SQL语句
134132
* @param val 要绑定的值
135133
* @param index 要绑定到的参数索引(从`0`开始)
136134
*/
137-
bind(val:any,index:number): void;
135+
bind(val: any, index: number): void;
138136

139137
/**
140138
* 绑定参数到一个SQL语句
141139
* @param val 要绑定的值
142140
* @param name 要绑定到的参数的参数名
143141
*/
144-
bind(val:any,name:string): void;
142+
bind(val: any, name: string): void;
143+
144+
/**
145+
* 执行SQL但不获取结果
146+
* @returns DBSession 处理完毕的会话对象(便于连锁进行其他操作)
147+
*/
148+
execute(): DBStmt;
145149

146150
/**
147151
* 步进到下一行结果
148152
* @returns boolean 执行成功与否
149153
*/
150-
step():boolean;
154+
step(): boolean;
151155

152156
/**
153157
* 步进到下一行结果
154158
* @returns boolean 执行成功与否
155159
*/
156-
next():boolean;
160+
next(): boolean;
157161

158162
/**
159163
* 获取当前结果行
160164
* @returns Object 当前结果行,形如`{col1: "value", col2: 2333}`
161165
*/
162-
fetch(): {[key:string]:any};
166+
fetch(): { [key: string]: any };
163167

164168
/**
165169
* 获取所有结果行
166170
* @returns Array<Array>
167171
* @tips 返回数组的第1行(`result[0]`)为结果集的表头(列名),剩余行为结果数据
168172
*/
169-
fetchAll(): Array<Array<any>>
173+
fetchAll(): Array<Array<any>>;
170174

171175
/**
172176
* 重置当前语句状态至“待执行”
173177
* @returns DBStmt 处理完毕的语句对象(便于连锁进行其他操作)
174178
* @tips 本函数不会清除已绑定的参数
175179
*/
176-
reset():DBStmt;
180+
reset(): DBStmt;
177181

178182
/**
179183
* 重新执行预准备语句
180184
* @returns DBStmt 处理完毕的语句对象(便于连锁进行其他操作)
181185
* @tips 本函数是一个便捷函数,等同于执行`stmt.reset()`和`stmt.execute()`
182186
*/
183-
reexec():DBStmt;
187+
reexec(): DBStmt;
184188

185189
/**
186190
* 清除所有已绑定的参数
187191
* @returns DBStmt 处理完毕的语句对象(便于连锁进行其他操作)
188192
*/
189-
clear():DBStmt;
193+
clear(): DBStmt;
190194
}
191-

0 commit comments

Comments
 (0)