Creating "users.id_users" on DynamoDB and PHP

I'm studing DynamoDB but I don't understand how can I create a unique user's id foreach user. In SQL is simple, there is an int (AI) field. It'll be a int value because each user's profile url is like (very common form):

my-application-url/users/[:id_users]
ex. my-application-url/users/1/

My old save_users function is:

public function save_users($users){ 
 if($users->id == 0){
    $this->tableGateway()->save($users);
 }else{
    $this->tableGateway()->update($users, 'id_users' => (int) $users->id);
 }
}

I use zend framework 2.

I could get the last registered user's id and increment it, but if I have 2 or more simultaneus registrations, I could get 2 or more identical user's id.

the users dynamodb table it also simple:

{
  "id_users" Number: 1,
  "firstname" String: "Alessandro",
  "lastname" String: "Corradini",
  "email" String: "my-email",
  "password" String: "my-encrypted-password"
}

POSSIBLE SOLUTION

I need a UUID field into users table. The table 'll be like:

{
  "UUID" String : <UUID-placeholder>,
  "id_users" Number: 1,
  "firstname" String: "Alessandro",
  "lastname" String: "Corradini",
  "email" String: "my-email",
  "password" String: "my-encrypted-password"
}

For id_users identifier, also unique, I'll generate a fixed lenght id_users with this function below. Before saving user into register.php, I'll check if is present into table (and email also!!), if is not, save user, else generate another unique id.

 function randomId($length){
    $result = mt_rand(1, 9);

    for($i = 0; $i < ($length - 1); $i++) {
        $result .= mt_rand(0, 9);
    }

    return $result;
 }

For 16 character length, I have 10^16 combinations. I think that is enaugh.

Answers


the approach in dynamodb is to create an UUID in your client side, for example by timestamp (instead of auto-increment feature)

you can also use an external service that provide you the id (by using locks on global verb)

you can get more information here:

Are autoincremented primary keys okay https://forums.aws.amazon.com/thread.jspa?messageID=561190

How to make a UUID in DynamoDB?

https://www.quora.com/How-to-auto-increment-in-DynamoDB


Need Your Help

How to ngFor in angular2

angular ionic2

I have this set of data that i want to use in one of my ng2 projects:

Cloudflare and cPanel issue - Reidrects back to main hostname

cpanel cloudflare

So I setup a subdomain off my regular domain. I then make an A record on Cloudflare to point to the IP address of my server. However, whenever I go to the subdomain, it just takes me back to the main