module
CQL::ActiveRecord::Insertable
Overview
Insertable module provides create! methods for ActiveRecord models.
UUID/ULID Generation in Transactions
Important Note: UUIDs and ULIDs are generated client-side BEFORE the INSERT statement is executed. This design ensures cross-database compatibility (SQLite, PostgreSQL, MySQL) by storing these IDs as strings.
Transaction Behavior:
- If a transaction rolls back after UUID/ULID generation, the generated ID is not reused. This is expected behavior and does not cause data integrity issues.
- The UUID/ULID address space is large enough (128 bits for UUID, 128 bits for ULID) that "wasted" IDs are statistically insignificant.
- For Int32/Int64 primary keys, the database handles ID generation via auto-increment, so rollbacks do not waste IDs at the application level.
Example with transactions (for a model with a UUID key):
User.transaction do |tx|
User.create!(name: "Alice", email: "alice@example.com") # UUID generated here
tx.rollback # UUID is "wasted" but harmless
end