baza 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/baza.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "baza"
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kasper Johansen"]
data/include/db.rb CHANGED
@@ -277,7 +277,7 @@ class Baza::Db
277
277
  # id = db.insert(:users, {:name => "John", :lastname => "Doe"}, :return_id => true)
278
278
  # sql = db.insert(:users, {:name => "John", :lastname => "Doe"}, :return_sql => true) #=> "INSERT INTO `users` (`name`, `lastname`) VALUES ('John', 'Doe')"
279
279
  def insert(tablename, arr_insert, args = nil)
280
- sql = "INSERT INTO #{@sep_table}#{tablename}#{@sep_table}"
280
+ sql = "INSERT INTO #{@sep_table}#{self.esc_table(tablename)}#{@sep_table}"
281
281
 
282
282
  if !arr_insert or arr_insert.empty?
283
283
  #This is the correct syntax for inserting a blank row in MySQL.
@@ -299,7 +299,7 @@ class Baza::Db
299
299
  sql << ", "
300
300
  end
301
301
 
302
- sql << "#{@sep_col}#{key}#{@sep_col}"
302
+ sql << "#{@sep_col}#{self.esc_col(key)}#{@sep_col}"
303
303
  end
304
304
 
305
305
  sql << ") VALUES ("
@@ -401,15 +401,15 @@ class Baza::Db
401
401
  #
402
402
  #===Examples
403
403
  # db.update(:users, {:name => "John"}, {:lastname => "Doe"})
404
- def update(tablename, arr_update, arr_terms = {}, args = nil)
405
- raise "'arr_update' was not a hash." if !arr_update.is_a?(Hash)
406
- return false if arr_update.empty?
404
+ def update(tablename, hash_update, arr_terms = {}, args = nil)
405
+ raise "'hash_update' was not a hash: '#{hash_update.class.name}'." if !hash_update.is_a?(Hash)
406
+ return false if hash_update.empty?
407
407
 
408
408
  sql = ""
409
409
  sql << "UPDATE #{@sep_col}#{tablename}#{@sep_col} SET "
410
410
 
411
411
  first = true
412
- arr_update.each do |key, value|
412
+ hash_update.each do |key, value|
413
413
  if first
414
414
  first = false
415
415
  else
@@ -419,8 +419,8 @@ class Baza::Db
419
419
  #Convert dates to valid dbstr.
420
420
  value = self.date_out(value) if value.is_a?(Datet) or value.is_a?(Time)
421
421
 
422
- sql << "#{@sep_col}#{key}#{@sep_col} = "
423
- sql << "#{@sep_val}#{@esc_driver.escape(value)}#{@sep_val}"
422
+ sql << "#{@sep_col}#{self.esc_col(key)}#{@sep_col} = "
423
+ sql << self.sqlval(value)
424
424
  end
425
425
 
426
426
  if arr_terms and arr_terms.length > 0
@@ -564,7 +564,7 @@ class Baza::Db
564
564
  elsif value.is_a?(Hash)
565
565
  raise "Dont know how to handle hash."
566
566
  else
567
- sql << "#{@sep_col}#{key}#{@sep_col} = #{@sep_val}#{@esc_driver.escape(value)}#{@sep_val}"
567
+ sql << "#{@sep_col}#{key}#{@sep_col} = #{self.sqlval(value)}"
568
568
  end
569
569
  end
570
570
 
@@ -9,7 +9,7 @@ class Baza::Driver::Sqlite3
9
9
  return {
10
10
  :type => :success,
11
11
  :args => {
12
- :type => "sqlite3",
12
+ :type => :sqlite3,
13
13
  :conn => args[:object]
14
14
  }
15
15
  }
data/include/model.rb CHANGED
@@ -870,4 +870,14 @@ class Baza::Model
870
870
  return obj.name(*args)
871
871
  end
872
872
  end
873
+
874
+ #Returns a hash reflection the current ActiveRecord model and its current values (not like .attributes which reflects the old values).
875
+ def self.activerecord_to_hash(model)
876
+ attrs = {}
877
+ model.attribute_names.each do |name|
878
+ attrs[name] = model.__send__(name)
879
+ end
880
+
881
+ return attrs
882
+ end
873
883
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baza
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -218,7 +218,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
218
218
  version: '0'
219
219
  segments:
220
220
  - 0
221
- hash: 452471857234570099
221
+ hash: -3309657141000385200
222
222
  required_rubygems_version: !ruby/object:Gem::Requirement
223
223
  none: false
224
224
  requirements: