File: pg_timestamptz.rb

package info (click to toggle)
ruby-sequel 5.97.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,188 kB
  • sloc: ruby: 123,115; makefile: 3
file content (52 lines) | stat: -rw-r--r-- 1,554 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# frozen-string-literal: true
#
# The pg_timestamptz extension changes the default timestamp
# type for the database to be +timestamptz+ (<tt>timestamp with time zone</tt>)
# instead of +timestamp+ (<tt>timestamp without time zone</tt>).  This is
# recommended if you are dealing with multiple timezones in your application.
#
# If you are using the auto_cast_date_and_time extension, the pg_timestamptz
# extension will automatically cast Time and DateTime values to
# <tt>TIMESTAMP WITH TIME ZONE</tt> instead of +TIMESTAMP+.
# 
# To load the extension into the database:
#
#   DB.extension :pg_timestamptz
#
# To load the extension into individual datasets:
#
#   ds = ds.extension(:pg_timestamptz)
#
# Note that the loading into individual datasets only affects the integration
# with the auto_cast_date_and_time extension.
#
# Related modules: Sequel::Postgres::Timestamptz, Sequel::Postgres::TimestamptzDatasetMethods

#
module Sequel
  module Postgres
    module Timestamptz
      def self.extended(db)
        db.extend_datasets(TimestamptzDatasetMethods)
      end

      private

      # Use timestamptz by default for generic timestamp value.
      def type_literal_generic_datetime(column)
        :timestamptz
      end
    end

    module TimestamptzDatasetMethods
      private

      def literal_datetime_timestamp_cast
        'TIMESTAMP WITH TIME ZONE '
      end
    end
  end

  Dataset.register_extension(:pg_timestamptz, Postgres::TimestamptzDatasetMethods)
  Database.register_extension(:pg_timestamptz, Postgres::Timestamptz)
end