https://pulumi.com logo
#general
Title
# general
s

swift-painter-31084

06/25/2019, 4:58 PM
Copy code
endpoint.get( '/posts/{postId}', ( req, res ) => {
    const post = req.params.postId;
    console.log( post );
    postsTable.get( { post } ).then( ( value ) => {
        res.status( 200 ).json( value );
    } );
} );
w

white-balloon-205

06/25/2019, 8:43 PM
How did you define your table? It sounds like you did not specify
post
as a primary key for this table.
s

swift-painter-31084

06/25/2019, 9:17 PM
``` const postsTable = new cloud.Table( 'feedPosts', 'postId' ); // Create an API endpoint const endpoint = new cloud.API( 'feed-posts' ); // Add a new Feed Post endpoint.post( '/posts/add', ( req, res ) => { const feedPost = JSON.parse( req.body ); console.log( feedPost ); postsTable.insert( { postId: feedPost.postId, title: feedPost.title, body: feedPost.body, } ).then( () => { res.status( 200 ).json( feedPost ); }, res.status( 500 ).end() ); } ); // Get a single Feed Post endpoint.get( '/posts/{postId}', ( req, res ) => { const post = req.params.postId; console.log( post ); postsTable.get( { post } ).then( ( value ) => { res.status( 200 ).json( value ); } ); } );
That was my code; after your message I updated my get to use postId for the assignment to the parameter and passed that into the query, that worked fine.
I guess the table.get {query} is looking at the key name itself, not assuming the value is the primary key.
w

white-balloon-205

06/25/2019, 11:25 PM
That's right - that JS code is a shorthand for
postsTable.get( { post: post } )
, so it's getting the primary key
"post"
whose value matches the value of
post
.