Auto-increment IDs #33
Unanswered
retorquere
asked this question in
Q&A
Replies: 1 comment 3 replies
-
You can write a helper function to do that. // Initialize userTableId with the highest number not present already
let userTableId = Math.max(...(await many(userTable)).map(u => u.id + 1));
const genUserTableId = () => userTableId++;
// Now, whenever you create an entity, use `genUserTableId` to generate your ID.
await insert(userTable, { id: genUserTableId(), name: "Adrian", age: 24 }); |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Is there a way to generate numeric auto-increment IDs rather than GUIDs as primary keys?
Beta Was this translation helpful? Give feedback.
All reactions