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 +7 -0
- data/Gemfile +7 -4
- data/Gemfile.lock +84 -48
- data/README.md +186 -0
- data/VERSION +1 -1
- data/baza.gemspec +37 -22
- data/include/db.rb +153 -166
- data/include/dbtime.rb +2 -2
- data/include/driver.rb +9 -0
- data/include/drivers/active_record/active_record.rb +64 -27
- data/include/drivers/mysql/mysql_columns.rb +33 -33
- data/include/drivers/mysql/mysql_indexes.rb +26 -17
- data/include/drivers/mysql/mysql_tables.rb +140 -132
- data/include/drivers/sqlite3/sqlite3_indexes.rb +37 -9
- data/include/drivers/sqlite3/sqlite3_tables.rb +181 -152
- data/include/query_buffer.rb +22 -22
- data/include/revision.rb +70 -70
- data/lib/baza.rb +3 -1
- data/shippable.yml +11 -0
- data/spec/include/drivers/active_record_spec.rb +8 -0
- data/spec/include/drivers/mysql_spec.rb +47 -0
- data/spec/include/drivers/sqlite3_spec.rb +60 -0
- data/spec/info_active_record.rb +37 -0
- data/spec/info_active_record_example.rb +37 -0
- data/spec/info_active_record_shippable.rb +36 -0
- data/spec/info_mysql_example.rb +24 -6
- data/spec/info_mysql_shippable.rb +23 -0
- data/spec/info_sqlite3.rb +23 -15
- data/spec/model_handler_spec.rb +84 -84
- data/spec/spec_helper.rb +6 -6
- data/spec/support/driver_collection.rb +288 -0
- data/spec/support/driver_columns_collection.rb +49 -0
- data/spec/support/driver_indexes_collection.rb +49 -0
- data/spec/support/driver_tables_collection.rb +73 -0
- metadata +100 -102
- data/README.rdoc +0 -136
- data/spec/baza_spec.rb +0 -410
- data/spec/db_spec_encoding_test_file.txt +0 -1
metadata
CHANGED
@@ -1,190 +1,181 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: baza
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.0.13
|
4
|
+
version: 0.0.14
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Kasper Johansen
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-10-15 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
|
16
|
-
|
14
|
+
name: datet
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
17
16
|
requirements:
|
18
|
-
- -
|
17
|
+
- - ">="
|
19
18
|
- !ruby/object:Gem::Version
|
20
19
|
version: '0'
|
21
|
-
name: datet
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
|
25
|
-
none: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
|
-
|
32
|
-
|
28
|
+
name: wref
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
33
30
|
requirements:
|
34
|
-
- -
|
31
|
+
- - ">="
|
35
32
|
- !ruby/object:Gem::Version
|
36
33
|
version: '0'
|
37
|
-
name: wref
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
|
-
|
41
|
-
none: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
|
-
|
48
|
-
|
42
|
+
name: knjrbfw
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
49
44
|
requirements:
|
50
|
-
- -
|
45
|
+
- - ">="
|
51
46
|
- !ruby/object:Gem::Version
|
52
47
|
version: '0'
|
53
|
-
name: knjrbfw
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
|
-
|
57
|
-
none: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
|
-
|
64
|
-
|
56
|
+
name: array_enumerator
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
65
58
|
requirements:
|
66
|
-
- -
|
59
|
+
- - ">="
|
67
60
|
- !ruby/object:Gem::Version
|
68
61
|
version: '0'
|
69
|
-
name: array_enumerator
|
70
62
|
type: :runtime
|
71
63
|
prerelease: false
|
72
|
-
|
73
|
-
none: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
|
-
|
80
|
-
|
70
|
+
name: string-cases
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
81
72
|
requirements:
|
82
|
-
- -
|
73
|
+
- - ">="
|
83
74
|
- !ruby/object:Gem::Version
|
84
75
|
version: '0'
|
85
|
-
name: string-cases
|
86
76
|
type: :runtime
|
87
77
|
prerelease: false
|
88
|
-
|
89
|
-
none: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - ">="
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
|
-
|
96
|
-
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
97
86
|
requirements:
|
98
|
-
- -
|
87
|
+
- - ">="
|
99
88
|
- !ruby/object:Gem::Version
|
100
|
-
version:
|
101
|
-
name: rspec
|
89
|
+
version: '0'
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
|
-
|
105
|
-
none: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
93
|
requirements:
|
107
|
-
- -
|
94
|
+
- - ">="
|
108
95
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
96
|
+
version: '0'
|
110
97
|
- !ruby/object:Gem::Dependency
|
111
|
-
|
112
|
-
|
98
|
+
name: rdoc
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
113
100
|
requirements:
|
114
|
-
- -
|
101
|
+
- - ">="
|
115
102
|
- !ruby/object:Gem::Version
|
116
|
-
version: '
|
117
|
-
name: rdoc
|
103
|
+
version: '0'
|
118
104
|
type: :development
|
119
105
|
prerelease: false
|
120
|
-
|
121
|
-
none: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
107
|
requirements:
|
123
|
-
- -
|
108
|
+
- - ">="
|
124
109
|
- !ruby/object:Gem::Version
|
125
|
-
version: '
|
110
|
+
version: '0'
|
126
111
|
- !ruby/object:Gem::Dependency
|
127
|
-
|
128
|
-
|
112
|
+
name: bundler
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
129
114
|
requirements:
|
130
|
-
- -
|
115
|
+
- - ">="
|
131
116
|
- !ruby/object:Gem::Version
|
132
|
-
version:
|
133
|
-
name: bundler
|
117
|
+
version: '0'
|
134
118
|
type: :development
|
135
119
|
prerelease: false
|
136
|
-
|
137
|
-
none: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
138
121
|
requirements:
|
139
|
-
- -
|
122
|
+
- - ">="
|
140
123
|
- !ruby/object:Gem::Version
|
141
|
-
version:
|
124
|
+
version: '0'
|
142
125
|
- !ruby/object:Gem::Dependency
|
143
|
-
|
144
|
-
|
126
|
+
name: jeweler
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
145
128
|
requirements:
|
146
|
-
- -
|
129
|
+
- - ">="
|
147
130
|
- !ruby/object:Gem::Version
|
148
|
-
version:
|
149
|
-
name: jeweler
|
131
|
+
version: '0'
|
150
132
|
type: :development
|
151
133
|
prerelease: false
|
152
|
-
|
153
|
-
none: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
154
135
|
requirements:
|
155
|
-
- -
|
136
|
+
- - ">="
|
156
137
|
- !ruby/object:Gem::Version
|
157
|
-
version:
|
138
|
+
version: '0'
|
158
139
|
- !ruby/object:Gem::Dependency
|
159
|
-
|
160
|
-
|
140
|
+
name: sqlite3
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
161
142
|
requirements:
|
162
|
-
- -
|
143
|
+
- - ">="
|
163
144
|
- !ruby/object:Gem::Version
|
164
145
|
version: '0'
|
165
|
-
name: sqlite3
|
166
146
|
type: :development
|
167
147
|
prerelease: false
|
168
|
-
|
169
|
-
none: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
170
149
|
requirements:
|
171
|
-
- -
|
150
|
+
- - ">="
|
172
151
|
- !ruby/object:Gem::Version
|
173
152
|
version: '0'
|
174
153
|
- !ruby/object:Gem::Dependency
|
175
|
-
|
176
|
-
|
154
|
+
name: mysql2
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
177
156
|
requirements:
|
178
|
-
- -
|
157
|
+
- - ">="
|
179
158
|
- !ruby/object:Gem::Version
|
180
159
|
version: '0'
|
181
|
-
name: mysql2
|
182
160
|
type: :development
|
183
161
|
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: activerecord
|
184
169
|
requirement: !ruby/object:Gem::Requirement
|
185
|
-
none: false
|
186
170
|
requirements:
|
187
|
-
- -
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
188
179
|
- !ruby/object:Gem::Version
|
189
180
|
version: '0'
|
190
181
|
description: A database abstraction layer, model framework and database framework.
|
@@ -193,19 +184,20 @@ executables: []
|
|
193
184
|
extensions: []
|
194
185
|
extra_rdoc_files:
|
195
186
|
- LICENSE.txt
|
196
|
-
- README.
|
187
|
+
- README.md
|
197
188
|
files:
|
198
|
-
- .document
|
199
|
-
- .rspec
|
189
|
+
- ".document"
|
190
|
+
- ".rspec"
|
200
191
|
- Gemfile
|
201
192
|
- Gemfile.lock
|
202
193
|
- LICENSE.txt
|
203
|
-
- README.
|
194
|
+
- README.md
|
204
195
|
- Rakefile
|
205
196
|
- VERSION
|
206
197
|
- baza.gemspec
|
207
198
|
- include/db.rb
|
208
199
|
- include/dbtime.rb
|
200
|
+
- include/driver.rb
|
209
201
|
- include/drivers/active_record/active_record.rb
|
210
202
|
- include/drivers/mysql/mysql.rb
|
211
203
|
- include/drivers/mysql/mysql_columns.rb
|
@@ -230,38 +222,44 @@ files:
|
|
230
222
|
- include/row.rb
|
231
223
|
- include/sqlspecs.rb
|
232
224
|
- lib/baza.rb
|
233
|
-
-
|
234
|
-
- spec/
|
225
|
+
- shippable.yml
|
226
|
+
- spec/include/drivers/active_record_spec.rb
|
227
|
+
- spec/include/drivers/mysql_spec.rb
|
228
|
+
- spec/include/drivers/sqlite3_spec.rb
|
229
|
+
- spec/info_active_record.rb
|
230
|
+
- spec/info_active_record_example.rb
|
231
|
+
- spec/info_active_record_shippable.rb
|
235
232
|
- spec/info_mysql_example.rb
|
233
|
+
- spec/info_mysql_shippable.rb
|
236
234
|
- spec/info_sqlite3.rb
|
237
235
|
- spec/model_handler_spec.rb
|
238
236
|
- spec/spec_helper.rb
|
237
|
+
- spec/support/driver_collection.rb
|
238
|
+
- spec/support/driver_columns_collection.rb
|
239
|
+
- spec/support/driver_indexes_collection.rb
|
240
|
+
- spec/support/driver_tables_collection.rb
|
239
241
|
homepage: http://github.com/kaspernj/baza
|
240
242
|
licenses:
|
241
243
|
- MIT
|
244
|
+
metadata: {}
|
242
245
|
post_install_message:
|
243
246
|
rdoc_options: []
|
244
247
|
require_paths:
|
245
248
|
- lib
|
246
249
|
required_ruby_version: !ruby/object:Gem::Requirement
|
247
|
-
none: false
|
248
250
|
requirements:
|
249
|
-
- -
|
251
|
+
- - ">="
|
250
252
|
- !ruby/object:Gem::Version
|
251
|
-
segments:
|
252
|
-
- 0
|
253
|
-
hash: -1432230654984551532
|
254
253
|
version: '0'
|
255
254
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
256
|
-
none: false
|
257
255
|
requirements:
|
258
|
-
- -
|
256
|
+
- - ">="
|
259
257
|
- !ruby/object:Gem::Version
|
260
258
|
version: '0'
|
261
259
|
requirements: []
|
262
260
|
rubyforge_project:
|
263
|
-
rubygems_version:
|
261
|
+
rubygems_version: 2.4.0
|
264
262
|
signing_key:
|
265
|
-
specification_version:
|
263
|
+
specification_version: 4
|
266
264
|
summary: A database abstraction layer, model framework and database framework.
|
267
265
|
test_files: []
|
data/README.rdoc
DELETED
@@ -1,136 +0,0 @@
|
|
1
|
-
= baza
|
2
|
-
|
3
|
-
A database abstraction layer for Ruby.
|
4
|
-
|
5
|
-
== Installation
|
6
|
-
|
7
|
-
Is fairly painless.
|
8
|
-
gem install baza
|
9
|
-
|
10
|
-
== Connection to a database.
|
11
|
-
|
12
|
-
=== MySQL
|
13
|
-
db = Baza::Db.new(:type => :mysql, :subtype => :mysql2, :host => "localhost", :user => "my_user", :pass => "my_password", :port => 3306, :db => "my_database")
|
14
|
-
|
15
|
-
=== SQLite3
|
16
|
-
db = Baza::Db.new(:type => :sqlite3, :path => "/path/to/file.sqlite3")
|
17
|
-
|
18
|
-
== Queries
|
19
|
-
|
20
|
-
=== Select
|
21
|
-
db.select(:users, {:name => "Kasper"}, {:orderby => "age"}) do |row|
|
22
|
-
puts "Row: #{row}"
|
23
|
-
end
|
24
|
-
|
25
|
-
name = "Kasper"
|
26
|
-
db.q("SELECT * FROM users WHERE name = '#{db.esc(name)}' ORDER BY age") do |row|
|
27
|
-
puts "Row: #{row}"
|
28
|
-
end
|
29
|
-
|
30
|
-
=== Inserting
|
31
|
-
db.insert(:users, {:name => "Kasper", :age => 27})
|
32
|
-
id = db.last_id
|
33
|
-
|
34
|
-
It can also return the ID at the same time
|
35
|
-
id = db.insert(:users, {:name => "Kasper", :age => 27}, :return_id => true)
|
36
|
-
|
37
|
-
Inserting multiple rows in one query is also fairly painless:
|
38
|
-
db.insert_multi(:users, [
|
39
|
-
{:name => "Kasper", :age => 27},
|
40
|
-
{:name => "Christina", :age => 25},
|
41
|
-
{:name => "Charlotte", :age => 23}
|
42
|
-
])
|
43
|
-
|
44
|
-
=== Update
|
45
|
-
db.update(:users, {:name => "Kasper Johansen"}, {:name => "Kasper"})
|
46
|
-
|
47
|
-
=== Delete
|
48
|
-
db.delete(:users, {:name => "Kasper"})
|
49
|
-
|
50
|
-
=== Upsert
|
51
|
-
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.
|
52
|
-
db.upsert(:users, {:name => "Kasper"}, {:age => 27})
|
53
|
-
|
54
|
-
== Structure
|
55
|
-
|
56
|
-
=== Table creation
|
57
|
-
db.tables.create(:users, {
|
58
|
-
:columns => [
|
59
|
-
{:name => :id, :type => :int, :autoincr => true, :primarykey => true},
|
60
|
-
{:name => :name, :type => :varchar}
|
61
|
-
],
|
62
|
-
:indexes => [
|
63
|
-
:name
|
64
|
-
]
|
65
|
-
})
|
66
|
-
|
67
|
-
=== Table dropping
|
68
|
-
table = db.tables[:users]
|
69
|
-
table.drop
|
70
|
-
|
71
|
-
=== Table listing
|
72
|
-
array_of_tables = db.tables.list
|
73
|
-
|
74
|
-
Or you can use blocks:
|
75
|
-
db.tables.list do |table|
|
76
|
-
puts "Table-name: #{table.name}"
|
77
|
-
end
|
78
|
-
|
79
|
-
=== Table renaming
|
80
|
-
table = db.tables[:users]
|
81
|
-
table.rename(:new_table_name)
|
82
|
-
|
83
|
-
=== Column listing
|
84
|
-
table = db.tables[:users]
|
85
|
-
cols = table.columns
|
86
|
-
|
87
|
-
Or a specific column:
|
88
|
-
col = table.column(:id)
|
89
|
-
puts "Column: #{col.name} #{col.type}(#{col.maxlength})"
|
90
|
-
|
91
|
-
== Copying databases
|
92
|
-
db_mysql = Baza::Db.new(:type => :mysql, :subtype => :mysql2, ...)
|
93
|
-
db_sqlite = Baza::Db.new(:type => :sqlite3, :path => ...)
|
94
|
-
|
95
|
-
db_mysql.copy_to(db_sqlite)
|
96
|
-
|
97
|
-
== Dumping SQL to an IO
|
98
|
-
db = Baza::Db.new(...)
|
99
|
-
dump = Baza::Dump.new(:db => db)
|
100
|
-
str_io = StringIO.new
|
101
|
-
dump.dump(str_io)
|
102
|
-
|
103
|
-
== Transactions
|
104
|
-
db.transaction do
|
105
|
-
1000.times do
|
106
|
-
db.insert(:users, {:name => "Kasper"})
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
== Query Buffer
|
111
|
-
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:
|
112
|
-
db.q_buffer do |buffer|
|
113
|
-
100_000.times do |count|
|
114
|
-
buffer.insert(:table_name, {:name => "Kasper #{count}"})
|
115
|
-
|
116
|
-
buffer.query("UPDATE table SET ...")
|
117
|
-
buffer.query("DELETE FROM table WHERE ...")
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
|
122
|
-
== Contributing to baza
|
123
|
-
|
124
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
125
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
126
|
-
* Fork the project.
|
127
|
-
* Start a feature/bugfix branch.
|
128
|
-
* Commit and push until you are happy with your contribution.
|
129
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
130
|
-
* 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.
|
131
|
-
|
132
|
-
== Copyright
|
133
|
-
|
134
|
-
Copyright (c) 2013 Kasper Johansen. See LICENSE.txt for
|
135
|
-
further details.
|
136
|
-
|