lib/swift/adapter.rb in swift-0.6.1 vs lib/swift/adapter.rb in swift-0.7.0
- old
+ new
@@ -51,14 +51,18 @@
def migrate! scheme
keys = scheme.header.keys
fields = scheme.header.map{|p| field_definition(p)}.join(', ')
fields += ", primary key (#{keys.join(', ')})" unless keys.empty?
- execute("drop table if exists #{scheme.store}")
+ drop_store scheme.store
execute("create table #{scheme.store} (#{fields})")
end
+ def drop_store name
+ execute("drop table if exists #{name}")
+ end
+
protected
def exchange_names scheme, query
query.gsub(/:(\w+)/){ scheme.send($1.to_sym).field }
end
@@ -100,15 +104,20 @@
"delete from #{scheme.store} where #{where}"
end
end
def field_definition attribute
- "#{attribute.field} " + case attribute
+ "#{attribute.field} " + field_type(attribute)
+ end
+
+ def field_type attribute
+ case attribute
when Type::String then 'text'
when Type::Integer then attribute.serial ? 'serial' : 'integer'
when Type::Float then 'float'
when Type::BigDecimal then 'numeric'
- when Type::DateTime then 'timestamp'
+ when Type::Time then 'timestamp'
+ when Type::Date then 'date'
when Type::Boolean then 'boolean'
when Type::IO then 'blob'
else 'text'
end
end