Skip to content

Commit

Permalink
fix: cancel statementリクエストを追加 (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
ohatakky committed Dec 8, 2020
1 parent bb87413 commit 3c1d8e2
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ type Statements struct {
}

type Statement struct {
ID int
Code string
State StatementState
Output StatementOutput
ID int
Code string
State StatementState
Output StatementOutput
Started int64
}

type StatementOutput struct {
Expand Down Expand Up @@ -189,3 +190,43 @@ func (c *StatementsInsertCall) doRequest() (*http.Response, error) {

return SendRequest(c.s.client, req)
}

type StatementsCancelCall struct {
s *Service
sessionID int
statementID int
}

func (r *StatementsService) Cancel(sessionID, statementID int) *StatementsCancelCall {
c := &StatementsCancelCall{s: r.s}
c.sessionID = sessionID
c.statementID = statementID

return c
}

func (c *StatementsCancelCall) Do() (*Statement, error) {
res, err := c.doRequest()
if err != nil {
return nil, err
}

statement := &Statement{}
err = DecodeResponse(statement, res)

if err != nil {
return nil, err
}
return statement, nil
}

func (c *StatementsCancelCall) doRequest() (*http.Response, error) {
url := c.s.BasePath + fmt.Sprintf("/sessions/%v/statements/%v/cancel", c.sessionID, c.statementID)
var body io.Reader = nil
req, err := http.NewRequest("POST", url, body)
if err != nil {
return nil, err
}

return SendRequest(c.s.client, req)
}

0 comments on commit 3c1d8e2

Please sign in to comment.