SQL++ - Case Study I. E-Commerce

For this case study, imagine that you want to build dimestore, an online store. You use Couchbase Server to store a variety of data – everything from product details and customer information to purchase and review histories.

Now, let's look at how N1QL can be used to solve some typical e-commerce scenarios. For this tutorial, our data is kept in 4 different buckets:

  • product This bucket contains a list of products to be sold, the categories to which they belong, price of each product, and other product info.
  • customers This bucket contains customer information such as the name, address, and the customers credit card details.
  • purchases This bucket contains a list of purchases made by a customer - each document contains a list of items purchased and the quantity of each item purchased.
  • reviews This bucket contains a list of reviews made by a customer or specific product. Each review is scored from 0 to 5.

There are 2 types of users of our application:

  • Shopper The shopper is the consumer and uses the application to buy products online.
  • Merchant An employee of dimestore.

Counting all the products
Don shops online at dimestore. When he visits the homepage, it displays a count of all the products.


To run this example, click the button in the top right corner of the code editor.

Code Editor

Output