labilerecord 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/labilerecord.rb +14 -4
- 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.
|
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
|
85
|
-
|
86
|
-
|
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="'")
|