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 +5 -5
- data/VERSION +1 -1
- data/baza.gemspec +7 -4
- data/lib/baza.rb +1 -1
- data/lib/baza/base_sql_driver.rb +1 -1
- data/lib/baza/database.rb +2 -1
- data/lib/baza/db.rb +1 -1
- data/lib/baza/driver/active_record/result.rb +1 -1
- data/lib/baza/driver/mysql/database.rb +2 -0
- data/lib/baza/driver/mysql/result.rb +10 -27
- data/lib/baza/driver/pg/database.rb +6 -4
- data/lib/baza/driver/tiny.rb +42 -0
- data/lib/baza/driver/tiny/commands.rb +9 -0
- data/lib/baza/driver/tiny/result.rb +9 -0
- data/lib/baza/row.rb +2 -2
- data/spec/support/driver_collection.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cf763d9725a54b1f83dc7fdd00181b8361b150c2ebb266b11ad914c9c3d7cbfa
|
4
|
+
data.tar.gz: 1818e5b131b457a5e8bb7a7e06a23a5261e5f4a2fe9812d3de6bdd10b51dccfa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3668e2de450161e3e616beeb6c2a40a85f870bd0234956e9c5ac949615f9b49e6e51a4c069675c3ec7a69b81e42603307eafb0b0a3d76da8159981dabdd77580
|
7
|
+
data.tar.gz: a3eee544394d088cf4171cfadab545521a91e42d1cb66ed6cf90fb86c95f25163056526311b6678d2b2088c01b2d4f371fb511da38e1a74ff9bcfdf2b6fbd695
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.34
|
data/baza.gemspec
CHANGED
@@ -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.
|
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.
|
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-
|
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.
|
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
|
data/lib/baza.rb
CHANGED
@@ -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
|
data/lib/baza/base_sql_driver.rb
CHANGED
@@ -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.
|
217
|
+
if val.class.name == "Fixnum" || val.is_a?(Integer)
|
218
218
|
val.to_s
|
219
219
|
elsif val == nil
|
220
220
|
"NULL"
|
data/lib/baza/database.rb
CHANGED
@@ -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
|
-
@
|
33
|
+
@name_was
|
33
34
|
end
|
34
35
|
|
35
36
|
def tables(args = {})
|
data/lib/baza/db.rb
CHANGED
@@ -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.
|
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
|
@@ -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
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
-
|
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(
|
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(
|
80
|
-
cloned_conn.query("SELECT pid, pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = #{db.sep_val}#{@db.esc(
|
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
|
data/lib/baza/row.rb
CHANGED
@@ -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].
|
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.
|
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.
|
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-
|
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.
|
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.
|