labilerecord 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/labilerecord.rb +14 -4
  2. metadata +1 -1
data/lib/labilerecord.rb CHANGED
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module LabileRecord
5
- VERSION = '0.0.10'
5
+ VERSION = '0.0.11'
6
6
 
7
7
  begin
8
8
  require 'pg'
@@ -81,9 +81,13 @@ module LabileRecord
81
81
  non_nil_column_names << fields[i].name if !column.nil?
82
82
  non_nil_values << column if !column.nil?
83
83
  end
84
- sql += %Q[
85
- #{"INSERT INTO " + table_name.to_s if table_name} (#{ non_nil_column_names.map { |c| quote_object(c) } * "," }) VALUES (#{ non_nil_values.map { |c| quote_value(c, quote) } * "," });
86
- ].strip + "\n"
84
+ sql << %Q[#{"INSERT INTO " + table_name.to_s if table_name} (#{ non_nil_column_names.map { |c| quote_object(c) } * "," })\n]
85
+ sql << "VALUES ("
86
+ non_nil_values.each_with_index do |v, i|
87
+ sql << quote_value(v, quote) + "::" + field_by_name(non_nil_column_names[i]).type
88
+ sql << ',' if i < non_nil_values.length - 1
89
+ end
90
+ sql << ");\n"
87
91
  end
88
92
  sql
89
93
  end
@@ -105,6 +109,12 @@ module LabileRecord
105
109
  rows_sql
106
110
  end
107
111
 
112
+ def field_by_name(name)
113
+ self.fields.each do |field|
114
+ return field if field.name == name
115
+ end
116
+ end
117
+
108
118
  private
109
119
 
110
120
  def quote_value(string, quote="'")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: labilerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alan Da Costa