Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cancel statementリクエストを追加 #11

Merged
merged 2 commits into from
Dec 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}