baza 0.0.33 → 0.0.34

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
- SHA1:
3
- metadata.gz: 1636cb2175a8d3d441067544e5ab2236cffdaf59
4
- data.tar.gz: b435a6ca05bf3a7f0240f0e5bd726a6714c2afaf
2
+ SHA256:
3
+ metadata.gz: cf763d9725a54b1f83dc7fdd00181b8361b150c2ebb266b11ad914c9c3d7cbfa
4
+ data.tar.gz: 1818e5b131b457a5e8bb7a7e06a23a5261e5f4a2fe9812d3de6bdd10b51dccfa
5
5
  SHA512:
6
- metadata.gz: 33ba5182cf87b242e63f700b75d35698ee7a166d41988ac066a50579c899d1f044f057cf4ed7883443693316e7cdf79dfa3b0ecdd7c988815492b91bfbe4f8d5
7
- data.tar.gz: ac1b0ce883e7096a806de147e6baa56be67249b3a1890a453072f3dcb22fc508a446320972d8ff8ed11fa4d1f03d17e7d293d3d8b5cb032b97d7275762aca43c
6
+ metadata.gz: 3668e2de450161e3e616beeb6c2a40a85f870bd0234956e9c5ac949615f9b49e6e51a4c069675c3ec7a69b81e42603307eafb0b0a3d76da8159981dabdd77580
7
+ data.tar.gz: a3eee544394d088cf4171cfadab545521a91e42d1cb66ed6cf90fb86c95f25163056526311b6678d2b2088c01b2d4f371fb511da38e1a74ff9bcfdf2b6fbd695
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.33
1
+ 0.0.34
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: baza 0.0.33 ruby lib
5
+ # stub: baza 0.0.34 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "baza".freeze
9
- s.version = "0.0.33"
9
+ s.version = "0.0.34"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Kasper Johansen".freeze]
14
- s.date = "2018-04-26"
14
+ s.date = "2018-06-07"
15
15
  s.description = "A database abstraction layer, model framework and database framework.".freeze
16
16
  s.email = "kj@gfish.com".freeze
17
17
  s.extra_rdoc_files = [
@@ -137,6 +137,9 @@ Gem::Specification.new do |s|
137
137
  "lib/baza/driver/sqlite3_java/tables.rb",
138
138
  "lib/baza/driver/sqlite3_java/unbuffered_result.rb",
139
139
  "lib/baza/driver/sqlite3_rhodes.rb",
140
+ "lib/baza/driver/tiny.rb",
141
+ "lib/baza/driver/tiny/commands.rb",
142
+ "lib/baza/driver/tiny/result.rb",
140
143
  "lib/baza/dump.rb",
141
144
  "lib/baza/errors.rb",
142
145
  "lib/baza/foreign_key.rb",
@@ -202,7 +205,7 @@ Gem::Specification.new do |s|
202
205
  ]
203
206
  s.homepage = "http://github.com/kaspernj/baza".freeze
204
207
  s.licenses = ["MIT".freeze]
205
- s.rubygems_version = "2.6.13".freeze
208
+ s.rubygems_version = "2.7.7".freeze
206
209
  s.summary = "A database abstraction layer, model framework and database framework.".freeze
207
210
 
208
211
  if s.respond_to? :specification_version then
@@ -54,7 +54,7 @@ class Baza
54
54
  loads = %w(databases database tables table columns column indexes index result commands)
55
55
  loads.each do |load|
56
56
  file_path = "#{File.dirname(__FILE__)}/baza/driver/#{name}/#{load}"
57
- require_relative file_path if File.exist?(file_path)
57
+ require_relative file_path if File.exist?(file_path) || File.exist?("#{file_path}.rb")
58
58
  end
59
59
  end
60
60
  end
@@ -214,7 +214,7 @@ class Baza::BaseSqlDriver
214
214
  # If it is a number, then just the raw number as a string will be returned.
215
215
  # nil's will be NULL and strings will have quotes and will be escaped.
216
216
  def self.sqlval(val)
217
- if val.is_a?(Fixnum) || val.is_a?(Integer)
217
+ if val.class.name == "Fixnum" || val.is_a?(Integer)
218
218
  val.to_s
219
219
  elsif val == nil
220
220
  "NULL"
@@ -20,6 +20,7 @@ class Baza::Database
20
20
  end
21
21
 
22
22
  def name=(new_name)
23
+ @name_was = @name
23
24
  @changes[:name] = new_name
24
25
  @name = new_name
25
26
  end
@@ -29,7 +30,7 @@ class Baza::Database
29
30
  end
30
31
 
31
32
  def name_was
32
- @changes[:name]
33
+ @name_was
33
34
  end
34
35
 
35
36
  def tables(args = {})
@@ -300,7 +300,7 @@ class Baza::Db
300
300
  if @debug
301
301
  print "SQL: #{string}\n"
302
302
 
303
- if @debug.is_a?(Fixnum) && @debug >= 2
303
+ if @debug.class.name == "Fixnum" && @debug >= 2
304
304
  print caller.join("\n")
305
305
  print "\n"
306
306
  end
@@ -14,7 +14,7 @@ class Baza::Driver::ActiveRecord::Result < Baza::ResultBase
14
14
  return unless @result
15
15
 
16
16
  @result.each do |result|
17
- result = result.delete_if { |k, _v| k.is_a?(Fixnum) } # Seems like this happens depending on the version installed? - kaspernj
17
+ result = result.delete_if { |k, _v| k.class.name == "Fixnum" } # Seems like this happens depending on the version installed? - kaspernj
18
18
  result = Hash[result.map { |k, v| [k, v.to_s] }] if @type_translation == :string
19
19
 
20
20
  yield result.symbolize_keys
@@ -59,6 +59,8 @@ class Baza::Driver::Mysql::Database < Baza::Database
59
59
  end
60
60
  end
61
61
 
62
+ private
63
+
62
64
  def rename(new_name)
63
65
  new_name = new_name.to_s
64
66
  @db.databases.create(name: new_name)
@@ -1,23 +1,5 @@
1
1
  # This class controls the results for the normal MySQL-driver.
2
2
  class Baza::Driver::Mysql::Result < Baza::ResultBase
3
- INT_TYPES = {
4
- ::Mysql::Field::TYPE_DECIMAL => true,
5
- ::Mysql::Field::TYPE_TINY => true,
6
- ::Mysql::Field::TYPE_LONG => true,
7
- ::Mysql::Field::TYPE_YEAR => true
8
- }.freeze
9
- FLOAT_TYPES = {
10
- ::Mysql::Field::TYPE_DECIMAL => true,
11
- ::Mysql::Field::TYPE_FLOAT => true,
12
- ::Mysql::Field::TYPE_DOUBLE => true
13
- }.freeze
14
- TIME_TYPES = {
15
- ::Mysql::Field::TYPE_DATETIME => true
16
- }.freeze
17
- DATE_TYPES = {
18
- ::Mysql::Field::TYPE_DATE => true
19
- }.freeze
20
-
21
3
  # Constructor. This should not be called manually.
22
4
  def initialize(driver, result)
23
5
  @driver = driver
@@ -74,16 +56,17 @@ private
74
56
  def translate_value_to_type(value, type_no)
75
57
  return if value == nil
76
58
 
77
- if INT_TYPES[type_no]
78
- return value.to_i
79
- elsif FLOAT_TYPES[type_no]
80
- return value.to_f
81
- elsif TIME_TYPES[type_no]
82
- return Time.parse(value)
83
- elsif DATE_TYPES[type_no]
84
- return Date.parse(value)
59
+ case type_no
60
+ when ::Mysql::Field::TYPE_DECIMAL, ::Mysql::Field::TYPE_TINY, ::Mysql::Field::TYPE_LONG, ::Mysql::Field::TYPE_YEAR
61
+ value.to_i
62
+ when ::Mysql::Field::TYPE_DECIMAL, ::Mysql::Field::TYPE_FLOAT, ::Mysql::Field::TYPE_DOUBLE
63
+ value.to_f
64
+ when ::Mysql::Field::TYPE_DATETIME
65
+ Time.parse(value)
66
+ when ::Mysql::Field::TYPE_DATE
67
+ Date.parse(value)
85
68
  else
86
- return value.to_s
69
+ value.to_s
87
70
  end
88
71
  end
89
72
  end
@@ -1,6 +1,6 @@
1
1
  class Baza::Driver::Pg::Database < Baza::Database
2
2
  def save!
3
- rename(name) unless name.to_s == name_was
3
+ rename(name) unless name.to_s == name_was.to_s
4
4
  self
5
5
  end
6
6
 
@@ -61,9 +61,11 @@ class Baza::Driver::Pg::Database < Baza::Database
61
61
  end
62
62
  end
63
63
 
64
+ private
65
+
64
66
  def rename(new_name)
65
67
  with_cloned_conn_and_terminated_connections do |cloned_conn|
66
- cloned_conn.query("ALTER DATABASE #{db.sep_database}#{db.escape_database(name_was)}#{db.sep_database} RENAME TO #{db.sep_database}#{db.escape_database(new_name)}#{db.sep_database}")
68
+ cloned_conn.query("ALTER DATABASE #{db.sep_database}#{db.escape_database(name_was)}#{db.sep_database} RENAME TO #{db.sep_database}#{db.escape_database(name)}#{db.sep_database}")
67
69
  end
68
70
 
69
71
  @name = new_name.to_s
@@ -76,8 +78,8 @@ class Baza::Driver::Pg::Database < Baza::Database
76
78
  # Drop database through a cloned connection, because Postgres might bug up if dropping the current
77
79
  db.clone_conn(db: other_db.name) do |cloned_conn|
78
80
  # Close existing connections to avoid 'is being accessed by other users' errors
79
- cloned_conn.query("REVOKE CONNECT ON DATABASE #{db.sep_database}#{db.escape_database(name)}#{db.sep_database} FROM public") unless name_changed?
80
- cloned_conn.query("SELECT pid, pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = #{db.sep_val}#{@db.esc(name)}#{db.sep_val} AND pid != pg_backend_pid()")
81
+ cloned_conn.query("REVOKE CONNECT ON DATABASE #{db.sep_database}#{db.escape_database(name_was)}#{db.sep_database} FROM public") unless name_changed?
82
+ cloned_conn.query("SELECT pid, pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = #{db.sep_val}#{@db.esc(name_was)}#{db.sep_val} AND pid != pg_backend_pid()")
81
83
 
82
84
  yield cloned_conn
83
85
  end
@@ -0,0 +1,42 @@
1
+ class Baza::Driver::Tiny < Baza::BaseSqlDriver
2
+ SEPARATOR_DATABASE = "`".freeze
3
+ SEPARATOR_TABLE = "".freeze
4
+ SEPARATOR_COLUMN = "".freeze
5
+ SEPARATOR_VALUE = "'".freeze
6
+ SEPARATOR_INDEX = "`".freeze
7
+
8
+ def initialize(db)
9
+ super
10
+
11
+ @sep_database = SEPARATOR_DATABASE
12
+ @sep_table = SEPARATOR_TABLE
13
+ @sep_col = SEPARATOR_COLUMN
14
+ @sep_val = SEPARATOR_VALUE
15
+ @sep_index = SEPARATOR_INDEX
16
+ end
17
+
18
+ def initialize(db)
19
+ super
20
+ @client = TinyTds::Client.new(username: db.opts.fetch(:user), password: db.opts.fetch(:pass), host: db.opts.fetch(:host))
21
+ end
22
+
23
+ def close
24
+ @client.close
25
+ end
26
+
27
+ def insert(table_name, data, args = {})
28
+ sql = Baza::SqlQueries::GenericInsert.new({
29
+ db: @db,
30
+ table_name: table_name,
31
+ data: data
32
+ }.merge(args)).to_sql
33
+
34
+ result = @client.execute(sql)
35
+ result.insert if args[:return_id]
36
+ end
37
+
38
+ def query(sql)
39
+ result = @client.execute(sql)
40
+ Baza::Driver::Tiny::Result.new(result)
41
+ end
42
+ end
@@ -0,0 +1,9 @@
1
+ class Baza::Driver::Tiny::Commands
2
+ def initialize(db:)
3
+ @db = db
4
+ end
5
+
6
+ def last_id
7
+ @db.query("SELECT SCOPE_IDENTITY() AS id").first.fetch(:id)
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class Baza::Driver::Tiny::Result < Baza::ResultBase
2
+ def initialize(result)
3
+ @result = result.to_a
4
+ end
5
+
6
+ def each(*args, &blk)
7
+ @result.each(*args, &blk)
8
+ end
9
+ end
@@ -16,13 +16,13 @@ class Baza::Row
16
16
  @args[:col_id] ||= :id
17
17
  raise "No table given." unless @args[:table]
18
18
 
19
- if @args[:data] && (@args[:data].is_a?(Integer) || @args[:data].is_a?(Fixnum) || @args[:data].is_a?(String))
19
+ if @args[:data] && (@args[:data].is_a?(Integer) || @args[:data].class.name == "Fixnum" || @args[:data].is_a?(String))
20
20
  @data = {@args[:col_id].to_sym => @args[:data].to_s}
21
21
  reload
22
22
  elsif @args[:data] && @args.fetch(:data).is_a?(Hash)
23
23
  @data = {}
24
24
  @args.fetch(:data).each do |key, value|
25
- key = key.to_sym unless key.is_a?(Fixnum)
25
+ key = key.to_sym unless key.class.name == "Fixnum"
26
26
  @data[key] = value
27
27
  end
28
28
  elsif @args[:id]
@@ -340,7 +340,7 @@ shared_examples_for "a baza driver" do
340
340
  row = db_with_type_translation.select(:test, text: "Kasper").fetch
341
341
 
342
342
  expect(row.fetch(:text).class).to eq String
343
- expect(row.fetch(:number).class).to eq Fixnum
343
+ expect(row.fetch(:number).class.name).to eq "Fixnum"
344
344
  expect(row.fetch(:float).class).to eq Float
345
345
 
346
346
  if db.driver.conn.class.name == "ActiveRecord::ConnectionAdapters::SQLite3Adapter"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baza
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.33
4
+ version: 0.0.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Johansen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-26 00:00:00.000000000 Z
11
+ date: 2018-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: array_enumerator
@@ -430,6 +430,9 @@ files:
430
430
  - lib/baza/driver/sqlite3_java/tables.rb
431
431
  - lib/baza/driver/sqlite3_java/unbuffered_result.rb
432
432
  - lib/baza/driver/sqlite3_rhodes.rb
433
+ - lib/baza/driver/tiny.rb
434
+ - lib/baza/driver/tiny/commands.rb
435
+ - lib/baza/driver/tiny/result.rb
433
436
  - lib/baza/dump.rb
434
437
  - lib/baza/errors.rb
435
438
  - lib/baza/foreign_key.rb
@@ -512,7 +515,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
512
515
  version: '0'
513
516
  requirements: []
514
517
  rubyforge_project:
515
- rubygems_version: 2.6.13
518
+ rubygems_version: 2.7.7
516
519
  signing_key:
517
520
  specification_version: 4
518
521
  summary: A database abstraction layer, model framework and database framework.