Auto generated IDs #20
-
|
I've been reading through the documentation and Quanta looks great. One question I have is on IDs. In the docs, when putting a record the ID is specified. Can Quanta auto generate/auto increment IDs? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
|
Hey @amugofjava As of now we don't have auto increment IDs, we create Yes we are already working on |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for your reply. |
Beta Was this translation helpful? Give feedback.
-
|
@amugofjava I added supports for both manual and automatic ID generation! Here's how it works:
@QuantaId()
final String id; // You provide the ID
@QuantaId(autoGenerate: true)
final String id; // Empty string will be auto-generatedThe auto-generated IDs follow this format:
You can also customize the prefix: @QuantaId(autoGenerate: true, prefix: 'usr_')
final String id; // Will generate IDs like: usr_1647123456789When using auto-generated IDs, just pass an empty string as the ID when creating a new entity: final user = User(
id: '', // Will be auto-generated
name: 'John',
email: 'john@example.com'
);The auto-generation happens automatically during the insert operation, so you don't need to do anything special beyond setting Note: While we don't have traditional auto-incrementing IDs yet, the timestamp-based generation ensures uniqueness. We're planning to add sequential ID generation in a future release. You can learn more about here @amugofjava Thanks for the contribution 😄 |
Beta Was this translation helpful? Give feedback.
-
|
Push to pub.dev. - https://pub.dev/packages/quanta_db |
Beta Was this translation helpful? Give feedback.
Hey @amugofjava As of now we don't have auto increment IDs, we create
primaryKeyand based on that we manage - You can learn more about it in indexManage hereYes we are already working on
auto generate/auto increment IDs, it's in pipeline we will implement this soon, I will update ones it is done.