sdk.go 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. package v1
  2. import (
  3. "fmt"
  4. "git.sxidc.com/service-supports/dps-sdk"
  5. "git.sxidc.com/service-supports/dps-sdk/client"
  6. "github.com/stretchr/testify/assert"
  7. "testing"
  8. )
  9. var clientInstance client.Client
  10. func initClient(t *testing.T, address string, databaseID string) {
  11. c, err := dps.NewClient(address, "v1", databaseID)
  12. if err != nil {
  13. t.Fatal(err)
  14. }
  15. clientInstance = c
  16. }
  17. func destroyClient(t *testing.T, databaseID string) {
  18. err := dps.DestroyClient("v1", databaseID)
  19. if err != nil {
  20. t.Fatal(err)
  21. }
  22. clientInstance = nil
  23. }
  24. type ToolKit struct {
  25. t *testing.T
  26. }
  27. func newToolKit(t *testing.T) *ToolKit {
  28. return &ToolKit{t: t}
  29. }
  30. func (toolKit *ToolKit) autoMigrate(req *client.AutoMigrateRequest) *ToolKit {
  31. err := clientInstance.AutoMigrate(req)
  32. if err != nil {
  33. toolKit.t.Fatal(err)
  34. }
  35. return toolKit
  36. }
  37. func (toolKit *ToolKit) transaction(txFunc client.TransactionFunc) *ToolKit {
  38. err := clientInstance.Transaction(txFunc)
  39. if err != nil {
  40. toolKit.t.Fatal(err)
  41. }
  42. return toolKit
  43. }
  44. func (toolKit *ToolKit) insert(req *client.InsertRequest) *ToolKit {
  45. statement, err := clientInstance.Insert(req)
  46. if err != nil {
  47. toolKit.t.Fatal(err)
  48. }
  49. fmt.Println(statement)
  50. return toolKit
  51. }
  52. func (toolKit *ToolKit) insertBatch(req *client.InsertBatchRequest) *ToolKit {
  53. statement, err := clientInstance.InsertBatch(req)
  54. if err != nil {
  55. toolKit.t.Fatal(err)
  56. }
  57. fmt.Println(statement)
  58. return toolKit
  59. }
  60. func (toolKit *ToolKit) delete(req *client.DeleteRequest) *ToolKit {
  61. statement, err := clientInstance.Delete(req)
  62. if err != nil {
  63. toolKit.t.Fatal(err)
  64. }
  65. fmt.Println(statement)
  66. return toolKit
  67. }
  68. func (toolKit *ToolKit) deleteBatch(req *client.DeleteBatchRequest) *ToolKit {
  69. statement, err := clientInstance.DeleteBatch(req)
  70. if err != nil {
  71. toolKit.t.Fatal(err)
  72. }
  73. fmt.Println(statement)
  74. return toolKit
  75. }
  76. func (toolKit *ToolKit) update(req *client.UpdateRequest) *ToolKit {
  77. statement, err := clientInstance.Update(req)
  78. if err != nil {
  79. toolKit.t.Fatal(err)
  80. }
  81. fmt.Println(statement)
  82. return toolKit
  83. }
  84. func (toolKit *ToolKit) reply(req *client.ReplayRequest) *ToolKit {
  85. statement, err := clientInstance.Replay(req)
  86. if err != nil {
  87. toolKit.t.Fatal(err)
  88. }
  89. fmt.Println(statement)
  90. return toolKit
  91. }
  92. func (toolKit *ToolKit) queryByWhereAndOrderBy(req *client.QueryByWhereAndOrderByRequest, retInfosMap *[]map[string]any, retTotalCount *int64) *ToolKit {
  93. statement, infosMap, totalCount, err := clientInstance.QueryByWhereAndOrderBy(req)
  94. if err != nil {
  95. toolKit.t.Fatal(err)
  96. }
  97. fmt.Println(statement)
  98. if retInfosMap != nil {
  99. *retInfosMap = make([]map[string]any, 0)
  100. *retInfosMap = infosMap
  101. }
  102. if retTotalCount != nil {
  103. *retTotalCount = totalCount
  104. }
  105. return toolKit
  106. }
  107. func (toolKit *ToolKit) commonQuery(req *client.CommonQueryRequest, retInfosMap *[]map[string]any, retTotalCount *int64) *ToolKit {
  108. statement, infosMap, totalCount, err := clientInstance.CommonQuery(req)
  109. if err != nil {
  110. toolKit.t.Fatal(err)
  111. }
  112. fmt.Println(statement)
  113. if retInfosMap != nil {
  114. *retInfosMap = make([]map[string]any, 0)
  115. *retInfosMap = infosMap
  116. }
  117. if retTotalCount != nil {
  118. *retTotalCount = totalCount
  119. }
  120. return toolKit
  121. }
  122. func (toolKit *ToolKit) queryOnlyByWhereAndOrderBy(req *client.QueryByWhereAndOrderByRequest, retInfosMap *[]map[string]any) *ToolKit {
  123. statement, infosMap, err := clientInstance.QueryOnlyByWhereAndOrderBy(req)
  124. if err != nil {
  125. toolKit.t.Fatal(err)
  126. }
  127. fmt.Println(statement)
  128. if retInfosMap != nil {
  129. *retInfosMap = make([]map[string]any, 0)
  130. *retInfosMap = infosMap
  131. }
  132. return toolKit
  133. }
  134. func (toolKit *ToolKit) commonQueryOnly(req *client.CommonQueryRequest, retInfosMap *[]map[string]any) *ToolKit {
  135. statement, infosMap, err := clientInstance.CommonQueryOnly(req)
  136. if err != nil {
  137. toolKit.t.Fatal(err)
  138. }
  139. fmt.Println(statement)
  140. if retInfosMap != nil {
  141. *retInfosMap = make([]map[string]any, 0)
  142. *retInfosMap = infosMap
  143. }
  144. return toolKit
  145. }
  146. func (toolKit *ToolKit) queryByKeys(req *client.QueryByKeysRequest, retInfoMap *map[string]any) *ToolKit {
  147. statement, infoMap, err := clientInstance.QueryByKeys(req)
  148. if err != nil {
  149. toolKit.t.Fatal(err)
  150. }
  151. fmt.Println(statement)
  152. if retInfoMap != nil {
  153. *retInfoMap = make(map[string]any)
  154. *retInfoMap = infoMap
  155. }
  156. return toolKit
  157. }
  158. func (toolKit *ToolKit) countWhere(req *client.CountWhereRequest, retCount *int64) *ToolKit {
  159. statement, count, err := clientInstance.CountWhere(req)
  160. if err != nil {
  161. toolKit.t.Fatal(err)
  162. }
  163. fmt.Println(statement)
  164. if retCount != nil {
  165. *retCount = count
  166. }
  167. return toolKit
  168. }
  169. func (toolKit *ToolKit) commonCount(req *client.CommonCountRequest, retCount *int64) *ToolKit {
  170. statement, count, err := clientInstance.CommonCount(req)
  171. if err != nil {
  172. toolKit.t.Fatal(err)
  173. }
  174. fmt.Println(statement)
  175. if retCount != nil {
  176. *retCount = count
  177. }
  178. return toolKit
  179. }
  180. func (toolKit *ToolKit) eventQueryByKeys(req *client.EventQueryByKeysRequest, retInfos *[]client.EventInfo, retTotalCount *int64) *ToolKit {
  181. statement, infos, totalCount, err := clientInstance.EventQueryByKeys(req)
  182. if err != nil {
  183. toolKit.t.Fatal(err)
  184. }
  185. fmt.Println(statement)
  186. if retInfos != nil {
  187. *retInfos = make([]client.EventInfo, 0)
  188. *retInfos = infos
  189. }
  190. if retTotalCount != nil {
  191. *retTotalCount = totalCount
  192. }
  193. return toolKit
  194. }
  195. func (toolKit *ToolKit) commonEventQuery(req *client.CommonEventQueryRequest, retInfos *[]client.EventInfo, retTotalCount *int64) *ToolKit {
  196. statement, infos, totalCount, err := clientInstance.CommonEventQuery(req)
  197. if err != nil {
  198. toolKit.t.Fatal(err)
  199. }
  200. fmt.Println(statement)
  201. if retInfos != nil {
  202. *retInfos = make([]client.EventInfo, 0)
  203. *retInfos = infos
  204. }
  205. if retTotalCount != nil {
  206. *retTotalCount = totalCount
  207. }
  208. return toolKit
  209. }
  210. func (toolKit *ToolKit) eventQueryOnlyByKeys(req *client.EventQueryByKeysRequest, retInfos *[]client.EventInfo) *ToolKit {
  211. statement, infos, err := clientInstance.EventQueryOnlyByKeys(req)
  212. if err != nil {
  213. toolKit.t.Fatal(err)
  214. }
  215. fmt.Println(statement)
  216. if retInfos != nil {
  217. *retInfos = make([]client.EventInfo, 0)
  218. *retInfos = infos
  219. }
  220. return toolKit
  221. }
  222. func (toolKit *ToolKit) commonEventQueryOnly(req *client.CommonEventQueryRequest, retInfos *[]client.EventInfo) *ToolKit {
  223. statement, infos, err := clientInstance.CommonEventQueryOnly(req)
  224. if err != nil {
  225. toolKit.t.Fatal(err)
  226. }
  227. fmt.Println(statement)
  228. if retInfos != nil {
  229. *retInfos = make([]client.EventInfo, 0)
  230. *retInfos = infos
  231. }
  232. return toolKit
  233. }
  234. func (toolKit *ToolKit) countEventByKeys(req *client.CountEventByKeysRequest, retCount *int64) *ToolKit {
  235. statement, count, err := clientInstance.CountEventByKeys(req)
  236. if err != nil {
  237. toolKit.t.Fatal(err)
  238. }
  239. fmt.Println(statement)
  240. if retCount != nil {
  241. *retCount = count
  242. }
  243. return toolKit
  244. }
  245. func (toolKit *ToolKit) commonCountEvent(req *client.CommonCountEventRequest, retCount *int64) *ToolKit {
  246. statement, count, err := clientInstance.CommonCountEvent(req)
  247. if err != nil {
  248. toolKit.t.Fatal(err)
  249. }
  250. fmt.Println(statement)
  251. if retCount != nil {
  252. *retCount = count
  253. }
  254. return toolKit
  255. }
  256. func (toolKit *ToolKit) eventHistoryQueryByKeys(req *client.EventQueryByKeysRequest, retInfos *[]client.EventInfo, retTotalCount *int64) *ToolKit {
  257. statement, infos, totalCount, err := clientInstance.EventHistoryQueryByKeys(req)
  258. if err != nil {
  259. toolKit.t.Fatal(err)
  260. }
  261. fmt.Println(statement)
  262. if retInfos != nil {
  263. *retInfos = make([]client.EventInfo, 0)
  264. *retInfos = infos
  265. }
  266. if retTotalCount != nil {
  267. *retTotalCount = totalCount
  268. }
  269. return toolKit
  270. }
  271. func (toolKit *ToolKit) commonEventHistoryQuery(req *client.CommonEventQueryRequest, retInfos *[]client.EventInfo, retTotalCount *int64) *ToolKit {
  272. statement, infos, totalCount, err := clientInstance.CommonEventHistoryQuery(req)
  273. if err != nil {
  274. toolKit.t.Fatal(err)
  275. }
  276. fmt.Println(statement)
  277. if retInfos != nil {
  278. *retInfos = make([]client.EventInfo, 0)
  279. *retInfos = infos
  280. }
  281. if retTotalCount != nil {
  282. *retTotalCount = totalCount
  283. }
  284. return toolKit
  285. }
  286. func (toolKit *ToolKit) eventHistoryQueryOnlyByKeys(req *client.EventQueryByKeysRequest, retInfos *[]client.EventInfo) *ToolKit {
  287. statement, infos, err := clientInstance.EventHistoryQueryOnlyByKeys(req)
  288. if err != nil {
  289. toolKit.t.Fatal(err)
  290. }
  291. fmt.Println(statement)
  292. if retInfos != nil {
  293. *retInfos = make([]client.EventInfo, 0)
  294. *retInfos = infos
  295. }
  296. return toolKit
  297. }
  298. func (toolKit *ToolKit) commonEventHistoryQueryOnly(req *client.CommonEventQueryRequest, retInfos *[]client.EventInfo) *ToolKit {
  299. statement, infos, err := clientInstance.CommonEventHistoryQueryOnly(req)
  300. if err != nil {
  301. toolKit.t.Fatal(err)
  302. }
  303. fmt.Println(statement)
  304. if retInfos != nil {
  305. *retInfos = make([]client.EventInfo, 0)
  306. *retInfos = infos
  307. }
  308. return toolKit
  309. }
  310. func (toolKit *ToolKit) countEventHistoryByKeys(req *client.CountEventByKeysRequest, retCount *int64) *ToolKit {
  311. statement, count, err := clientInstance.CountEventHistoryByKeys(req)
  312. if err != nil {
  313. toolKit.t.Fatal(err)
  314. }
  315. fmt.Println(statement)
  316. if retCount != nil {
  317. *retCount = count
  318. }
  319. return toolKit
  320. }
  321. func (toolKit *ToolKit) commonCountEventHistory(req *client.CommonCountEventRequest, retCount *int64) *ToolKit {
  322. statement, count, err := clientInstance.CommonCountEventHistory(req)
  323. if err != nil {
  324. toolKit.t.Fatal(err)
  325. }
  326. fmt.Println(statement)
  327. if retCount != nil {
  328. *retCount = count
  329. }
  330. return toolKit
  331. }
  332. func (toolKit *ToolKit) assertEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) *ToolKit {
  333. assert.Equal(toolKit.t, expected, actual, msgAndArgs)
  334. return toolKit
  335. }
  336. func (toolKit *ToolKit) assertNotEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) *ToolKit {
  337. assert.NotEqual(toolKit.t, expected, actual, msgAndArgs)
  338. return toolKit
  339. }
  340. func (toolKit *ToolKit) assertNotEmpty(object interface{}, msgAndArgs ...interface{}) *ToolKit {
  341. assert.NotEmpty(toolKit.t, object, msgAndArgs)
  342. return toolKit
  343. }