Sha256: 49e30899f4cefe76f7c0399d72a63f4e7e889f431b163737e03f2b9699f737da

Contents?: true

Size: 1.11 KB

Versions: 88

Compression:

Stored size: 1.11 KB

Contents

# -*- ruby -*-
# frozen_string_literal: true

require 'date'
require 'json'

module PG
	module TextDecoder
		class Date < SimpleDecoder
			def decode(string, tuple=nil, field=nil)
				if string =~ /\A(\d{4})-(\d\d)-(\d\d)\z/
					::Date.new $1.to_i, $2.to_i, $3.to_i
				else
					string
				end
			end
		end

		class JSON < SimpleDecoder
			def decode(string, tuple=nil, field=nil)
				::JSON.parse(string, quirks_mode: true)
			end
		end

		# Convenience classes for timezone options
		class TimestampUtc < Timestamp
			def initialize(params={})
				super(params.merge(flags: PG::Coder::TIMESTAMP_DB_UTC | PG::Coder::TIMESTAMP_APP_UTC))
			end
		end
		class TimestampUtcToLocal < Timestamp
			def initialize(params={})
				super(params.merge(flags: PG::Coder::TIMESTAMP_DB_UTC | PG::Coder::TIMESTAMP_APP_LOCAL))
			end
		end
		class TimestampLocal < Timestamp
			def initialize(params={})
				super(params.merge(flags: PG::Coder::TIMESTAMP_DB_LOCAL | PG::Coder::TIMESTAMP_APP_LOCAL))
			end
		end

		# For backward compatibility:
		TimestampWithoutTimeZone = TimestampLocal
		TimestampWithTimeZone = Timestamp
	end
end # module PG

Version data entries

88 entries across 88 versions & 4 rubygems

Version Path
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pg-1.4.5/lib/pg/text_decoder.rb
cipherstash-pg-1.0.0.beta.1-x86_64-darwin-21 ./lib/pg/text_decoder.rb
cipherstash-pg-1.0.0.beta.1-arm64-darwin-21 ./lib/pg/text_decoder.rb
cipherstash-pg-1.0.0.beta.1-x86_64-linux ./lib/pg/text_decoder.rb
cipherstash-pg-1.0.0.beta.1-x86_64-darwin-22 ./lib/pg/text_decoder.rb
cipherstash-pg-1.0.0.beta.1-arm64-darwin-22 ./lib/pg/text_decoder.rb
cipherstash-pg-1.0.0.beta.1-aarch64-linux ./lib/pg/text_decoder.rb
pg-1.4.6-x86-mingw32 lib/pg/text_decoder.rb
pg-1.4.6-x64-mingw32 lib/pg/text_decoder.rb
pg-1.4.6-x64-mingw-ucrt lib/pg/text_decoder.rb
pg-1.4.6 lib/pg/text_decoder.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pg-1.4.5/lib/pg/text_decoder.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pg-1.4.5/lib/pg/text_decoder.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pg-1.4.5/lib/pg/text_decoder.rb
pg-1.4.5-x86-mingw32 lib/pg/text_decoder.rb
pg-1.4.5-x64-mingw-ucrt lib/pg/text_decoder.rb
pg-1.4.5-x64-mingw32 lib/pg/text_decoder.rb
pg-1.4.5 lib/pg/text_decoder.rb
pg-1.4.4-x86-mingw32 lib/pg/text_decoder.rb
pg-1.4.4-x64-mingw32 lib/pg/text_decoder.rb