herbsjs / herbs-cli

Herbs CLI
https://herbsjs.org/
MIT License
29 stars 30 forks source link

Uses ObjectID on id field for all databases choices #158

Open italojs opened 2 years ago

italojs commented 2 years ago

When we create a project, the entity ID is generated via a simple random number

ctx.user.id = Math.floor(Math.random() * 100000).toString()

We could improve it using ObjectID, it could be a default value for all databases:

dalssoft commented 2 years ago

use objectID in ID field for the user(generated) entity;

I didn't understand. Could you proved a code example?

italojs commented 2 years ago

I'm sorry, maybe I'm not clear. We generate a random number for User.id as we do for SQL databases here, we could just define the id as string, so insert the User using a ObjectID id instead

change this:

<% if(!props.mongo){ %>ctx.<%- props.name.camelCase %>.id = Math.floor(Math.random() * 100000).toString()<% } %>

for this:

ctx.<%- props.name.camelCase %>.id = new ObjectId()