DEV Community

Nicolas Penot for Siodb

Posted on

Schemaless SQL database for strong and lasting back end

Benefits of the solution

  • Schemaless structures maintain in the code
  • Your documents stored as relational tables transparently
  • Performance and efficiency of relational database
  • Easier to maintain in the long term
  • Consume much fewer resources (cheaper in the cloud)

Examples

Single document - code side

  var doc = {
         email: "dwain.jonhson@gmail.com",
         firstname: "Dwain",
         lastname: "Jonhson",
         username: "dwainjonhson"
  };
  doc.save();

  collection("users").find({username: "dwainjonhson"});

  /*
      {
         trid : 2,   // auto id generation
         email: "dwain.jonhson@gmail.com",
         firstname: "Dwain",
         lastname: "Jonhson",
         username: "dwainjonhson"
      }
  */
Enter fullscreen mode Exit fullscreen mode

Single document - Database side

> select * from users;

TRID   EMAIL                       FIRST_NAME     LAST_NAME     USERNAME
------ --------------------------- -------------- ------------- --------------
     2 dwain.jonhson@gmail.com     Dwain          Jonhson       dwainjonhson
Enter fullscreen mode Exit fullscreen mode

Nested documents - code side

  var doc = {
         email: "dwain.jonhson@gmail.com",
         firstname: "Dwain",
         lastname: "Jonhson",
         username: "dwainjonhson",
         phones: [{
           alias: "home",
           number: "+1-202-555-0143" 
         },{
           alias: "mobile",
           number: "+1-202-555-0156" 
         }]
  };
  doc.save();

  collection("users").find({username: "dwainjonhson"});

  /*
      {
         trid : 2,   // auto id generation
         email: "dwain.jonhson@gmail.com",
         firstname: "Dwain",
         lastname: "Jonhson",
         username: "dwainjonhson"
         phones: [{
           trid : 1,   // auto id generation
           alias: "home",
           number: "+1-202-555-0143" 
         },{
           trid : 2,    // auto id generation
           alias: "mobile",
           number: "+1-202-555-0156" 
         }]
      }
  */
Enter fullscreen mode Exit fullscreen mode

Nested documents - database side

> select * from users;

TRID   EMAIL                       FIRST_NAME     LAST_NAME     USERNAME
------ --------------------------- -------------- ------------- --------------
     2 dwain.jonhson@gmail.com     Dwain          Jonhson       dwainjonhson

-- Nested phone documents automatically organized in table with the proper relationship.
> select * from users_phones;

TRID   USERD_TRID   ALIAS             NUMBER
------ ----------- ----------------- ------------------------
     1           2 home              +1-202-555-0143
     2           2 mobile            +1-202-555-0156      
Enter fullscreen mode Exit fullscreen mode

Conclusion

Push your document in the database without any worries about restructuring them later. Made all the modifications that you didn't predict because wasn't part of the initial requirements. And do this afterward with the comfort of SQL. Finally, reduce the cloud cost due to the resource consumption involved with traditional NoSQL databases.

This concept allows you to code fast with your data objects as documents (like Mongodb) while benefiting transparently from the relational databases (like PostgreSQL) .

Any questions? Please comment below :)

Top comments (0)