Menu

Build a Type-Safe Product Catalog API...
πŸ“°

Build a Type-Safe Product Catalog API...

DEV CommunityΒ·Jugkapong PoobanΒ·6 months ago
#4UgrY57k
#create#list#get#restock#delete
Reading 0:00
15s threshold

If you've ever worked with Azure Cosmos DB directly, you know the pain. Writing raw SQL queries by hand, managing parameterized inputs, zero validation before data hits the database. Compare these two approaches for finding electronics under $100:

Raw @azure/cosmos SDK:

const { resources } = await container . items . query ({ query : ' SELECT * FROM c WHERE c.category = @cat AND c.price >= @min AND c.price <= @max ' , parameters : [ { name : ' @cat ' , value : ' electronics ' }, { name : ' @min ' , value : 10 }, { name : ' @max ' , value : 100 }, ], }) . fetchAll ();

Enter fullscreen mode

Exit fullscreen mode

With Cosmoose:

const products = await Product . find ({ category : ' electronics ' , price : { $gte : 10 , $lte : 100 }, });

Enter fullscreen mode

Exit fullscreen mode

Cosmoose is a type-safe ODM for Azure Cosmos DB, built with TypeScript.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.