client.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  1. package dpsv1
  2. import (
  3. "context"
  4. "encoding/json"
  5. "errors"
  6. "git.sxidc.com/service-supports/dps-sdk/client"
  7. "git.sxidc.com/service-supports/dps-sdk/pb/v1"
  8. "git.sxidc.com/service-supports/dps-sdk/pb/v1/request"
  9. "google.golang.org/grpc"
  10. "google.golang.org/grpc/credentials/insecure"
  11. "io"
  12. "sync"
  13. )
  14. type Client struct {
  15. databaseID string
  16. conn *grpc.ClientConn
  17. commandServiceClient v1.CommandServiceClient
  18. queryServiceClient v1.QueryServiceClient
  19. eventQueryServiceClient v1.EventQueryServiceClient
  20. transactionMutex sync.Mutex
  21. }
  22. func NewClient(address string, databaseID string) (*Client, error) {
  23. conn, err := grpc.DialContext(context.Background(), address,
  24. grpc.WithTransportCredentials(insecure.NewCredentials()))
  25. if err != nil {
  26. return nil, err
  27. }
  28. return &Client{
  29. databaseID: databaseID,
  30. conn: conn,
  31. commandServiceClient: v1.NewCommandServiceClient(conn),
  32. queryServiceClient: v1.NewQueryServiceClient(conn),
  33. eventQueryServiceClient: v1.NewEventQueryServiceClient(conn),
  34. }, nil
  35. }
  36. func DestroyClient(client *Client) error {
  37. if client == nil {
  38. return nil
  39. }
  40. client.transactionMutex.Lock()
  41. defer client.transactionMutex.Unlock()
  42. err := client.conn.Close()
  43. if err != nil {
  44. return err
  45. }
  46. client.databaseID = ""
  47. client.conn = nil
  48. client.commandServiceClient = nil
  49. client.queryServiceClient = nil
  50. return nil
  51. }
  52. func (c *Client) AutoMigrate(req *client.AutoMigrateRequest) error {
  53. items := make([]*request.AutoMigrateItem, 0)
  54. for _, reqItem := range req.Items {
  55. tableModelDescribeJsonBytes, err := json.Marshal(reqItem.TableModelDescribe)
  56. if err != nil {
  57. return err
  58. }
  59. items = append(items, &request.AutoMigrateItem{
  60. TablePrefixWithSchema: reqItem.TablePrefixWithSchema,
  61. Version: reqItem.Version,
  62. TableModelDescribe: tableModelDescribeJsonBytes,
  63. NoEvent: reqItem.NoEvent,
  64. })
  65. }
  66. _, err := c.commandServiceClient.AutoMigrate(context.Background(), &request.AutoMigrateRequest{
  67. DatabaseID: c.databaseID,
  68. Items: items,
  69. })
  70. if err != nil {
  71. return err
  72. }
  73. return nil
  74. }
  75. func (c *Client) Transaction(txFunc client.TransactionFunc) error {
  76. stream, err := c.commandServiceClient.Transaction(context.Background())
  77. if err != nil {
  78. return err
  79. }
  80. defer func() {
  81. innerErr := stream.CloseSend()
  82. if innerErr != nil {
  83. panic(innerErr)
  84. }
  85. }()
  86. err = stream.Send(&request.TransactionOperation{
  87. Request: &request.TransactionOperation_TransactionBeginRequest{
  88. TransactionBeginRequest: &request.TransactionBeginRequest{DatabaseID: c.databaseID},
  89. }})
  90. if err != nil {
  91. return err
  92. }
  93. err = txFunc(&Transaction{
  94. stream: stream,
  95. client: c,
  96. })
  97. if err != nil {
  98. return err
  99. }
  100. err = stream.Send(&request.TransactionOperation{
  101. Request: &request.TransactionOperation_TransactionEndRequest{
  102. TransactionEndRequest: &request.TransactionEndRequest{},
  103. }})
  104. if err != nil {
  105. return err
  106. }
  107. _, err = stream.Recv()
  108. if err != nil && err != io.EOF {
  109. return err
  110. }
  111. return nil
  112. }
  113. func (c *Client) Insert(req *client.InsertRequest) (string, error) {
  114. if req.TableRow == nil {
  115. return "", nil
  116. }
  117. tableRow, err := req.TableRow.ToDPSTableRow()
  118. if err != nil {
  119. return "", err
  120. }
  121. reply, err := c.commandServiceClient.Insert(context.Background(), &request.InsertRequest{
  122. DatabaseID: c.databaseID,
  123. TablePrefixWithSchema: req.TablePrefixWithSchema,
  124. Version: req.Version,
  125. KeyColumns: req.KeyColumns,
  126. TableRow: tableRow,
  127. UserID: req.UserID,
  128. })
  129. if err != nil {
  130. return "", err
  131. }
  132. return reply.Statement, nil
  133. }
  134. func (c *Client) InsertBatch(req *client.InsertBatchRequest) (string, error) {
  135. tableRowItems := make([]*request.InsertTableRowItem, 0)
  136. for _, reqTableItem := range req.Items {
  137. tableRows := make([]*request.TableRow, 0)
  138. for _, reqTableRow := range reqTableItem.TableRows {
  139. if reqTableRow == nil {
  140. continue
  141. }
  142. tableRow, err := reqTableRow.ToDPSTableRow()
  143. if err != nil {
  144. return "", err
  145. }
  146. tableRows = append(tableRows, tableRow)
  147. }
  148. tableRowItems = append(tableRowItems, &request.InsertTableRowItem{
  149. TablePrefixWithSchema: reqTableItem.TablePrefixWithSchema,
  150. Version: reqTableItem.Version,
  151. KeyColumns: reqTableItem.KeyColumns,
  152. TableRows: tableRows,
  153. })
  154. }
  155. reply, err := c.commandServiceClient.InsertBatch(context.Background(), &request.InsertBatchRequest{
  156. DatabaseID: c.databaseID,
  157. Items: tableRowItems,
  158. UserID: req.UserID,
  159. })
  160. if err != nil {
  161. return "", err
  162. }
  163. return reply.Statement, nil
  164. }
  165. func (c *Client) Delete(req *client.DeleteRequest) (string, error) {
  166. reply, err := c.commandServiceClient.Delete(context.Background(), &request.DeleteRequest{
  167. DatabaseID: c.databaseID,
  168. TablePrefixWithSchema: req.TablePrefixWithSchema,
  169. Version: req.Version,
  170. KeyColumns: req.KeyValues.Columns(),
  171. KeyValues: req.KeyValues.Values(),
  172. UserID: req.UserID,
  173. })
  174. if err != nil {
  175. return "", err
  176. }
  177. return reply.Statement, nil
  178. }
  179. func (c *Client) DeleteWhere(req *client.DeleteWhereRequest) (string, error) {
  180. if req.Where == nil {
  181. return "", errors.New("没有传递Where条件")
  182. }
  183. whereJsonBytes, err := req.Where.ToJson()
  184. if err != nil {
  185. return "", err
  186. }
  187. reply, err := c.commandServiceClient.DeleteWhere(context.Background(), &request.DeleteWhereRequest{
  188. DatabaseID: c.databaseID,
  189. TablePrefixWithSchema: req.TablePrefixWithSchema,
  190. Version: req.Version,
  191. KeyColumns: req.KeyColumns,
  192. Where: whereJsonBytes,
  193. UserID: req.UserID,
  194. })
  195. if err != nil {
  196. return "", err
  197. }
  198. return reply.Statement, nil
  199. }
  200. func (c *Client) Update(req *client.UpdateRequest) (string, error) {
  201. if req.NewTableRow == nil {
  202. return "", nil
  203. }
  204. newTableRow, err := req.NewTableRow.ToDPSTableRow()
  205. if err != nil {
  206. return "", err
  207. }
  208. reply, err := c.commandServiceClient.Update(context.Background(), &request.UpdateRequest{
  209. DatabaseID: c.databaseID,
  210. TablePrefixWithSchema: req.TablePrefixWithSchema,
  211. Version: req.Version,
  212. KeyColumns: req.KeyValues.Columns(),
  213. KeyValues: req.KeyValues.Values(),
  214. NewTableRow: newTableRow,
  215. UserID: req.UserID,
  216. })
  217. if err != nil {
  218. return "", err
  219. }
  220. return reply.Statement, nil
  221. }
  222. func (c *Client) UpdateWhere(req *client.UpdateWhereRequest) (string, error) {
  223. if req.Where == nil {
  224. return "", errors.New("没有传递Where条件")
  225. }
  226. if req.NewTableRow == nil {
  227. return "", nil
  228. }
  229. whereJsonBytes, err := req.Where.ToJson()
  230. if err != nil {
  231. return "", err
  232. }
  233. newTableRow, err := req.NewTableRow.ToDPSTableRow()
  234. if err != nil {
  235. return "", err
  236. }
  237. reply, err := c.commandServiceClient.UpdateWhere(context.Background(), &request.UpdateWhereRequest{
  238. DatabaseID: c.databaseID,
  239. TablePrefixWithSchema: req.TablePrefixWithSchema,
  240. Version: req.Version,
  241. KeyColumns: req.KeyColumns,
  242. Where: whereJsonBytes,
  243. NewTableRow: newTableRow,
  244. UserID: req.UserID,
  245. })
  246. if err != nil {
  247. return "", err
  248. }
  249. return reply.Statement, nil
  250. }
  251. func (c *Client) Replay(req *client.ReplayRequest) (string, error) {
  252. reply, err := c.commandServiceClient.Replay(context.Background(), &request.ReplayRequest{
  253. DatabaseID: c.databaseID,
  254. TablePrefixWithSchema: req.TablePrefixWithSchema,
  255. Version: req.Version,
  256. KeyColumns: req.KeyValues.Columns(),
  257. KeyValues: req.KeyValues.Values(),
  258. UserID: req.UserID,
  259. })
  260. if err != nil {
  261. return "", err
  262. }
  263. return reply.Statement, nil
  264. }
  265. func (c *Client) QueryByWhereAndOrderBy(req *client.QueryByWhereAndOrderByRequest) (string, []client.TableRow, int64, error) {
  266. var selectJsonBytes []byte
  267. if req.Select != nil {
  268. innerJsonBytes, err := req.Select.ToJson()
  269. if err != nil {
  270. return "", nil, 0, err
  271. }
  272. selectJsonBytes = innerJsonBytes
  273. }
  274. var whereJsonBytes []byte
  275. if req.Where != nil {
  276. innerJsonBytes, err := req.Where.ToJson()
  277. if err != nil {
  278. return "", nil, 0, err
  279. }
  280. whereJsonBytes = innerJsonBytes
  281. }
  282. reply, err := c.queryServiceClient.QueryByWhereAndOrderBy(context.Background(), &request.QueryByWhereAndOrderByRequest{
  283. DatabaseID: c.databaseID,
  284. TablePrefixWithSchema: req.TablePrefixWithSchema,
  285. Table: req.Table,
  286. Version: req.Version,
  287. Select: selectJsonBytes,
  288. Where: whereJsonBytes,
  289. OrderBy: req.OrderBy,
  290. PageNo: int32(req.PageNo),
  291. PageSize: int32(req.PageSize),
  292. })
  293. if err != nil {
  294. return "", nil, 0, err
  295. }
  296. tableRows, err := client.FromDSPInfosData(reply.Infos)
  297. if err != nil {
  298. return "", nil, 0, err
  299. }
  300. return reply.Statement, tableRows, reply.TotalCount, nil
  301. }
  302. func (c *Client) CommonQuery(req *client.CommonQueryRequest) (string, []client.TableRow, int64, error) {
  303. var selectJsonBytes []byte
  304. if req.Select != nil {
  305. innerJsonBytes, err := req.Select.ToJson()
  306. if err != nil {
  307. return "", nil, 0, err
  308. }
  309. selectJsonBytes = innerJsonBytes
  310. }
  311. var whereJsonBytes []byte
  312. if req.Where != nil {
  313. innerJsonBytes, err := req.Where.ToJson()
  314. if err != nil {
  315. return "", nil, 0, err
  316. }
  317. whereJsonBytes = innerJsonBytes
  318. }
  319. var orJsonBytes []byte
  320. if req.Or != nil {
  321. innerJsonBytes, err := req.Or.ToJson()
  322. if err != nil {
  323. return "", nil, 0, err
  324. }
  325. orJsonBytes = innerJsonBytes
  326. }
  327. var joinsJsonBytes []byte
  328. if req.Joins != nil {
  329. innerJsonBytes, err := req.Joins.ToJson()
  330. if err != nil {
  331. return "", nil, 0, err
  332. }
  333. joinsJsonBytes = innerJsonBytes
  334. }
  335. var havingJsonBytes []byte
  336. if req.Having != nil {
  337. innerJsonBytes, err := req.Having.ToJson()
  338. if err != nil {
  339. return "", nil, 0, err
  340. }
  341. havingJsonBytes = innerJsonBytes
  342. }
  343. reply, err := c.queryServiceClient.CommonQuery(context.Background(), &request.CommonQueryRequest{
  344. DatabaseID: c.databaseID,
  345. TablePrefixWithSchema: req.TablePrefixWithSchema,
  346. Table: req.Table,
  347. Version: req.Version,
  348. Select: selectJsonBytes,
  349. Where: whereJsonBytes,
  350. OrderBy: req.OrderBy,
  351. Or: orJsonBytes,
  352. GroupBy: req.GroupBy,
  353. Joins: joinsJsonBytes,
  354. Having: havingJsonBytes,
  355. PageNo: int32(req.PageNo),
  356. PageSize: int32(req.PageSize),
  357. })
  358. if err != nil {
  359. return "", nil, 0, err
  360. }
  361. tableRows, err := client.FromDSPInfosData(reply.Infos)
  362. if err != nil {
  363. return "", nil, 0, err
  364. }
  365. return reply.Statement, tableRows, reply.TotalCount, nil
  366. }
  367. func (c *Client) QueryOnlyByWhereAndOrderBy(req *client.QueryByWhereAndOrderByRequest) (string, []client.TableRow, error) {
  368. var selectJsonBytes []byte
  369. if req.Select != nil {
  370. innerJsonBytes, err := req.Select.ToJson()
  371. if err != nil {
  372. return "", nil, err
  373. }
  374. selectJsonBytes = innerJsonBytes
  375. }
  376. var whereJsonBytes []byte
  377. if req.Where != nil {
  378. innerJsonBytes, err := req.Where.ToJson()
  379. if err != nil {
  380. return "", nil, err
  381. }
  382. whereJsonBytes = innerJsonBytes
  383. }
  384. reply, err := c.queryServiceClient.QueryOnlyByWhereAndOrderBy(context.Background(), &request.QueryByWhereAndOrderByRequest{
  385. DatabaseID: c.databaseID,
  386. TablePrefixWithSchema: req.TablePrefixWithSchema,
  387. Table: req.Table,
  388. Version: req.Version,
  389. Select: selectJsonBytes,
  390. Where: whereJsonBytes,
  391. OrderBy: req.OrderBy,
  392. PageNo: int32(req.PageNo),
  393. PageSize: int32(req.PageSize),
  394. })
  395. if err != nil {
  396. return "", nil, err
  397. }
  398. tableRows, err := client.FromDSPInfosData(reply.Infos)
  399. if err != nil {
  400. return "", nil, err
  401. }
  402. return reply.Statement, tableRows, nil
  403. }
  404. func (c *Client) CommonQueryOnly(req *client.CommonQueryRequest) (string, []client.TableRow, error) {
  405. var selectJsonBytes []byte
  406. if req.Select != nil {
  407. innerJsonBytes, err := req.Select.ToJson()
  408. if err != nil {
  409. return "", nil, err
  410. }
  411. selectJsonBytes = innerJsonBytes
  412. }
  413. var whereJsonBytes []byte
  414. if req.Where != nil {
  415. innerJsonBytes, err := req.Where.ToJson()
  416. if err != nil {
  417. return "", nil, err
  418. }
  419. whereJsonBytes = innerJsonBytes
  420. }
  421. var orJsonBytes []byte
  422. if req.Or != nil {
  423. innerJsonBytes, err := req.Or.ToJson()
  424. if err != nil {
  425. return "", nil, err
  426. }
  427. orJsonBytes = innerJsonBytes
  428. }
  429. var joinsJsonBytes []byte
  430. if req.Joins != nil {
  431. innerJsonBytes, err := req.Joins.ToJson()
  432. if err != nil {
  433. return "", nil, err
  434. }
  435. joinsJsonBytes = innerJsonBytes
  436. }
  437. var havingJsonBytes []byte
  438. if req.Having != nil {
  439. innerJsonBytes, err := req.Having.ToJson()
  440. if err != nil {
  441. return "", nil, err
  442. }
  443. havingJsonBytes = innerJsonBytes
  444. }
  445. reply, err := c.queryServiceClient.CommonQueryOnly(context.Background(), &request.CommonQueryRequest{
  446. DatabaseID: c.databaseID,
  447. TablePrefixWithSchema: req.TablePrefixWithSchema,
  448. Table: req.Table,
  449. Version: req.Version,
  450. Select: selectJsonBytes,
  451. Where: whereJsonBytes,
  452. OrderBy: req.OrderBy,
  453. Or: orJsonBytes,
  454. GroupBy: req.GroupBy,
  455. Joins: joinsJsonBytes,
  456. Having: havingJsonBytes,
  457. PageNo: int32(req.PageNo),
  458. PageSize: int32(req.PageSize),
  459. })
  460. if err != nil {
  461. return "", nil, err
  462. }
  463. tableRows, err := client.FromDSPInfosData(reply.Infos)
  464. if err != nil {
  465. return "", nil, err
  466. }
  467. return reply.Statement, tableRows, nil
  468. }
  469. func (c *Client) QueryByKeys(req *client.QueryByKeysRequest) (string, *client.TableRow, error) {
  470. var selectJsonBytes []byte
  471. if req.Select != nil {
  472. innerJsonBytes, err := req.Select.ToJson()
  473. if err != nil {
  474. return "", nil, err
  475. }
  476. selectJsonBytes = innerJsonBytes
  477. }
  478. reply, err := c.queryServiceClient.QueryByKeys(context.Background(), &request.QueryByKeysRequest{
  479. DatabaseID: c.databaseID,
  480. TablePrefixWithSchema: req.TablePrefixWithSchema,
  481. Version: req.Version,
  482. Select: selectJsonBytes,
  483. KeyColumns: req.KeyValues.Columns(),
  484. KeyValues: req.KeyValues.Values(),
  485. })
  486. if err != nil {
  487. return "", nil, err
  488. }
  489. tableRow := client.NewTableRow()
  490. err = tableRow.FromDSPInfoData(reply.Info)
  491. if err != nil {
  492. return "", nil, err
  493. }
  494. return reply.Statement, tableRow, nil
  495. }
  496. func (c *Client) CountWhere(req *client.CountWhereRequest) (string, int64, error) {
  497. var whereJsonBytes []byte
  498. if req.Where != nil {
  499. innerJsonBytes, err := req.Where.ToJson()
  500. if err != nil {
  501. return "", 0, err
  502. }
  503. whereJsonBytes = innerJsonBytes
  504. }
  505. reply, err := c.queryServiceClient.CountWhere(context.Background(), &request.CountWhereRequest{
  506. DatabaseID: c.databaseID,
  507. TablePrefixWithSchema: req.TablePrefixWithSchema,
  508. Table: req.Table,
  509. Version: req.Version,
  510. Where: whereJsonBytes,
  511. })
  512. if err != nil {
  513. return "", 0, err
  514. }
  515. return reply.Statement, reply.Count, nil
  516. }
  517. func (c *Client) CommonCount(req *client.CommonCountRequest) (string, int64, error) {
  518. var whereJsonBytes []byte
  519. if req.Where != nil {
  520. innerJsonBytes, err := req.Where.ToJson()
  521. if err != nil {
  522. return "", 0, err
  523. }
  524. whereJsonBytes = innerJsonBytes
  525. }
  526. var orJsonBytes []byte
  527. if req.Or != nil {
  528. innerJsonBytes, err := req.Or.ToJson()
  529. if err != nil {
  530. return "", 0, err
  531. }
  532. orJsonBytes = innerJsonBytes
  533. }
  534. var joinsJsonBytes []byte
  535. if req.Joins != nil {
  536. innerJsonBytes, err := req.Joins.ToJson()
  537. if err != nil {
  538. return "", 0, err
  539. }
  540. joinsJsonBytes = innerJsonBytes
  541. }
  542. var havingJsonBytes []byte
  543. if req.Having != nil {
  544. innerJsonBytes, err := req.Having.ToJson()
  545. if err != nil {
  546. return "", 0, err
  547. }
  548. havingJsonBytes = innerJsonBytes
  549. }
  550. reply, err := c.queryServiceClient.CommonCount(context.Background(), &request.CommonCountRequest{
  551. DatabaseID: c.databaseID,
  552. TablePrefixWithSchema: req.TablePrefixWithSchema,
  553. Table: req.Table,
  554. Version: req.Version,
  555. Where: whereJsonBytes,
  556. Or: orJsonBytes,
  557. GroupBy: req.GroupBy,
  558. Joins: joinsJsonBytes,
  559. Having: havingJsonBytes,
  560. })
  561. if err != nil {
  562. return "", 0, err
  563. }
  564. return reply.Statement, reply.Count, nil
  565. }
  566. func (c *Client) EventQueryByKeys(req *client.EventQueryByKeysRequest) (string, []client.EventInfo, int64, error) {
  567. var selectJsonBytes []byte
  568. if req.Select != nil {
  569. innerJsonBytes, err := req.Select.ToJson()
  570. if err != nil {
  571. return "", nil, 0, err
  572. }
  573. selectJsonBytes = innerJsonBytes
  574. }
  575. reply, err := c.eventQueryServiceClient.EventQueryByKeys(context.Background(), &request.EventQueryByKeysRequest{
  576. DatabaseID: c.databaseID,
  577. TablePrefixWithSchema: req.TablePrefixWithSchema,
  578. Select: selectJsonBytes,
  579. KeyValues: req.KeyValues,
  580. PageNo: int32(req.PageNo),
  581. PageSize: int32(req.PageSize),
  582. })
  583. if err != nil {
  584. return "", nil, 0, err
  585. }
  586. return reply.Statement, client.FormEventInfoBatch(reply.Infos), reply.TotalCount, nil
  587. }
  588. func (c *Client) CommonEventQuery(req *client.CommonEventQueryRequest) (string, []client.EventInfo, int64, error) {
  589. var selectJsonBytes []byte
  590. if req.Select != nil {
  591. innerJsonBytes, err := req.Select.ToJson()
  592. if err != nil {
  593. return "", nil, 0, err
  594. }
  595. selectJsonBytes = innerJsonBytes
  596. }
  597. reply, err := c.eventQueryServiceClient.CommonEventQuery(context.Background(), &request.CommonEventQueryRequest{
  598. DatabaseID: c.databaseID,
  599. TablePrefixWithSchema: req.TablePrefixWithSchema,
  600. Select: selectJsonBytes,
  601. KeyValues: req.KeyValues,
  602. Version: req.Version,
  603. Operation: req.Operation,
  604. CreatorID: req.CreatorID,
  605. StartCreatedTime: req.StartCreatedTime,
  606. EndCreatedTime: req.EndCreatedTime,
  607. PageNo: int32(req.PageNo),
  608. PageSize: int32(req.PageSize),
  609. })
  610. if err != nil {
  611. return "", nil, 0, err
  612. }
  613. return reply.Statement, client.FormEventInfoBatch(reply.Infos), reply.TotalCount, nil
  614. }
  615. func (c *Client) EventQueryOnlyByKeys(req *client.EventQueryByKeysRequest) (string, []client.EventInfo, error) {
  616. var selectJsonBytes []byte
  617. if req.Select != nil {
  618. innerJsonBytes, err := req.Select.ToJson()
  619. if err != nil {
  620. return "", nil, err
  621. }
  622. selectJsonBytes = innerJsonBytes
  623. }
  624. reply, err := c.eventQueryServiceClient.EventQueryOnlyByKeys(context.Background(), &request.EventQueryByKeysRequest{
  625. DatabaseID: c.databaseID,
  626. TablePrefixWithSchema: req.TablePrefixWithSchema,
  627. Select: selectJsonBytes,
  628. KeyValues: req.KeyValues,
  629. PageNo: int32(req.PageNo),
  630. PageSize: int32(req.PageSize),
  631. })
  632. if err != nil {
  633. return "", nil, err
  634. }
  635. return reply.Statement, client.FormEventInfoBatch(reply.Infos), nil
  636. }
  637. func (c *Client) CommonEventQueryOnly(req *client.CommonEventQueryRequest) (string, []client.EventInfo, error) {
  638. var selectJsonBytes []byte
  639. if req.Select != nil {
  640. innerJsonBytes, err := req.Select.ToJson()
  641. if err != nil {
  642. return "", nil, err
  643. }
  644. selectJsonBytes = innerJsonBytes
  645. }
  646. reply, err := c.eventQueryServiceClient.CommonEventQueryOnly(context.Background(), &request.CommonEventQueryRequest{
  647. DatabaseID: c.databaseID,
  648. TablePrefixWithSchema: req.TablePrefixWithSchema,
  649. Select: selectJsonBytes,
  650. KeyValues: req.KeyValues,
  651. Version: req.Version,
  652. Operation: req.Operation,
  653. CreatorID: req.CreatorID,
  654. StartCreatedTime: req.StartCreatedTime,
  655. EndCreatedTime: req.EndCreatedTime,
  656. PageNo: int32(req.PageNo),
  657. PageSize: int32(req.PageSize),
  658. })
  659. if err != nil {
  660. return "", nil, err
  661. }
  662. return reply.Statement, client.FormEventInfoBatch(reply.Infos), nil
  663. }
  664. func (c *Client) CountEventByKeys(req *client.CountEventByKeysRequest) (string, int64, error) {
  665. reply, err := c.eventQueryServiceClient.CountEventByKeys(context.Background(), &request.CountEventByKeysRequest{
  666. DatabaseID: c.databaseID,
  667. TablePrefixWithSchema: req.TablePrefixWithSchema,
  668. KeyValues: req.KeyValues,
  669. })
  670. if err != nil {
  671. return "", 0, err
  672. }
  673. return reply.Statement, reply.Count, nil
  674. }
  675. func (c *Client) CommonCountEvent(req *client.CommonCountEventRequest) (string, int64, error) {
  676. reply, err := c.eventQueryServiceClient.CommonCountEvent(context.Background(), &request.CommonCountEventRequest{
  677. DatabaseID: c.databaseID,
  678. TablePrefixWithSchema: req.TablePrefixWithSchema,
  679. KeyValues: req.KeyValues,
  680. Version: req.Version,
  681. Operation: req.Operation,
  682. CreatorID: req.CreatorID,
  683. StartCreatedTime: req.StartCreatedTime,
  684. EndCreatedTime: req.EndCreatedTime,
  685. })
  686. if err != nil {
  687. return "", 0, err
  688. }
  689. return reply.Statement, reply.Count, nil
  690. }
  691. func (c *Client) EventHistoryQueryByKeys(req *client.EventQueryByKeysRequest) (string, []client.EventInfo, int64, error) {
  692. var selectJsonBytes []byte
  693. if req.Select != nil {
  694. innerJsonBytes, err := req.Select.ToJson()
  695. if err != nil {
  696. return "", nil, 0, err
  697. }
  698. selectJsonBytes = innerJsonBytes
  699. }
  700. reply, err := c.eventQueryServiceClient.EventHistoryQueryByKeys(context.Background(), &request.EventQueryByKeysRequest{
  701. DatabaseID: c.databaseID,
  702. TablePrefixWithSchema: req.TablePrefixWithSchema,
  703. Select: selectJsonBytes,
  704. KeyValues: req.KeyValues,
  705. PageNo: int32(req.PageNo),
  706. PageSize: int32(req.PageSize),
  707. })
  708. if err != nil {
  709. return "", nil, 0, err
  710. }
  711. return reply.Statement, client.FormEventInfoBatch(reply.Infos), reply.TotalCount, nil
  712. }
  713. func (c *Client) CommonEventHistoryQuery(req *client.CommonEventQueryRequest) (string, []client.EventInfo, int64, error) {
  714. var selectJsonBytes []byte
  715. if req.Select != nil {
  716. innerJsonBytes, err := req.Select.ToJson()
  717. if err != nil {
  718. return "", nil, 0, err
  719. }
  720. selectJsonBytes = innerJsonBytes
  721. }
  722. reply, err := c.eventQueryServiceClient.CommonEventHistoryQuery(context.Background(), &request.CommonEventQueryRequest{
  723. DatabaseID: c.databaseID,
  724. TablePrefixWithSchema: req.TablePrefixWithSchema,
  725. Select: selectJsonBytes,
  726. KeyValues: req.KeyValues,
  727. Version: req.Version,
  728. Operation: req.Operation,
  729. CreatorID: req.CreatorID,
  730. StartCreatedTime: req.StartCreatedTime,
  731. EndCreatedTime: req.EndCreatedTime,
  732. PageNo: int32(req.PageNo),
  733. PageSize: int32(req.PageSize),
  734. })
  735. if err != nil {
  736. return "", nil, 0, err
  737. }
  738. return reply.Statement, client.FormEventInfoBatch(reply.Infos), reply.TotalCount, nil
  739. }
  740. func (c *Client) EventHistoryQueryOnlyByKeys(req *client.EventQueryByKeysRequest) (string, []client.EventInfo, error) {
  741. var selectJsonBytes []byte
  742. if req.Select != nil {
  743. innerJsonBytes, err := req.Select.ToJson()
  744. if err != nil {
  745. return "", nil, err
  746. }
  747. selectJsonBytes = innerJsonBytes
  748. }
  749. reply, err := c.eventQueryServiceClient.EventHistoryQueryOnlyByKeys(context.Background(), &request.EventQueryByKeysRequest{
  750. DatabaseID: c.databaseID,
  751. TablePrefixWithSchema: req.TablePrefixWithSchema,
  752. Select: selectJsonBytes,
  753. KeyValues: req.KeyValues,
  754. PageNo: int32(req.PageNo),
  755. PageSize: int32(req.PageSize),
  756. })
  757. if err != nil {
  758. return "", nil, err
  759. }
  760. return reply.Statement, client.FormEventInfoBatch(reply.Infos), nil
  761. }
  762. func (c *Client) CommonEventHistoryQueryOnly(req *client.CommonEventQueryRequest) (string, []client.EventInfo, error) {
  763. var selectJsonBytes []byte
  764. if req.Select != nil {
  765. innerJsonBytes, err := req.Select.ToJson()
  766. if err != nil {
  767. return "", nil, err
  768. }
  769. selectJsonBytes = innerJsonBytes
  770. }
  771. reply, err := c.eventQueryServiceClient.CommonEventHistoryQueryOnly(context.Background(), &request.CommonEventQueryRequest{
  772. DatabaseID: c.databaseID,
  773. TablePrefixWithSchema: req.TablePrefixWithSchema,
  774. Select: selectJsonBytes,
  775. KeyValues: req.KeyValues,
  776. Version: req.Version,
  777. Operation: req.Operation,
  778. CreatorID: req.CreatorID,
  779. StartCreatedTime: req.StartCreatedTime,
  780. EndCreatedTime: req.EndCreatedTime,
  781. PageNo: int32(req.PageNo),
  782. PageSize: int32(req.PageSize),
  783. })
  784. if err != nil {
  785. return "", nil, err
  786. }
  787. return reply.Statement, client.FormEventInfoBatch(reply.Infos), nil
  788. }
  789. func (c *Client) CountEventHistoryByKeys(req *client.CountEventByKeysRequest) (string, int64, error) {
  790. reply, err := c.eventQueryServiceClient.CountEventHistoryByKeys(context.Background(), &request.CountEventByKeysRequest{
  791. DatabaseID: c.databaseID,
  792. TablePrefixWithSchema: req.TablePrefixWithSchema,
  793. KeyValues: req.KeyValues,
  794. })
  795. if err != nil {
  796. return "", 0, err
  797. }
  798. return reply.Statement, reply.Count, nil
  799. }
  800. func (c *Client) CommonCountEventHistory(req *client.CommonCountEventRequest) (string, int64, error) {
  801. reply, err := c.eventQueryServiceClient.CommonCountEventHistory(context.Background(), &request.CommonCountEventRequest{
  802. DatabaseID: c.databaseID,
  803. TablePrefixWithSchema: req.TablePrefixWithSchema,
  804. KeyValues: req.KeyValues,
  805. Version: req.Version,
  806. Operation: req.Operation,
  807. CreatorID: req.CreatorID,
  808. StartCreatedTime: req.StartCreatedTime,
  809. EndCreatedTime: req.EndCreatedTime,
  810. })
  811. if err != nil {
  812. return "", 0, err
  813. }
  814. return reply.Statement, reply.Count, nil
  815. }