railz_lite 0.2.9 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/railz_lite/models/sql_object.rb +15 -5
- data/lib/railz_lite/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9724d201098c2135958bdc42970c61d03dd14fe5bce5ccf221635bf2a6e2a638
|
4
|
+
data.tar.gz: 8eec203e4ad068df54aebf077ae9aa1187c251a1e82dce7d422ab5e4f81e66db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce5a7bd14989ae937c1c03c7c74aff4ec432179bf0342b9abbc83bd95d5fe676c8db44490f496ae98978fc90ae2ec1c48eaded1a59c1553d5155213aef429ccc
|
7
|
+
data.tar.gz: 5ff0e2ac3fd0fbf2059994c21b7cae7fa62cea045a037b150f556a51fcf50dfee1e6c84fcf3ae2d2d3b8297530ea76db20a8431528cf83e3daa2ede1a86f28c4
|
@@ -65,6 +65,11 @@ module RailzLite
|
|
65
65
|
self.new(target.first)
|
66
66
|
end
|
67
67
|
|
68
|
+
# for insert statements we don't want to include the id field
|
69
|
+
def self.columns_sans_id
|
70
|
+
self.columns.reject { |col| col == :id }
|
71
|
+
end
|
72
|
+
|
68
73
|
def initialize(params = {})
|
69
74
|
params.each do |attr_name, val|
|
70
75
|
name_sym = attr_name.to_sym
|
@@ -81,22 +86,27 @@ module RailzLite
|
|
81
86
|
self.class.columns.map { |attr| send(attr) }
|
82
87
|
end
|
83
88
|
|
89
|
+
# see columns_sans_id
|
90
|
+
def attribute_values_sans_id
|
91
|
+
self.class.columns_sans_id.map { |attr| send(attr) }
|
92
|
+
end
|
93
|
+
|
84
94
|
def insert
|
85
|
-
last_row_id = DBConnection.insert(<<-SQL, *
|
95
|
+
last_row_id = DBConnection.insert(<<-SQL, *attribute_values_sans_id)
|
86
96
|
INSERT INTO
|
87
|
-
#{self.class.table_name}(#{self.class.
|
97
|
+
#{self.class.table_name}(#{self.class.columns_sans_id.join(',')})
|
88
98
|
VALUES
|
89
|
-
(#{(["?"] *
|
99
|
+
(#{(["?"] * attribute_values_sans_id.length).join(',')});
|
90
100
|
SQL
|
91
101
|
self.id = last_row_id
|
92
102
|
end
|
93
103
|
|
94
104
|
def update
|
95
|
-
DBConnection.execute(<<-SQL, *
|
105
|
+
DBConnection.execute(<<-SQL, *attribute_values_sans_id, self.id)
|
96
106
|
UPDATE
|
97
107
|
#{self.class.table_name}
|
98
108
|
SET
|
99
|
-
#{self.class.
|
109
|
+
#{self.class.columns_sans_id.map { |attr_name| "#{attr_name}=?"}.join(',')}
|
100
110
|
WHERE
|
101
111
|
id = ?;
|
102
112
|
SQL
|
data/lib/railz_lite/version.rb
CHANGED