Sha256: 2d3d4f33c39dec4226a33df19de44d4fa2645d46eb7d6f8e87cb8c3fbfe1be4c

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

module Swift
  module DB
    class Mysql < Adapter
      def initialize options = {}
        super options.update(driver: 'mysql')
        execute('select unix_timestamp() - unix_timestamp(utc_timestamp()) as offset') {|r| @tzoffset = r[:offset] }
      end

      def timezone *args
        super(*args)
        execute('select unix_timestamp() - unix_timestamp(utc_timestamp()) as offset') {|r| @tzoffset = r[:offset] }
        @tzoffset
      end

      def returning?
        false
      end
    end # Mysql

    class Postgres < Adapter
      def initialize options = {}
        super options.update(driver: 'postgresql')
        sql = "select extract(epoch from now())::bigint - extract(epoch from now() at time zone 'UTC')::bigint"
        execute('%s as offset' % sql) {|r| @tzoffset = r[:offset] }
      end

      def timezone *args
        super(*args)
        sql = "select extract(epoch from now())::bigint - extract(epoch from now() at time zone 'UTC')::bigint"
        execute('%s as offset' % sql) {|r| @tzoffset = r[:offset] }
        @tzoffset
      end

      def returning?
        true
      end
    end # Postgres
  end # DB
end # Swift

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
swift-0.4.3 lib/swift/db.rb
swift-0.4.2 lib/swift/db.rb
swift-0.4.1 lib/swift/db.rb