baza 0.0.24 → 0.0.25

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ca360eb0771fa4e40e286f2693d2e2957b9ee44
4
- data.tar.gz: f9e91f37f01b60f6333fa1561d907c3ab7759d24
3
+ metadata.gz: a08442b27108efbaf692c8672da32fb95e0fb554
4
+ data.tar.gz: f975c643812141118d9767aaea21b265143a1ca8
5
5
  SHA512:
6
- metadata.gz: ffbb2c02f6d404ceb64d4ebf7dca19f5a31d43e5fcfd0f43aac60fa42d61d459fb285c2308ec477f2ad8383cd7c2e8a2eac6746716e338841db2677608b1e448
7
- data.tar.gz: ad1a9f018bed9a0e3ed570a2058d28ee6c83fa43ba821fe3f3b55de458cbde5f40685c5a21a4cbc0f4265f92f0ba9e376a348e0ab03ca3a824b0613a8510747b
6
+ metadata.gz: 5b82757ce77e2333b61a881c73c2ef0b0a384d2ada12376caa84e749c887608297f16816a958b56d095e5d3470d5bad693b9d429264466361eb4fa6d82848471
7
+ data.tar.gz: 661c572c592445928abd4c1dd9d23f38d8b6275abfd4e3646dff24adc7d6fb4ae91cc790d04893558d20d2670288123d05a0d9060b3487783098c5c666810c79
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.24
1
+ 0.0.25
data/baza.gemspec CHANGED
@@ -2,11 +2,11 @@
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.24 ruby lib
5
+ # stub: baza 0.0.25 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "baza".freeze
9
- s.version = "0.0.24"
9
+ s.version = "0.0.25"
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]
@@ -38,6 +38,7 @@ Gem::Specification.new do |s|
38
38
  "lib/baza/cloner.rb",
39
39
  "lib/baza/column.rb",
40
40
  "lib/baza/commands.rb",
41
+ "lib/baza/commands/importer.rb",
41
42
  "lib/baza/commands/select.rb",
42
43
  "lib/baza/database.rb",
43
44
  "lib/baza/database_model.rb",
@@ -185,6 +186,7 @@ Gem::Specification.new do |s|
185
186
  "spec/support/driver_columns_collection.rb",
186
187
  "spec/support/driver_databases_collection.rb",
187
188
  "spec/support/driver_foreign_keys_collection.rb",
189
+ "spec/support/driver_importer_collection.rb",
188
190
  "spec/support/driver_indexes_collection.rb",
189
191
  "spec/support/driver_tables_collection.rb",
190
192
  "spec/support/driver_users_collection.rb"
@@ -0,0 +1,31 @@
1
+ class Baza::Commands::Importer
2
+ def initialize(args)
3
+ @db = args.fetch(:db)
4
+ @debug = args[:debug]
5
+ @io = args.fetch(:io)
6
+ end
7
+
8
+ def execute
9
+ sql = ""
10
+
11
+ @io.each_line do |line|
12
+ next if line.strip.blank?
13
+ next if line.start_with?("--")
14
+
15
+ debug "Add line to SQL: #{line}" if @debug
16
+ sql << line
17
+
18
+ next unless line.end_with?(";\n")
19
+
20
+ debug "Execute SQL: #{sql}" if @debug
21
+ @db.query(sql)
22
+ sql = ""
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def debug(message)
29
+ puts message if @debug
30
+ end
31
+ end
data/lib/baza/database.rb CHANGED
@@ -11,6 +11,14 @@ class Baza::Database
11
11
  @name_was = @name
12
12
  end
13
13
 
14
+ def import_file!(path)
15
+ File.open(path, "r") do |io|
16
+ use do
17
+ Baza::Commands::Importer.new(db: @db, io: io).execute
18
+ end
19
+ end
20
+ end
21
+
14
22
  def tables(args = {})
15
23
  list_args = {database: name}
16
24
  list_args[:name] = args.fetch(:name) if args[:name]
@@ -13,6 +13,24 @@ class Baza::Driver::Pg::Table < Baza::Table
13
13
  end
14
14
  end
15
15
 
16
+ def data
17
+ ret = {
18
+ name: name,
19
+ columns: [],
20
+ indexes: []
21
+ }
22
+
23
+ columns do |column|
24
+ ret[:columns] << column.data
25
+ end
26
+
27
+ indexes do |index|
28
+ ret[:indexes] << index.data
29
+ end
30
+
31
+ ret
32
+ end
33
+
16
34
  def database_name
17
35
  @data.fetch(:table_catalog)
18
36
  end
@@ -17,5 +17,6 @@ unless RUBY_PLATFORM == "java"
17
17
  it_should_behave_like "a baza indexes driver"
18
18
  it_should_behave_like "a baza users driver"
19
19
  it_should_behave_like "an active record driver"
20
+ it_should_behave_like "a baza importer driver"
20
21
  end
21
22
  end
@@ -15,4 +15,5 @@ describe Baza::Driver::ActiveRecord do
15
15
  it_should_behave_like "a baza indexes driver"
16
16
  it_should_behave_like "a baza users driver"
17
17
  it_should_behave_like "an active record driver"
18
+ it_should_behave_like "a baza importer driver"
18
19
  end
@@ -17,5 +17,6 @@ unless RUBY_PLATFORM == "java"
17
17
  it_should_behave_like "a baza foreign keys driver"
18
18
  it_should_behave_like "a baza indexes driver"
19
19
  it_should_behave_like "an active record driver"
20
+ it_should_behave_like "a baza importer driver"
20
21
  end
21
22
  end
@@ -14,4 +14,5 @@ describe Baza::Driver::ActiveRecord do
14
14
  it_should_behave_like "a baza columns driver"
15
15
  it_should_behave_like "a baza indexes driver"
16
16
  it_should_behave_like "an active record driver"
17
+ it_should_behave_like "a baza importer driver"
17
18
  end
@@ -15,4 +15,5 @@ describe Baza::Driver::Mysql2 do
15
15
  it_should_behave_like "a baza foreign keys driver"
16
16
  it_should_behave_like "a baza indexes driver"
17
17
  it_should_behave_like "a baza users driver"
18
+ it_should_behave_like "a baza importer driver"
18
19
  end
@@ -15,6 +15,7 @@ describe Baza.const_get(:Driver).const_get(:Mysql) do
15
15
  it_should_behave_like "a baza foreign keys driver"
16
16
  it_should_behave_like "a baza indexes driver"
17
17
  it_should_behave_like "a baza users driver"
18
+ it_should_behave_like "a baza importer driver"
18
19
 
19
20
  it "should dump to sqlite3" do
20
21
  require "info_sqlite3"
@@ -15,5 +15,6 @@ unless RUBY_PLATFORM == "java"
15
15
  it_should_behave_like "a baza columns driver"
16
16
  it_should_behave_like "a baza foreign keys driver"
17
17
  it_should_behave_like "a baza indexes driver"
18
+ it_should_behave_like "a baza importer driver"
18
19
  end
19
20
  end
@@ -12,6 +12,7 @@ describe Baza::Driver::Sqlite3 do
12
12
  it_should_behave_like "a baza tables driver"
13
13
  it_should_behave_like "a baza columns driver"
14
14
  it_should_behave_like "a baza indexes driver"
15
+ it_should_behave_like "a baza importer driver"
15
16
 
16
17
  it "should copy database structure and data" do
17
18
  require "info_sqlite3"
@@ -0,0 +1,38 @@
1
+ shared_examples_for "a baza importer driver" do
2
+ let(:driver) { constant.new(debug: false) }
3
+ let(:db) { driver.db }
4
+ let(:test_table) do
5
+ db.tables.create(
6
+ "test",
7
+ columns: [
8
+ {name: "id", type: :int, autoincr: true, primarykey: true},
9
+ {name: "text", type: :varchar}
10
+ ]
11
+ )
12
+ db.tables[:test]
13
+ end
14
+
15
+ before do
16
+ driver.before
17
+ end
18
+
19
+ after do
20
+ driver.after
21
+ end
22
+
23
+ it "imports sql" do
24
+ test_table
25
+
26
+ io = StringIO.new
27
+ dumper = Baza::Dump.new(db: db)
28
+ dumper.dump(io)
29
+ io.rewind
30
+
31
+ test_table.drop
32
+
33
+ importer = Baza::Commands::Importer.new(db: db, io: io)
34
+ importer.execute
35
+
36
+ expect(db.tables[:test].name).to eq "test"
37
+ end
38
+ 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.24
4
+ version: 0.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Johansen
@@ -345,6 +345,7 @@ files:
345
345
  - lib/baza/cloner.rb
346
346
  - lib/baza/column.rb
347
347
  - lib/baza/commands.rb
348
+ - lib/baza/commands/importer.rb
348
349
  - lib/baza/commands/select.rb
349
350
  - lib/baza/database.rb
350
351
  - lib/baza/database_model.rb
@@ -492,6 +493,7 @@ files:
492
493
  - spec/support/driver_columns_collection.rb
493
494
  - spec/support/driver_databases_collection.rb
494
495
  - spec/support/driver_foreign_keys_collection.rb
496
+ - spec/support/driver_importer_collection.rb
495
497
  - spec/support/driver_indexes_collection.rb
496
498
  - spec/support/driver_tables_collection.rb
497
499
  - spec/support/driver_users_collection.rb