logo_positive
logo_positive

Reputation: 25

How do I correctly unmarshal the results of a PartiQL Query in Go using the AWS sdk?

I have upcoming shows for my band stored with DynamoDB, and I have the following code:

type PartiQLRunner struct {
    DynamoDbClient *dynamodb.DynamoDB
    TableName      string
}

func BuildRunner() *PartiQLRunner {
    sess := session.Must(session.NewSessionWithOptions(session.Options{
        SharedConfigState: session.SharedConfigEnable,
    }))

    svc := dynamodb.New(sess)

    return &PartiQLRunner{
        DynamoDbClient: svc,
        TableName:      "SHOWS",
    }
}

type Show struct {
    PK      int    `dynamodbav:"PK"`
    DATE    string `dynamodbav:"DATE"`
    ADDRESS string `dynamodbav:"ADDRESS"`
    VENUE   string `dynamodbav:"VENUE"`
}

func (runner PartiQLRunner) GetShows() ([]Show, error) {
    var shows []Show
    response, err := runner.DynamoDbClient.ExecuteStatement(
        &dynamodb.ExecuteStatementInput{
            Statement: aws.String(fmt.Sprintf("SELECT * FROM \"%v\" WHERE PK = 1", runner.TableName)),
        })
    if err != nil {
        log.Printf("Couldn't get info. Here's why: %v\n", err)
    } else {
        err = attributevalue.UnmarshalListOfMaps(response.Items, &shows)
        if err != nil {
            log.Printf("Couldn't unmarshal response. Here's why: %v\n", err)
        }
    }
    return shows, err
}

However, I am getting the following error with the response.Items parameter in UnmarshalListOfMaps():

Cannot use 'response.Items' (type []map[string]*AttributeValue) as the type []map[string]types.AttributeValue

I am still somewhat new to Go syntax, and I'm not sure I'm understanding the mismatch between what is being passed in and what is expected. Any help would be greatly appreciated.

Upvotes: 1

Views: 234

Answers (0)

Related Questions