baza 0.0.35 → 0.0.36

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +14 -17
  4. data/VERSION +1 -1
  5. data/baza.gemspec +8 -7
  6. data/lib/baza/base_sql_driver.rb +38 -8
  7. data/lib/baza/cloner.rb +10 -0
  8. data/lib/baza/commands/select.rb +15 -8
  9. data/lib/baza/db.rb +8 -4
  10. data/lib/baza/driver/active_record.rb +7 -0
  11. data/lib/baza/driver/mysql/column.rb +4 -6
  12. data/lib/baza/driver/mysql/columns.rb +4 -4
  13. data/lib/baza/driver/mysql/database.rb +4 -4
  14. data/lib/baza/driver/mysql/databases.rb +3 -3
  15. data/lib/baza/driver/mysql/foreign_key.rb +2 -2
  16. data/lib/baza/driver/mysql/index.rb +1 -1
  17. data/lib/baza/driver/mysql/sql/column.rb +4 -4
  18. data/lib/baza/driver/mysql/sql/create_indexes.rb +3 -3
  19. data/lib/baza/driver/mysql/sql/create_table.rb +1 -1
  20. data/lib/baza/driver/mysql/table.rb +16 -16
  21. data/lib/baza/driver/mysql_java.rb +3 -3
  22. data/lib/baza/driver/pg/column.rb +5 -13
  23. data/lib/baza/driver/pg/columns.rb +4 -4
  24. data/lib/baza/driver/pg/create_index_sql_creator.rb +3 -3
  25. data/lib/baza/driver/pg/database.rb +4 -4
  26. data/lib/baza/driver/pg/databases.rb +1 -1
  27. data/lib/baza/driver/pg/foreign_key.rb +2 -2
  28. data/lib/baza/driver/pg/index.rb +1 -1
  29. data/lib/baza/driver/pg/table.rb +9 -9
  30. data/lib/baza/driver/pg/tables.rb +1 -1
  31. data/lib/baza/driver/sqlite3/column.rb +1 -1
  32. data/lib/baza/driver/sqlite3/columns.rb +1 -1
  33. data/lib/baza/driver/sqlite3/index.rb +1 -1
  34. data/lib/baza/driver/sqlite3/table.rb +4 -4
  35. data/lib/baza/driver/tiny.rb +83 -8
  36. data/lib/baza/driver/tiny/result.rb +18 -2
  37. data/lib/baza/idquery.rb +3 -3
  38. data/lib/baza/mysql_base_driver.rb +3 -3
  39. data/lib/baza/sql_queries/generic_insert.rb +3 -3
  40. data/lib/baza/sql_queries/generic_update.rb +2 -2
  41. data/lib/baza/sql_queries/mysql_upsert.rb +5 -5
  42. data/lib/baza/sql_queries/mysql_upsert_duplicate_key.rb +3 -3
  43. data/lib/baza/sql_queries/postgres_upsert_duplicate_key.rb +7 -7
  44. data/lib/baza/sql_queries/select.rb +8 -8
  45. data/lib/baza/sql_queries/sqlite_upsert_duplicate_key.rb +6 -6
  46. data/lib/baza/table.rb +3 -3
  47. data/spec/baza/cloner_spec.rb +2 -2
  48. data/spec/drivers/tiny_spec.rb +27 -0
  49. data/spec/info_active_record_pg_peak_flow.rb +2 -2
  50. data/spec/info_active_record_sqlite3.rb +6 -13
  51. data/spec/info_sqlite3.rb +3 -12
  52. metadata +8 -7
@@ -51,7 +51,7 @@ private
51
51
  end
52
52
 
53
53
  def insert_sql
54
- sql = "INSERT OR IGNORE INTO #{@db.sep_table}#{@db.escape_table(@table_name)}#{@db.sep_table} ("
54
+ sql = "INSERT OR IGNORE INTO #{@db.quote_table(@table_name)} ("
55
55
 
56
56
  combined_data = @updates.merge(@terms)
57
57
 
@@ -59,7 +59,7 @@ private
59
59
  combined_data.each_key do |column_name|
60
60
  sql << ", " unless first
61
61
  first = false if first
62
- sql << "#{@db.sep_col}#{@db.escape_column(column_name)}#{@db.sep_col}"
62
+ sql << @db.quote_column(column_name)
63
63
  end
64
64
 
65
65
  sql << ") VALUES ("
@@ -68,7 +68,7 @@ private
68
68
  combined_data.each_value do |value|
69
69
  sql << ", " unless first
70
70
  first = false if first
71
- sql << @db.sqlval(value).to_s
71
+ sql << @db.quote_value(value).to_s
72
72
  end
73
73
 
74
74
  sql << ")"
@@ -76,13 +76,13 @@ private
76
76
  end
77
77
 
78
78
  def update_sql
79
- sql = "UPDATE OR IGNORE #{@db.sep_table}#{@db.escape_table(@table_name)}#{@db.sep_table} SET "
79
+ sql = "UPDATE OR IGNORE #{@db.quote_table(@table_name)} SET "
80
80
 
81
81
  first = true
82
82
  @updates.each do |key, value|
83
83
  sql << ", " unless first
84
84
  first = false if first
85
- sql << "#{@db.sep_col}#{@db.escape_column(key)}#{@db.sep_col} = #{@db.sqlval(value)}"
85
+ sql << "#{@db.quote_column(key)} = #{@db.quote_value(value)}"
86
86
  end
87
87
 
88
88
  sql << " WHERE "
@@ -91,7 +91,7 @@ private
91
91
  @terms.each do |key, value|
92
92
  sql << " AND " unless first
93
93
  first = false if first
94
- sql << "#{@db.sep_col}#{@db.escape_column(key)}#{@db.sep_col} = #{@db.sqlval(value)}"
94
+ sql << "#{@db.quote_column(key)} = #{@db.quote_value(value)}"
95
95
  end
96
96
 
97
97
  sql
@@ -43,12 +43,12 @@ class Baza::Table
43
43
  end
44
44
 
45
45
  def rows_count
46
- sql = "SELECT COUNT(*) AS count FROM #{@db.sep_table}#{@db.escape_table(name)}#{@db.sep_table}"
46
+ sql = "SELECT COUNT(*) AS count FROM #{db.quote_table(name)}"
47
47
  @db.query(sql).fetch.fetch(:count).to_i
48
48
  end
49
49
 
50
50
  def truncate
51
- @db.query("TRUNCATE #{@db.sep_table}#{@db.escape_table(name)}#{@db.sep_table}")
51
+ @db.query("TRUNCATE #{@db.quote_table(name)}")
52
52
  self
53
53
  end
54
54
 
@@ -60,7 +60,7 @@ class Baza::Table
60
60
 
61
61
  def create_columns(col_arr)
62
62
  col_arr.each do |col_data|
63
- sql = "ALTER TABLE #{db.sep_col}#{name}#{db.sep_col} ADD COLUMN #{@db.columns.data_sql(col_data)};"
63
+ sql = "ALTER TABLE #{db.quote_column(name)} ADD COLUMN #{@db.columns.data_sql(col_data)};"
64
64
  @db.query(sql)
65
65
  end
66
66
  end
@@ -2,8 +2,8 @@ require "spec_helper"
2
2
 
3
3
  describe Baza::Cloner do
4
4
  it "can clone drivers" do
5
- require "info_active_record_mysql2"
6
- conn = Baza::InfoActiveRecordMysql2.connection
5
+ require "info_active_record_pg"
6
+ conn = Baza::InfoActiveRecordPg.connection
7
7
  baza_db = Baza::Cloner.from_active_record_connection(conn[:conn])
8
8
  expect(baza_db.query("SELECT 1 AS test").fetch[:test].to_s).to eq "1"
9
9
  end
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+
3
+ describe Baza::Driver::Tiny do
4
+ describe "#quote_database" do
5
+ it "quotes the given database name" do
6
+ expect(Baza::Driver::Tiny.quote_database("test_database")).to eq "[test_database]"
7
+ end
8
+ end
9
+
10
+ describe "#quote_column" do
11
+ it "quotes the given column name" do
12
+ expect(Baza::Driver::Tiny.quote_column("test_column")).to eq "[test_column]"
13
+ end
14
+ end
15
+
16
+ describe "#quote_index" do
17
+ it "quotes the given index name" do
18
+ expect(Baza::Driver::Tiny.quote_index("test_index")).to eq "[test_index]"
19
+ end
20
+ end
21
+
22
+ describe "#quote_table" do
23
+ it "quotes the given table name" do
24
+ expect(Baza::Driver::Tiny.quote_table("test_table")).to eq "[test_table]"
25
+ end
26
+ end
27
+ end
@@ -5,12 +5,12 @@ class Baza::InfoActiveRecordPg
5
5
  require "active_record"
6
6
  require "pg"
7
7
 
8
- @conn_pool ||= ::ActiveRecord::Base.establish_connection(
8
+ @conn_pool = ::ActiveRecord::Base.establish_connection(
9
9
  adapter: "postgresql",
10
10
  database: "baza",
11
11
  username: "postgres"
12
12
  )
13
- @conn ||= @conn_pool.connection
13
+ @conn = @conn_pool.connection
14
14
 
15
15
  {pool: @conn_pool, conn: @conn}
16
16
  end
@@ -4,16 +4,13 @@ class Baza::InfoActiveRecordSqlite3
4
4
  def self.connection
5
5
  require "active_record"
6
6
 
7
- path = "#{Dir.tmpdir}/baza_sqlite3_test_#{Time.now.to_f.to_s.hash}_#{Random.rand}.sqlite3"
8
- File.unlink(path) if File.exist?(path)
9
-
10
- @conn_pool ||= ::ActiveRecord::Base.establish_connection(
7
+ conn_pool = ::ActiveRecord::ConnectionAdapters::ConnectionHandler.new.establish_connection(
11
8
  adapter: "sqlite3",
12
- database: path
9
+ database: ":memory:"
13
10
  )
14
- @conn ||= @conn_pool.connection
11
+ conn = conn_pool.connection
15
12
 
16
- {pool: @conn_pool, conn: @conn}
13
+ {pool: conn_pool, conn: conn}
17
14
  end
18
15
 
19
16
  def initialize(args = {})
@@ -26,11 +23,7 @@ class Baza::InfoActiveRecordSqlite3
26
23
  }.merge(args))
27
24
  end
28
25
 
29
- def before
30
- @db.tables.list(&:drop)
31
- end
26
+ def before; end
32
27
 
33
- def after
34
- @db.close
35
- end
28
+ def after; end
36
29
  end
@@ -3,26 +3,17 @@ class Baza::InfoSqlite3
3
3
 
4
4
  def initialize(args = {})
5
5
  require "sqlite3" unless RUBY_ENGINE == "jruby"
6
- require "tmpdir"
7
-
8
- @path = "#{Dir.tmpdir}/baza_sqlite3_test_#{Time.now.to_f.to_s.hash}_#{Random.rand}.sqlite3"
9
- File.unlink(path) if File.exist?(@path)
10
6
 
11
7
  @db = Baza::Db.new({
12
8
  type: :sqlite3,
13
- path: @path,
9
+ path: ":memory:",
14
10
  index_append_table_name: true,
15
11
  sql_to_error: true,
16
12
  debug: false
17
13
  }.merge(args))
18
14
  end
19
15
 
20
- def before
21
- @db.tables.list(&:drop)
22
- end
16
+ def before; end
23
17
 
24
- def after
25
- @db.close
26
- File.unlink(@path)
27
- end
18
+ def after; end
28
19
  end
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.35
4
+ version: 0.0.36
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-06-07 00:00:00.000000000 Z
11
+ date: 2018-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: array_enumerator
@@ -112,16 +112,16 @@ dependencies:
112
112
  name: activerecord
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: 4.2.5
117
+ version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: 4.2.5
124
+ version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: activerecord-jdbc-adapter
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -470,6 +470,7 @@ files:
470
470
  - spec/drivers/pg/columns_spec.rb
471
471
  - spec/drivers/pg_spec.rb
472
472
  - spec/drivers/sqlite3_spec.rb
473
+ - spec/drivers/tiny_spec.rb
473
474
  - spec/info_active_record_example.rb
474
475
  - spec/info_active_record_mysql2_example.rb
475
476
  - spec/info_active_record_mysql2_peak_flow.rb
@@ -515,7 +516,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
515
516
  version: '0'
516
517
  requirements: []
517
518
  rubyforge_project:
518
- rubygems_version: 2.7.7
519
+ rubygems_version: 2.6.14
519
520
  signing_key:
520
521
  specification_version: 4
521
522
  summary: A database abstraction layer, model framework and database framework.