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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9da64c4f69092de235e6a5c3602a2e6f8fc6be5ac6e3fb88b6621246e8dc3bc4
4
- data.tar.gz: 8c44980e47498b3be67ce7d894d3fe2a7eb8c18335e7fe68b56b74f198fe0cd8
3
+ metadata.gz: 9724d201098c2135958bdc42970c61d03dd14fe5bce5ccf221635bf2a6e2a638
4
+ data.tar.gz: 8eec203e4ad068df54aebf077ae9aa1187c251a1e82dce7d422ab5e4f81e66db
5
5
  SHA512:
6
- metadata.gz: e3b0ffdd0f01715fadc5b5d1a9d1c9cefc5b01295d5b46a1b05c9ff4794b0dc8cd789b96adec8a556602835a7a7cbac57fa38bff8ae18ceef4220afe6c7c3802
7
- data.tar.gz: 56f7965f2bd969c47924b173933566a147d5718d0495d32dc9041afb5dd4c6b44a33d480faee63c972e4ebd03336f4731591d167b6e13bbaf56d054dc1f19dce
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, *attribute_values)
95
+ last_row_id = DBConnection.insert(<<-SQL, *attribute_values_sans_id)
86
96
  INSERT INTO
87
- #{self.class.table_name}(#{self.class.columns.join(',')})
97
+ #{self.class.table_name}(#{self.class.columns_sans_id.join(',')})
88
98
  VALUES
89
- (#{(["?"] * attribute_values.length).join(',')});
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, *attribute_values, self.id)
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.columns.map { |attr_name| "#{attr_name}=?"}.join(',')}
109
+ #{self.class.columns_sans_id.map { |attr_name| "#{attr_name}=?"}.join(',')}
100
110
  WHERE
101
111
  id = ?;
102
112
  SQL
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailzLite
4
- VERSION = "0.2.9"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railz_lite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bryan lynch