Make C++ Great Again
For Web
Real life Scenario - Cookups in Bangladesh
1. User cooks something at home, post through an app
2. Diners order from one of those posts
3. Therefore user (owner of the posts) has orders
Our Task
1. Create Users
2. Create Posts and link Owner/User
3. Create Order for posts and link Orders
4. Query Posts, Orders, Users/Owners
Our Task
1. Create User
Send C++ web server a JSON object, specify class User
And info :
{UserId:uid, Name:name, Email:email}
Example:
url/create/?class=’user’&object={UserId:uid, Name:name, Email:email}
Our Task
2. Create Posts and Link with User
Send C++ web server a JSON object, specify class Post
And info :
{PostId:pid, Image:url, Description:desc, UserID:uid}
Example:
url/create/?class=post’&object={PostId:pid, Image:url, Description:desc, UserID:uid}
Our Task
3. Create Order for posts and link Orders
Send C++ web server a JSON object, specify class Order
And info :
{OrderId:orderId, orderedBy:orderuserid, PostId:postId,
OwnerId:userId}
Example:
url/create/?class=order&object={OrderId:orderId, orderedBy:userid, PostId:postId,
OwnerID:userId}
4. Query posts, their owners, and orders
● Say we want to Query the food posts which are
approved and rating is above 3, and want to list the
respective owner of the posts and
List all orders associated with the owner where the
delivery type is pickup
Query Format (inspired by loopbackJS)
{
Filter:"posts",
scope: {
// post rating greater than 3 and post approved
where: [{rating: {gt: 3}}, {approved:{eq:1}]
},
sort:["created_at", "priority"],
include: {
relation: 'owner', by: 'owner_id',// include the owner object i.e owner/writer of the post
scope: { // further filter the owner object
fields: ['username', 'email'], // only show two fields
include: { // include orders for the owner
relation: 'orders', by: 'order_id',
scope: {
where: {deliveryType: {eq:”pickup”}} // only select order with id 5
}
}
};
};
Data Storage Format
With the advent of SSD/Flash Drives, SQL DB Formats will become
redundant, they use unnecessary optimizations now a days which are not
required for modern day Hardware. So idea is:
Simple File System by class names
Like Users.json, Posts.json, Orders.json
Later we will divide by
UsersCluster1.json, UsersCluster2.json … etc. and use some Info.db where it would be specified
how many classes and clusters are there. Like : [{Users:2 (i.e 2 clusters)}, {Posts:4}] etc.
Next we will Optimize Searching and Caching
Status Successfully used https://github.com/nlohmann/json
for serializing JSON Objects
Codes avaiable already.