DEV Community

Cover image for The Magic Of A Single Integer Number To Contain Huge Information
Haripriya Lekshmi
Haripriya Lekshmi

Posted on

The Magic Of A Single Integer Number To Contain Huge Information

This blog is about how we can effectively store huge pieces of information by consuming less space. For this, here taking an example of “How to store all roles of a user in a single integer value.
A programmer should write a module for handling Roles and Permissions for the users when developing an application software. Suppose we have the following roles.

The programmer will usually assign an integer ID to each role like the following:

Suppose the user with ID 1 has the roles of Data Entry and View Only.
In this case, the programmer can save user permissions in two different ways:
Create a string with roles separated by a comma, for example, 6,7 and this can be stored in the column. While retrieving back, we can split the string by comma and find the role IDs.
Each role IDs can be stored against user id by consuming each column for each role ID as follows:

In this case, we need a separate table for storing information on user roles.
Would you like to know another better way to store any combination of user roles as a single integer value?
Read our latest blog by Sukesh Chand on storing huge information in a single integer values
https://urlzs.com/7QWkj

Top comments (0)