Sha256: b85be068a376335d3840753a9fbb5ce0cbc8c538b92ab31ff31ba1e36dcaa601

Contents?: true

Size: 1.77 KB

Versions: 2

Compression:

Stored size: 1.77 KB

Contents

module Swift
  module DB
    class Mysql < Adapter
      def initialize options = {}
        super options.update(driver: 'mysql')
      end

      def returning?
        false
      end
    end # Mysql

    class Postgres < Adapter
      def initialize options = {}
        super options.update(driver: 'postgresql')
      end

      def returning?
        true
      end

      def field_type attribute
        case attribute
          when Type::IO then 'bytea'
          else super
        end
      end
    end # Postgres

    class DB2 < Adapter
      def initialize options = {}
        super options.update(driver: 'db2')
      end

      def returning?
        false
      end

      def drop_store name
        exists_sql =<<-SQL
          select count(*) as exists from syscat.tables where tabschema = CURRENT_SCHEMA and tabname = '#{name.upcase}'
        SQL

        execute(exists_sql.strip) do |r|
          execute("drop table #{name}") if r[:exists] > 0
        end
      end

      def field_type attribute
        case attribute
          when Type::String     then 'clob(2g)'
          when Type::Integer    then attribute.serial ? 'integer not null generated by default as identity' : 'integer'
          when Type::Boolean    then 'char(1)'
          when Type::Float      then 'real'
          when Type::BigDecimal then 'double'
          else super
        end
      end

      def prepare_create scheme
        prepare_cached(scheme, :create) do
          values = (['?'] * scheme.header.insertable.size).join(', ')
          sql    = "insert into #{scheme.store} (#{scheme.header.insertable.join(', ')}) values (#{values})"
          scheme.header.serial ? "select #{scheme.header.serial} from final table (#{sql})" : sql
        end
      end
    end # DB2
  end # DB
end # Swift

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
swift-0.7.1 lib/swift/db.rb
swift-0.7.0 lib/swift/db.rb