baza 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6b59d710af6cacaf585d14ba20a3f269909c1c5c
4
+ data.tar.gz: 6788d6b19dd3cac5f820e59e9ba2714269a8630d
5
+ SHA512:
6
+ metadata.gz: 4d0f1a4cf4f7d8f7825753099395983f2d031b2c963f822b8ecbea39badd2d668ef32f20fdd1bd235a8f82048b610a0e0bbdb7d0bb96b2d8a2d3318eb2db5f75
7
+ data.tar.gz: 5ba4b78729f00c40b30e60095a133ed6254557f044880ee55aa8d27d3e8a75b89928f07ad3d5bbf0887d852d9b7f03f623610fc8f369daf56a43faca1200cee3
data/Gemfile CHANGED
@@ -12,10 +12,13 @@ gem "string-cases"
12
12
  # Add dependencies to develop your gem here.
13
13
  # Include everything needed to run rake, tests, features, etc.
14
14
  group :development do
15
- gem "rspec", "~> 2.8.0"
16
- gem "rdoc", "~> 3.12"
17
- gem "bundler", ">= 1.0.0"
18
- gem "jeweler", "~> 1.8.4"
15
+ gem "rspec"
16
+ gem "rdoc"
17
+ gem "bundler"
18
+ gem "jeweler"
19
19
  gem "sqlite3"
20
20
  gem "mysql2"
21
+ gem "activerecord"
21
22
  end
23
+
24
+ gem "codeclimate-test-reporter", group: :test, require: nil
data/Gemfile.lock CHANGED
@@ -1,54 +1,76 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- addressable (2.3.5)
4
+ activemodel (4.1.6)
5
+ activesupport (= 4.1.6)
6
+ builder (~> 3.1)
7
+ activerecord (4.1.6)
8
+ activemodel (= 4.1.6)
9
+ activesupport (= 4.1.6)
10
+ arel (~> 5.0.0)
11
+ activesupport (4.1.6)
12
+ i18n (~> 0.6, >= 0.6.9)
13
+ json (~> 1.7, >= 1.7.7)
14
+ minitest (~> 5.1)
15
+ thread_safe (~> 0.1)
16
+ tzinfo (~> 1.1)
17
+ addressable (2.3.6)
18
+ arel (5.0.1.20140414130214)
5
19
  array_enumerator (0.0.3)
6
20
  builder (3.2.2)
21
+ codeclimate-test-reporter (0.4.1)
22
+ simplecov (>= 0.7.1, < 1.0.0)
7
23
  datet (0.0.25)
8
- diff-lcs (1.1.3)
9
- faraday (0.8.8)
10
- multipart-post (~> 1.2.0)
11
- git (1.2.6)
12
- github_api (0.10.1)
13
- addressable
14
- faraday (~> 0.8.1)
15
- hashie (>= 1.2)
16
- multi_json (~> 1.4)
17
- nokogiri (~> 1.5.2)
24
+ descendants_tracker (0.0.4)
25
+ thread_safe (~> 0.3, >= 0.3.1)
26
+ diff-lcs (1.2.5)
27
+ docile (1.1.5)
28
+ faraday (0.9.0)
29
+ multipart-post (>= 1.2, < 3)
30
+ git (1.2.8)
31
+ github_api (0.12.1)
32
+ addressable (~> 2.3)
33
+ descendants_tracker (~> 0.0.4)
34
+ faraday (~> 0.8, < 0.10)
35
+ hashie (>= 3.2)
36
+ multi_json (>= 1.7.5, < 2.0)
37
+ nokogiri (~> 1.6.3)
18
38
  oauth2
19
- hashie (2.0.5)
20
- highline (1.6.19)
21
- http2 (0.0.22)
22
- httpauth (0.2.0)
23
- jeweler (1.8.7)
39
+ hashie (3.3.1)
40
+ highline (1.6.21)
41
+ http2 (0.0.26)
42
+ string-cases
43
+ i18n (0.6.11)
44
+ jeweler (2.0.1)
24
45
  builder
25
- bundler (~> 1.0)
46
+ bundler (>= 1.0)
26
47
  git (>= 1.2.5)
27
- github_api (= 0.10.1)
48
+ github_api
28
49
  highline (>= 1.6.15)
29
- nokogiri (= 1.5.10)
50
+ nokogiri (>= 1.5.10)
30
51
  rake
31
52
  rdoc
32
- json (1.8.0)
33
- jwt (0.1.8)
34
- multi_json (>= 1.5)
35
- knjrbfw (0.0.107)
53
+ json (1.8.1)
54
+ jwt (1.0.0)
55
+ knjrbfw (0.0.110)
36
56
  datet
37
57
  http2
38
58
  php4r
39
59
  ruby_process
40
60
  tsafe
41
61
  wref
42
- multi_json (1.7.9)
62
+ mini_portile (0.6.0)
63
+ minitest (5.4.2)
64
+ multi_json (1.10.1)
43
65
  multi_xml (0.5.5)
44
- multipart-post (1.2.0)
45
- mysql2 (0.3.13)
46
- nokogiri (1.5.10)
47
- oauth2 (0.9.2)
48
- faraday (~> 0.8)
49
- httpauth (~> 0.2)
50
- jwt (~> 0.1.4)
51
- multi_json (~> 1.0)
66
+ multipart-post (2.0.0)
67
+ mysql2 (0.3.16)
68
+ nokogiri (1.6.3.1)
69
+ mini_portile (= 0.6.0)
70
+ oauth2 (1.0.0)
71
+ faraday (>= 0.8, < 0.10)
72
+ jwt (~> 1.0)
73
+ multi_json (~> 1.3)
52
74
  multi_xml (~> 0.5)
53
75
  rack (~> 1.2)
54
76
  php4r (0.0.4)
@@ -56,38 +78,52 @@ GEM
56
78
  http2
57
79
  string-strtr
58
80
  rack (1.5.2)
59
- rake (10.1.0)
60
- rdoc (3.12.2)
81
+ rake (10.3.2)
82
+ rdoc (4.1.2)
61
83
  json (~> 1.4)
62
- rspec (2.8.0)
63
- rspec-core (~> 2.8.0)
64
- rspec-expectations (~> 2.8.0)
65
- rspec-mocks (~> 2.8.0)
66
- rspec-core (2.8.0)
67
- rspec-expectations (2.8.0)
68
- diff-lcs (~> 1.1.2)
69
- rspec-mocks (2.8.0)
70
- ruby_process (0.0.8)
84
+ rspec (3.1.0)
85
+ rspec-core (~> 3.1.0)
86
+ rspec-expectations (~> 3.1.0)
87
+ rspec-mocks (~> 3.1.0)
88
+ rspec-core (3.1.7)
89
+ rspec-support (~> 3.1.0)
90
+ rspec-expectations (3.1.2)
91
+ diff-lcs (>= 1.2.0, < 2.0)
92
+ rspec-support (~> 3.1.0)
93
+ rspec-mocks (3.1.3)
94
+ rspec-support (~> 3.1.0)
95
+ rspec-support (3.1.2)
96
+ ruby_process (0.0.9)
71
97
  tsafe
72
98
  wref
73
- sqlite3 (1.3.8)
99
+ simplecov (0.9.1)
100
+ docile (~> 1.1.0)
101
+ multi_json (~> 1.0)
102
+ simplecov-html (~> 0.8.0)
103
+ simplecov-html (0.8.0)
104
+ sqlite3 (1.3.9)
74
105
  string-cases (0.0.0)
75
106
  string-strtr (0.0.3)
107
+ thread_safe (0.3.4)
76
108
  tsafe (0.0.11)
109
+ tzinfo (1.2.2)
110
+ thread_safe (~> 0.1)
77
111
  wref (0.0.6)
78
112
 
79
113
  PLATFORMS
80
114
  ruby
81
115
 
82
116
  DEPENDENCIES
117
+ activerecord
83
118
  array_enumerator
84
- bundler (>= 1.0.0)
119
+ bundler
120
+ codeclimate-test-reporter
85
121
  datet
86
- jeweler (~> 1.8.4)
122
+ jeweler
87
123
  knjrbfw
88
124
  mysql2
89
- rdoc (~> 3.12)
90
- rspec (~> 2.8.0)
125
+ rdoc
126
+ rspec
91
127
  sqlite3
92
128
  string-cases
93
129
  wref
data/README.md ADDED
@@ -0,0 +1,186 @@
1
+ [![Code Climate](https://codeclimate.com/github/kaspernj/baza/badges/gpa.svg)](https://codeclimate.com/github/kaspernj/baza)
2
+ [![Test Coverage](https://codeclimate.com/github/kaspernj/baza/badges/coverage.svg)](https://codeclimate.com/github/kaspernj/baza)
3
+ [![Build Status](https://api.shippable.com/projects/540e7b993479c5ea8f9ec1fe/badge?branchName=master)](https://app.shippable.com/projects/540e7b993479c5ea8f9ec1fe/builds/latest)
4
+
5
+ # baza
6
+
7
+ A database abstraction layer for Ruby.
8
+
9
+ ## Installation
10
+
11
+ Is fairly painless.
12
+ ```
13
+ gem install baza
14
+ ```
15
+
16
+ Or in your Gemfile:
17
+ ```ruby
18
+ gem 'baza'
19
+ ```
20
+
21
+ ## Connection to a database.
22
+
23
+ ### MySQL
24
+ ```ruby
25
+ db = Baza::Db.new(type: :mysql, subtype: :mysql2, host: "localhost", user: "my_user", pass: "my_password", port: 3306, db: "my_database")
26
+ ```
27
+
28
+ ### SQLite3
29
+ ```ruby
30
+ db = Baza::Db.new(type: :sqlite3, path: "/path/to/file.sqlite3")
31
+ ```
32
+
33
+ ## Queries
34
+
35
+ ### Select
36
+ ```ruby
37
+ db.select(:users, {name: "Kasper"}, {orderby: "age"}) do |row|
38
+ puts "Row: #{row}"
39
+ end
40
+
41
+ name = "Kasper"
42
+ db.q("SELECT * FROM users WHERE name = '#{db.esc(name)}' ORDER BY age") do |row|
43
+ puts "Row: #{row}"
44
+ end
45
+ ```
46
+
47
+ ### Inserting
48
+ ```ruby
49
+ db.insert(:users, {name: "Kasper", age: 27})
50
+ id = db.last_id
51
+ ```
52
+
53
+ It can also return the ID at the same time
54
+ ```ruby
55
+ id = db.insert(:users, {name: "Kasper", age: 27}, return_id: true)
56
+ ```
57
+
58
+ Inserting multiple rows in one query is also fairly painless:
59
+ ```ruby
60
+ db.insert_multi(:users, [
61
+ {name: "Kasper", age: 27},
62
+ {name: "Christina", age: 25},
63
+ {name: "Charlotte", age: 23}
64
+ ])
65
+ ```
66
+
67
+ ### Update
68
+ ```ruby
69
+ db.update(:users, {name: "Kasper Johansen"}, {name: "Kasper"})
70
+ ```
71
+
72
+ ### Delete
73
+ ```ruby
74
+ db.delete(:users, {name: "Kasper"})
75
+ ```
76
+
77
+ ### Upsert
78
+ The following example handels a row that will be inserted with {name: "Kasper", age: 27} if it doesnt exist or rows with {name: "Kasper"} will have their their age updated to 27.
79
+ ```ruby
80
+ db.upsert(:users, {name: "Kasper"}, {age: 27})
81
+ ```
82
+
83
+ ## Structure
84
+
85
+ ### Table creation
86
+ ```ruby
87
+ db.tables.create(:users, {
88
+ :columns => [
89
+ {:name => :id, :type => :int, :autoincr => true, :primarykey => true},
90
+ {:name => :name, :type => :varchar}
91
+ ],
92
+ :indexes => [
93
+ :name
94
+ ]
95
+ })
96
+ ```
97
+
98
+ ### Table dropping
99
+ ```ruby
100
+ table = db.tables[:users]
101
+ table.drop
102
+ ```
103
+
104
+ ### Table listing
105
+ ```ruby
106
+ array_of_tables = db.tables.list
107
+ ```
108
+
109
+ Or you can use blocks:
110
+ ```ruby
111
+ db.tables.list do |table|
112
+ puts "Table-name: #{table.name}"
113
+ end
114
+ ```
115
+
116
+ ### Table renaming
117
+ ```ruby
118
+ table = db.tables[:users]
119
+ table.rename(:new_table_name)
120
+ ```
121
+
122
+ ### Column listing
123
+ ```ruby
124
+ table = db.tables[:users]
125
+ cols = table.columns
126
+ ```
127
+
128
+ Or a specific column:
129
+ ```ruby
130
+ col = table.column(:id)
131
+ puts "Column: #{col.name} #{col.type}(#{col.maxlength})"
132
+ ```
133
+
134
+ ## Copying databases
135
+ ```ruby
136
+ db_mysql = Baza::Db.new(:type => :mysql, :subtype => :mysql2, ...)
137
+ db_sqlite = Baza::Db.new(:type => :sqlite3, :path => ...)
138
+
139
+ db_mysql.copy_to(db_sqlite)
140
+ ```
141
+
142
+ ## Dumping SQL to an IO
143
+ ```ruby
144
+ db = Baza::Db.new(...)
145
+ dump = Baza::Dump.new(:db => db)
146
+ str_io = StringIO.new
147
+ dump.dump(str_io)
148
+ ```
149
+
150
+ ## Transactions
151
+ ```ruby
152
+ db.transaction do
153
+ 1000.times do
154
+ db.insert(:users, {:name => "Kasper"})
155
+ end
156
+ end
157
+ ```
158
+
159
+ ## Query Buffer
160
+ In order to speed things up, but without using transactions directly, you can use a query buffer. This stores various instructions in memory and flushes them every now and then through transactions or intelligent queries (like multi-insertion). The drawback is that it will not be possible to test the queries for errors before a flush is executed and it wont be possible to read results form any of the queries. It is fairly simple do however:
161
+ ```ruby
162
+ db.q_buffer do |buffer|
163
+ 100_000.times do |count|
164
+ buffer.insert(:table_name, {:name => "Kasper #{count}"})
165
+
166
+ buffer.query("UPDATE table SET ...")
167
+ buffer.query("DELETE FROM table WHERE ...")
168
+ end
169
+ end
170
+ ```
171
+
172
+ ## Contributing to baza
173
+
174
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
175
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
176
+ * Fork the project.
177
+ * Start a feature/bugfix branch.
178
+ * Commit and push until you are happy with your contribution.
179
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
180
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
181
+
182
+ ## Copyright
183
+
184
+ Copyright (c) 2013 Kasper Johansen. See LICENSE.txt for
185
+ further details.
186
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.13
1
+ 0.0.14
data/baza.gemspec CHANGED
@@ -2,19 +2,21 @@
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.14 ruby lib
5
6
 
6
7
  Gem::Specification.new do |s|
7
8
  s.name = "baza"
8
- s.version = "0.0.13"
9
+ s.version = "0.0.14"
9
10
 
10
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
11
13
  s.authors = ["Kasper Johansen"]
12
- s.date = "2013-09-06"
14
+ s.date = "2014-10-15"
13
15
  s.description = "A database abstraction layer, model framework and database framework."
14
16
  s.email = "kj@gfish.com"
15
17
  s.extra_rdoc_files = [
16
18
  "LICENSE.txt",
17
- "README.rdoc"
19
+ "README.md"
18
20
  ]
19
21
  s.files = [
20
22
  ".document",
@@ -22,12 +24,13 @@ Gem::Specification.new do |s|
22
24
  "Gemfile",
23
25
  "Gemfile.lock",
24
26
  "LICENSE.txt",
25
- "README.rdoc",
27
+ "README.md",
26
28
  "Rakefile",
27
29
  "VERSION",
28
30
  "baza.gemspec",
29
31
  "include/db.rb",
30
32
  "include/dbtime.rb",
33
+ "include/driver.rb",
31
34
  "include/drivers/active_record/active_record.rb",
32
35
  "include/drivers/mysql/mysql.rb",
33
36
  "include/drivers/mysql/mysql_columns.rb",
@@ -52,21 +55,30 @@ Gem::Specification.new do |s|
52
55
  "include/row.rb",
53
56
  "include/sqlspecs.rb",
54
57
  "lib/baza.rb",
55
- "spec/baza_spec.rb",
56
- "spec/db_spec_encoding_test_file.txt",
58
+ "shippable.yml",
59
+ "spec/include/drivers/active_record_spec.rb",
60
+ "spec/include/drivers/mysql_spec.rb",
61
+ "spec/include/drivers/sqlite3_spec.rb",
62
+ "spec/info_active_record.rb",
63
+ "spec/info_active_record_example.rb",
64
+ "spec/info_active_record_shippable.rb",
57
65
  "spec/info_mysql_example.rb",
66
+ "spec/info_mysql_shippable.rb",
58
67
  "spec/info_sqlite3.rb",
59
68
  "spec/model_handler_spec.rb",
60
- "spec/spec_helper.rb"
69
+ "spec/spec_helper.rb",
70
+ "spec/support/driver_collection.rb",
71
+ "spec/support/driver_columns_collection.rb",
72
+ "spec/support/driver_indexes_collection.rb",
73
+ "spec/support/driver_tables_collection.rb"
61
74
  ]
62
75
  s.homepage = "http://github.com/kaspernj/baza"
63
76
  s.licenses = ["MIT"]
64
- s.require_paths = ["lib"]
65
- s.rubygems_version = "1.8.23"
77
+ s.rubygems_version = "2.4.0"
66
78
  s.summary = "A database abstraction layer, model framework and database framework."
67
79
 
68
80
  if s.respond_to? :specification_version then
69
- s.specification_version = 3
81
+ s.specification_version = 4
70
82
 
71
83
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
72
84
  s.add_runtime_dependency(%q<datet>, [">= 0"])
@@ -74,24 +86,26 @@ Gem::Specification.new do |s|
74
86
  s.add_runtime_dependency(%q<knjrbfw>, [">= 0"])
75
87
  s.add_runtime_dependency(%q<array_enumerator>, [">= 0"])
76
88
  s.add_runtime_dependency(%q<string-cases>, [">= 0"])
77
- s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
78
- s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
79
- s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
80
- s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
89
+ s.add_development_dependency(%q<rspec>, [">= 0"])
90
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
91
+ s.add_development_dependency(%q<bundler>, [">= 0"])
92
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
81
93
  s.add_development_dependency(%q<sqlite3>, [">= 0"])
82
94
  s.add_development_dependency(%q<mysql2>, [">= 0"])
95
+ s.add_development_dependency(%q<activerecord>, [">= 0"])
83
96
  else
84
97
  s.add_dependency(%q<datet>, [">= 0"])
85
98
  s.add_dependency(%q<wref>, [">= 0"])
86
99
  s.add_dependency(%q<knjrbfw>, [">= 0"])
87
100
  s.add_dependency(%q<array_enumerator>, [">= 0"])
88
101
  s.add_dependency(%q<string-cases>, [">= 0"])
89
- s.add_dependency(%q<rspec>, ["~> 2.8.0"])
90
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
91
- s.add_dependency(%q<bundler>, [">= 1.0.0"])
92
- s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
102
+ s.add_dependency(%q<rspec>, [">= 0"])
103
+ s.add_dependency(%q<rdoc>, [">= 0"])
104
+ s.add_dependency(%q<bundler>, [">= 0"])
105
+ s.add_dependency(%q<jeweler>, [">= 0"])
93
106
  s.add_dependency(%q<sqlite3>, [">= 0"])
94
107
  s.add_dependency(%q<mysql2>, [">= 0"])
108
+ s.add_dependency(%q<activerecord>, [">= 0"])
95
109
  end
96
110
  else
97
111
  s.add_dependency(%q<datet>, [">= 0"])
@@ -99,12 +113,13 @@ Gem::Specification.new do |s|
99
113
  s.add_dependency(%q<knjrbfw>, [">= 0"])
100
114
  s.add_dependency(%q<array_enumerator>, [">= 0"])
101
115
  s.add_dependency(%q<string-cases>, [">= 0"])
102
- s.add_dependency(%q<rspec>, ["~> 2.8.0"])
103
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
104
- s.add_dependency(%q<bundler>, [">= 1.0.0"])
105
- s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
116
+ s.add_dependency(%q<rspec>, [">= 0"])
117
+ s.add_dependency(%q<rdoc>, [">= 0"])
118
+ s.add_dependency(%q<bundler>, [">= 0"])
119
+ s.add_dependency(%q<jeweler>, [">= 0"])
106
120
  s.add_dependency(%q<sqlite3>, [">= 0"])
107
121
  s.add_dependency(%q<mysql2>, [">= 0"])
122
+ s.add_dependency(%q<activerecord>, [">= 0"])
108
123
  end
109
124
  end
110
125