interface.uts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /**
  2. * 初始化数据库时的相关配置
  3. * @param name 数据库名称
  4. */
  5. export type createSQLiteContextOptions = {
  6. /**
  7. * 数据库名称
  8. */
  9. name: string,
  10. }
  11. /**
  12. * 执行增删改等操作的SQL语句的相关配置
  13. * @param sql SQL语句
  14. * @param success 成功回调
  15. * @param fail 失败回调
  16. * @param complete 完成回调
  17. */
  18. export type executeSqlOptions = {
  19. /**
  20. * SQL语句
  21. */
  22. sql: string,
  23. /**
  24. * 执行增删改等操作的SQL语句的成功回调
  25. */
  26. success?: executeSqlOptionsSuccessCallback | null,
  27. /**
  28. * 执行增删改等操作的SQL语句的失败回调
  29. */
  30. fail?: executeSqlOptionsFailCallback | null,
  31. /**
  32. * 执行增删改等操作的SQL语句的完成回调
  33. */
  34. complete?: executeSqlOptionsCompleteCallback | null,
  35. }
  36. /**
  37. * 执行增删改等操作的SQL语句的成功回调
  38. */
  39. export type executeSqlOptionsSuccessCallback = (res: executeSqlOptionsResult) => void
  40. /**
  41. * 执行增删改等操作的SQL语句的失败回调
  42. */
  43. export type executeSqlOptionsFailCallback = (res: executeSqlOptionsResult) => void
  44. /**
  45. * 执行增删改等操作的SQL语句的完成回调
  46. */
  47. export type executeSqlOptionsCompleteCallback = (res: executeSqlOptionsResult) => void
  48. /**
  49. * 执行增删改等操作的SQL语句的返回结果
  50. * @param errMsg 返回的错误信息
  51. * @param date 返回的数据
  52. */
  53. export interface executeSqlOptionsResultInterface extends ICreateSQLiteContextError {
  54. /**
  55. * 返回的错误信息
  56. */
  57. errMsg: string,
  58. /**
  59. * 返回的数据
  60. */
  61. date?: boolean[],
  62. }
  63. export type executeSqlOptionsResult = executeSqlOptionsResultInterface
  64. /**
  65. * 执行查询操作的SQL语句的相关配置
  66. */
  67. export type selectSqlOptions = {
  68. /**
  69. * SQL语句
  70. */
  71. sql: string,
  72. /**
  73. * 执行查询操作的SQL语句的成功回调
  74. */
  75. success?: selectSqlOptionsSuccessCallback | null,
  76. /**
  77. * 执行查询操作的SQL语句的失败回调
  78. */
  79. fail?: selectSqlOptionsFailCallback | null,
  80. /**
  81. * 执行查询操作的SQL语句的完成回调
  82. */
  83. complete?: selectSqlOptionsCompleteCallback | null,
  84. }
  85. /**
  86. * 执行查询操作的SQL语句的成功回调
  87. */
  88. export type selectSqlOptionsSuccessCallback = (res: selectSqlOptionsResult) => void
  89. /**
  90. * 执行查询操作的SQL语句的失败回调
  91. */
  92. export type selectSqlOptionsFailCallback = (res: selectSqlOptionsResult) => void
  93. /**
  94. * 执行查询操作的SQL语句的完成回调
  95. */
  96. export type selectSqlOptionsCompleteCallback = (res: selectSqlOptionsResult) => void
  97. /**
  98. * 执行查询操作的SQL语句的返回结果
  99. * @param errMsg 返回的错误信息
  100. * @param date 返回的数据
  101. */
  102. export interface selectSqlOptionsResultInterface extends ICreateSQLiteContextError {
  103. /**
  104. * 返回的错误信息
  105. */
  106. errMsg: string,
  107. /**
  108. * 返回的数据
  109. */
  110. date?: string[],
  111. }
  112. export type selectSqlOptionsResult = selectSqlOptionsResultInterface
  113. /**
  114. * uni.createSQLiteContext失败回调参数
  115. */
  116. export interface ICreateSQLiteContextError extends IUniError {
  117. errCode: number
  118. }
  119. export type CreateSQLiteContext = (options: createSQLiteContextOptions) => CreateSQLiteContextCallBack
  120. export interface CreateSQLiteContextCallBack {
  121. /**
  122. * 执行增删改等操作的SQL语句
  123. */
  124. executeSql: (options: executeSqlOptions) => executeSqlOptionsCompleteCallback,
  125. /**
  126. * 执行查询操作的SQL语句
  127. */
  128. selectSql: (options: selectSqlOptions) => selectSqlOptionsCompleteCallback,
  129. /**
  130. * 关闭数据库
  131. */
  132. close: () => void,
  133. /**
  134. * 开启事务
  135. */
  136. transaction: (options: transactionOptions) => transactionCompleteCallback,
  137. }
  138. export type transactionOptions = {
  139. /**
  140. * 事务执行的操作
  141. */
  142. operation: transactionOperation,
  143. /**
  144. * 事务执行的成功回调
  145. */
  146. success?: transactionSuccessCallback | null,
  147. /**
  148. * 事务执行的失败回调
  149. */
  150. fail?: transactionFailCallback | null,
  151. /**
  152. * 事务执行的完成回调
  153. */
  154. complete?: transactionCompleteCallback | null,
  155. }
  156. /**
  157. * 事务操作类型
  158. * @param begin 开始事务
  159. * @param commit 提交事务
  160. * @param rollback 回滚事务
  161. */
  162. export type transactionOperation = 'begin' | 'commit' | 'rollback'
  163. /**
  164. * 事务执行的成功回调
  165. */
  166. export type transactionSuccessCallback = (res: transactionResult) => void
  167. /**
  168. * 事务执行的失败回调
  169. */
  170. export type transactionFailCallback = (res: transactionResult) => void
  171. /**
  172. * 事务执行的完成回调
  173. */
  174. export type transactionCompleteCallback = (res: transactionResult) => void
  175. /**
  176. * 事务执行的返回结果
  177. */
  178. export interface transactionResultInterface extends ICreateSQLiteContextError {
  179. /**
  180. * 返回的错误信息
  181. */
  182. errMsg: string,
  183. }
  184. export type transactionResult = transactionResultInterface