module
CQL::ActiveRecord::TimestampManager
Overview
Module for managing timestamp fields (created_at, updated_at) Provides automatic timestamp handling following Active Record conventions
Features:
- Automatic created_at setting on record creation
- Automatic updated_at setting on record modification
- Touch functionality for updating timestamps without callbacks
- Bulk timestamp updates for multiple records
Example Using timestamp management (the users table has created_at/updated_at columns)
user = User.new("Alice", "alice@example.com")
user.save # Automatically sets created_at and updated_at
user.touch # Updates updated_at without running callbacks
Defined in:
active_record/timestamp_manager.crMacro Summary
-
apply_timestamps(attrs)
Apply timestamp attributes to the record - @param attrs [Hash(Symbol, DB::Any)] Timestamp attributes to apply
-
has_timestamp_column?(column_name)
Check if the model has a timestamp column - @param column_name [Symbol] The timestamp column name - @return [CQL::BaseColumn?] The column, or nil if the table has none by that name
-
prepare_timestamps(is_new_record)
Automatically set timestamp fields before save Sets created_at on create and updated_at on both create and update - @param is_new_record [Bool] Whether this is a new record - @return [Hash(Symbol, DB::Any)] Hash of timestamp attributes to update
-
validate_timestamp_columns(fields)
Validate that timestamp columns exist in the table - @param fields [Array(Symbol)] Field names to validate - @raise [CQL::Error] If any field doesn't exist in the table
Macro Detail
Apply timestamp attributes to the record
- @param attrs [Hash(Symbol, DB::Any)] Timestamp attributes to apply
Example Applying timestamps
apply_timestamps(timestamp_attrs)
Check if the model has a timestamp column
- @param column_name [Symbol] The timestamp column name
- @return [CQL::BaseColumn?] The column, or nil if the table has none by that name
Example Checking for timestamp column
has_timestamp_column?(:created_at) # the column, or nil
Automatically set timestamp fields before save Sets created_at on create and updated_at on both create and update
- @param is_new_record [Bool] Whether this is a new record
- @return [Hash(Symbol, DB::Any)] Hash of timestamp attributes to update
Example Setting timestamps
timestamp_attrs = prepare_timestamps(new_record?)
Validate that timestamp columns exist in the table
- @param fields [Array(Symbol)] Field names to validate
- @raise [CQL::Error] If any field doesn't exist in the table
Example Validating timestamp fields
validate_timestamp_columns([:created_at, :updated_at])