1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package glue 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/glue/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Retrieves the definitions of some or all of the tables in a given Database. 16func (c *Client) GetTables(ctx context.Context, params *GetTablesInput, optFns ...func(*Options)) (*GetTablesOutput, error) { 17 if params == nil { 18 params = &GetTablesInput{} 19 } 20 21 result, metadata, err := c.invokeOperation(ctx, "GetTables", params, optFns, addOperationGetTablesMiddlewares) 22 if err != nil { 23 return nil, err 24 } 25 26 out := result.(*GetTablesOutput) 27 out.ResultMetadata = metadata 28 return out, nil 29} 30 31type GetTablesInput struct { 32 33 // The database in the catalog whose tables to list. For Hive compatibility, this 34 // name is entirely lowercase. 35 // 36 // This member is required. 37 DatabaseName *string 38 39 // The ID of the Data Catalog where the tables reside. If none is provided, the AWS 40 // account ID is used by default. 41 CatalogId *string 42 43 // A regular expression pattern. If present, only those tables whose names match 44 // the pattern are returned. 45 Expression *string 46 47 // The maximum number of tables to return in a single response. 48 MaxResults *int32 49 50 // A continuation token, included if this is a continuation call. 51 NextToken *string 52} 53 54type GetTablesOutput struct { 55 56 // A continuation token, present if the current list segment is not the last. 57 NextToken *string 58 59 // A list of the requested Table objects. 60 TableList []types.Table 61 62 // Metadata pertaining to the operation's result. 63 ResultMetadata middleware.Metadata 64} 65 66func addOperationGetTablesMiddlewares(stack *middleware.Stack, options Options) (err error) { 67 err = stack.Serialize.Add(&awsAwsjson11_serializeOpGetTables{}, middleware.After) 68 if err != nil { 69 return err 70 } 71 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpGetTables{}, middleware.After) 72 if err != nil { 73 return err 74 } 75 if err = addSetLoggerMiddleware(stack, options); err != nil { 76 return err 77 } 78 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 79 return err 80 } 81 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 82 return err 83 } 84 if err = addResolveEndpointMiddleware(stack, options); err != nil { 85 return err 86 } 87 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 88 return err 89 } 90 if err = addRetryMiddlewares(stack, options); err != nil { 91 return err 92 } 93 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 94 return err 95 } 96 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 97 return err 98 } 99 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 100 return err 101 } 102 if err = addClientUserAgent(stack); err != nil { 103 return err 104 } 105 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 106 return err 107 } 108 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 109 return err 110 } 111 if err = addOpGetTablesValidationMiddleware(stack); err != nil { 112 return err 113 } 114 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetTables(options.Region), middleware.Before); err != nil { 115 return err 116 } 117 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 118 return err 119 } 120 if err = addResponseErrorMiddleware(stack); err != nil { 121 return err 122 } 123 if err = addRequestResponseLogging(stack, options); err != nil { 124 return err 125 } 126 return nil 127} 128 129// GetTablesAPIClient is a client that implements the GetTables operation. 130type GetTablesAPIClient interface { 131 GetTables(context.Context, *GetTablesInput, ...func(*Options)) (*GetTablesOutput, error) 132} 133 134var _ GetTablesAPIClient = (*Client)(nil) 135 136// GetTablesPaginatorOptions is the paginator options for GetTables 137type GetTablesPaginatorOptions struct { 138 // The maximum number of tables to return in a single response. 139 Limit int32 140 141 // Set to true if pagination should stop if the service returns a pagination token 142 // that matches the most recent token provided to the service. 143 StopOnDuplicateToken bool 144} 145 146// GetTablesPaginator is a paginator for GetTables 147type GetTablesPaginator struct { 148 options GetTablesPaginatorOptions 149 client GetTablesAPIClient 150 params *GetTablesInput 151 nextToken *string 152 firstPage bool 153} 154 155// NewGetTablesPaginator returns a new GetTablesPaginator 156func NewGetTablesPaginator(client GetTablesAPIClient, params *GetTablesInput, optFns ...func(*GetTablesPaginatorOptions)) *GetTablesPaginator { 157 options := GetTablesPaginatorOptions{} 158 if params.MaxResults != nil { 159 options.Limit = *params.MaxResults 160 } 161 162 for _, fn := range optFns { 163 fn(&options) 164 } 165 166 if params == nil { 167 params = &GetTablesInput{} 168 } 169 170 return &GetTablesPaginator{ 171 options: options, 172 client: client, 173 params: params, 174 firstPage: true, 175 } 176} 177 178// HasMorePages returns a boolean indicating whether more pages are available 179func (p *GetTablesPaginator) HasMorePages() bool { 180 return p.firstPage || p.nextToken != nil 181} 182 183// NextPage retrieves the next GetTables page. 184func (p *GetTablesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*GetTablesOutput, error) { 185 if !p.HasMorePages() { 186 return nil, fmt.Errorf("no more pages available") 187 } 188 189 params := *p.params 190 params.NextToken = p.nextToken 191 192 var limit *int32 193 if p.options.Limit > 0 { 194 limit = &p.options.Limit 195 } 196 params.MaxResults = limit 197 198 result, err := p.client.GetTables(ctx, ¶ms, optFns...) 199 if err != nil { 200 return nil, err 201 } 202 p.firstPage = false 203 204 prevToken := p.nextToken 205 p.nextToken = result.NextToken 206 207 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 208 p.nextToken = nil 209 } 210 211 return result, nil 212} 213 214func newServiceMetadataMiddleware_opGetTables(region string) *awsmiddleware.RegisterServiceMetadata { 215 return &awsmiddleware.RegisterServiceMetadata{ 216 Region: region, 217 ServiceID: ServiceID, 218 SigningName: "glue", 219 OperationName: "GetTables", 220 } 221} 222