1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package redshiftdata 4 5import ( 6 "context" 7 "fmt" 8 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" 9 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" 10 "github.com/aws/aws-sdk-go-v2/service/redshiftdata/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// List of SQL statements. By default, only finished statements are shown. A token 16// is returned to page through the statement list. 17func (c *Client) ListStatements(ctx context.Context, params *ListStatementsInput, optFns ...func(*Options)) (*ListStatementsOutput, error) { 18 if params == nil { 19 params = &ListStatementsInput{} 20 } 21 22 result, metadata, err := c.invokeOperation(ctx, "ListStatements", params, optFns, addOperationListStatementsMiddlewares) 23 if err != nil { 24 return nil, err 25 } 26 27 out := result.(*ListStatementsOutput) 28 out.ResultMetadata = metadata 29 return out, nil 30} 31 32type ListStatementsInput struct { 33 34 // The maximum number of SQL statements to return in the response. If more SQL 35 // statements exist than fit in one response, then NextToken is returned to page 36 // through the results. 37 MaxResults int32 38 39 // A value that indicates the starting point for the next set of response records 40 // in a subsequent request. If a value is returned in a response, you can retrieve 41 // the next set of records by providing this returned NextToken value in the next 42 // NextToken parameter and retrying the command. If the NextToken field is empty, 43 // all response records have been retrieved for the request. 44 NextToken *string 45 46 // A value that filters which statements to return in the response. If true, all 47 // statements run by the caller's IAM role are returned. If false, only statements 48 // run by the caller's IAM role in the current IAM session are returned. The 49 // default is true. 50 RoleLevel *bool 51 52 // The name of the SQL statement specified as input to ExecuteStatement to identify 53 // the query. You can list multiple statements by providing a prefix that matches 54 // the beginning of the statement name. For example, to list myStatement1, 55 // myStatement2, myStatement3, and so on, then provide the a value of myStatement. 56 // Data API does a case-sensitive match of SQL statement names to the prefix value 57 // you provide. 58 StatementName *string 59 60 // The status of the SQL statement to list. Status values are defined as 61 // follows: 62 // 63 // * ABORTED - The query run was stopped by the user. 64 // 65 // * ALL - A status 66 // value that includes all query statuses. This value can be used to filter 67 // results. 68 // 69 // * FAILED - The query run failed. 70 // 71 // * FINISHED - The query has finished 72 // running. 73 // 74 // * PICKED - The query has been chosen to be run. 75 // 76 // * STARTED - The query 77 // run has started. 78 // 79 // * SUBMITTED - The query was submitted, but not yet processed. 80 Status types.StatusString 81} 82 83type ListStatementsOutput struct { 84 85 // The SQL statements. 86 // 87 // This member is required. 88 Statements []types.StatementData 89 90 // A value that indicates the starting point for the next set of response records 91 // in a subsequent request. If a value is returned in a response, you can retrieve 92 // the next set of records by providing this returned NextToken value in the next 93 // NextToken parameter and retrying the command. If the NextToken field is empty, 94 // all response records have been retrieved for the request. 95 NextToken *string 96 97 // Metadata pertaining to the operation's result. 98 ResultMetadata middleware.Metadata 99} 100 101func addOperationListStatementsMiddlewares(stack *middleware.Stack, options Options) (err error) { 102 err = stack.Serialize.Add(&awsAwsjson11_serializeOpListStatements{}, middleware.After) 103 if err != nil { 104 return err 105 } 106 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListStatements{}, middleware.After) 107 if err != nil { 108 return err 109 } 110 if err = addSetLoggerMiddleware(stack, options); err != nil { 111 return err 112 } 113 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 114 return err 115 } 116 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 117 return err 118 } 119 if err = addResolveEndpointMiddleware(stack, options); err != nil { 120 return err 121 } 122 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 123 return err 124 } 125 if err = addRetryMiddlewares(stack, options); err != nil { 126 return err 127 } 128 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 129 return err 130 } 131 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 132 return err 133 } 134 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 135 return err 136 } 137 if err = addClientUserAgent(stack); err != nil { 138 return err 139 } 140 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 141 return err 142 } 143 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 144 return err 145 } 146 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListStatements(options.Region), middleware.Before); err != nil { 147 return err 148 } 149 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 150 return err 151 } 152 if err = addResponseErrorMiddleware(stack); err != nil { 153 return err 154 } 155 if err = addRequestResponseLogging(stack, options); err != nil { 156 return err 157 } 158 return nil 159} 160 161// ListStatementsAPIClient is a client that implements the ListStatements 162// operation. 163type ListStatementsAPIClient interface { 164 ListStatements(context.Context, *ListStatementsInput, ...func(*Options)) (*ListStatementsOutput, error) 165} 166 167var _ ListStatementsAPIClient = (*Client)(nil) 168 169// ListStatementsPaginatorOptions is the paginator options for ListStatements 170type ListStatementsPaginatorOptions struct { 171 // The maximum number of SQL statements to return in the response. If more SQL 172 // statements exist than fit in one response, then NextToken is returned to page 173 // through the results. 174 Limit int32 175 176 // Set to true if pagination should stop if the service returns a pagination token 177 // that matches the most recent token provided to the service. 178 StopOnDuplicateToken bool 179} 180 181// ListStatementsPaginator is a paginator for ListStatements 182type ListStatementsPaginator struct { 183 options ListStatementsPaginatorOptions 184 client ListStatementsAPIClient 185 params *ListStatementsInput 186 nextToken *string 187 firstPage bool 188} 189 190// NewListStatementsPaginator returns a new ListStatementsPaginator 191func NewListStatementsPaginator(client ListStatementsAPIClient, params *ListStatementsInput, optFns ...func(*ListStatementsPaginatorOptions)) *ListStatementsPaginator { 192 if params == nil { 193 params = &ListStatementsInput{} 194 } 195 196 options := ListStatementsPaginatorOptions{} 197 if params.MaxResults != 0 { 198 options.Limit = params.MaxResults 199 } 200 201 for _, fn := range optFns { 202 fn(&options) 203 } 204 205 return &ListStatementsPaginator{ 206 options: options, 207 client: client, 208 params: params, 209 firstPage: true, 210 } 211} 212 213// HasMorePages returns a boolean indicating whether more pages are available 214func (p *ListStatementsPaginator) HasMorePages() bool { 215 return p.firstPage || p.nextToken != nil 216} 217 218// NextPage retrieves the next ListStatements page. 219func (p *ListStatementsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListStatementsOutput, error) { 220 if !p.HasMorePages() { 221 return nil, fmt.Errorf("no more pages available") 222 } 223 224 params := *p.params 225 params.NextToken = p.nextToken 226 227 params.MaxResults = p.options.Limit 228 229 result, err := p.client.ListStatements(ctx, ¶ms, optFns...) 230 if err != nil { 231 return nil, err 232 } 233 p.firstPage = false 234 235 prevToken := p.nextToken 236 p.nextToken = result.NextToken 237 238 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 239 p.nextToken = nil 240 } 241 242 return result, nil 243} 244 245func newServiceMetadataMiddleware_opListStatements(region string) *awsmiddleware.RegisterServiceMetadata { 246 return &awsmiddleware.RegisterServiceMetadata{ 247 Region: region, 248 ServiceID: ServiceID, 249 SigningName: "redshift-data", 250 OperationName: "ListStatements", 251 } 252} 253