current_datetime_timestamp.rb

Path: lib/sequel/extensions/current_datetime_timestamp.rb
Last Update: Sun Oct 02 21:06:53 +0000 2016

frozen-string-literal: true

The current_datetime_timestamp extension makes Dataset#current_datetime return an object that operates like Sequel.datetime_class.now, but will be literalized as CURRENT_TIMESTAMP.

This allows you to use the defaults_setter, timestamps, and touch model plugins and make sure that CURRENT_TIMESTAMP is used instead of a literalized timestamp value.

The reason that CURRENT_TIMESTAMP is better than a literalized version of the timestamp is that it obeys correct transactional semantics (all calls to CURRENT_TIMESTAMP in the same transaction return the same timestamp, at least on some databases).

To have current_datetime be literalized as CURRENT_TIMESTAMP for a single dataset:

  ds = ds.extension(:current_datetime_timestamp)

To have current_datetime be literalized as CURRENT_TIMESTAMP for all datasets of a given database.

  DB.extension(:current_datetime_timestamp)

Related module: Sequel::CurrentDateTimeTimestamp

[Validate]