Skip to content

v1.3.0 – Auto-Increment Support & Validation

Choose a tag to compare

@velkymx velkymx released this 09 Apr 19:10
· 197 commits to main since this release

This release introduces support for traditional SQL-style AUTO_INCREMENT primary keys, with smarter insert handling, enhanced validation, and full test coverage.


🚀 New Features

✅ Auto-Increment ID Field Support

You can now define a struct field like this:

{
  name: "id",
  type: "number",
  required: true,
  length: 11,
  default: "auto_increment"
}

Behavior:

  • On create():
    • The id is ignored automatically (not included in SQL).
    • If the user tries to pass id, validation will fail.
  • On update() / remove():
    • The id is required and validated as a number.

🔐 Validation Enhancements

The validatePayload() function now:

  • Skips validation for auto_increment fields during insert
  • Rejects attempts to manually pass id during insert
  • Preserves strict type validation for updates/deletes

🧪 Tests Added

New tests verify:

  • Successful creation without ID
  • Proper update/delete using returned ID
  • Failure if user tries to provide an auto_increment ID on insert

✨ Example

await create('users', userStruct, {
  title: 'Auto User'
});
// Returns: { success: true, data: { id: 1 } }
await create('users', userStruct, {
  id: 99,
  title: 'Invalid'
});
// Fails: id should not be provided (auto_increment)

✅ Summary

This update adds:

  • Cleaner support for auto-incrementing numeric IDs
  • Safer inserts with validation against misuse
  • Consistent handling across all CRUD operations