baza 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +58 -13
- data/VERSION +1 -1
- data/baza.gemspec +15 -3
- data/include/db.rb +871 -865
- data/include/drivers/mysql/mysql.rb +104 -297
- data/include/drivers/mysql/mysql_column.rb +133 -0
- data/include/drivers/mysql/mysql_columns.rb +4 -127
- data/include/drivers/mysql/mysql_index.rb +76 -0
- data/include/drivers/mysql/mysql_indexes.rb +0 -73
- data/include/drivers/mysql/mysql_result.rb +42 -0
- data/include/drivers/mysql/mysql_result_java.rb +61 -0
- data/include/drivers/mysql/mysql_result_mysql2.rb +26 -0
- data/include/drivers/mysql/mysql_result_unbuffered.rb +72 -0
- data/include/drivers/mysql/mysql_sqlspecs.rb +1 -1
- data/include/drivers/mysql/mysql_table.rb +361 -0
- data/include/drivers/mysql/mysql_tables.rb +23 -381
- data/include/drivers/sqlite3/libknjdb_java_sqlite3.rb +17 -22
- data/include/drivers/sqlite3/libknjdb_sqlite3_ironruby.rb +13 -13
- data/include/drivers/sqlite3/sqlite3.rb +39 -105
- data/include/drivers/sqlite3/sqlite3_column.rb +146 -0
- data/include/drivers/sqlite3/sqlite3_columns.rb +17 -149
- data/include/drivers/sqlite3/sqlite3_index.rb +55 -0
- data/include/drivers/sqlite3/sqlite3_indexes.rb +0 -52
- data/include/drivers/sqlite3/sqlite3_result.rb +35 -0
- data/include/drivers/sqlite3/sqlite3_result_java.rb +39 -0
- data/include/drivers/sqlite3/sqlite3_table.rb +399 -0
- data/include/drivers/sqlite3/sqlite3_tables.rb +7 -403
- data/include/idquery.rb +19 -19
- data/include/model.rb +139 -139
- data/include/model_handler_sqlhelper.rb +74 -74
- data/spec/support/driver_columns_collection.rb +17 -0
- metadata +14 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd02457700f9360c5cef41f8b101fa297016136e
|
4
|
+
data.tar.gz: 66949e26d04439be674b2cdd908c613753c5e26d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13fdc63c67474ad44f1ba5b029046246d9339a5bfff7cdcdfb9761f3ebff42df0599d85f03409be4ed9e947613565dca672e9e0e679b0d5fbc3bda07f2c4c4cb
|
7
|
+
data.tar.gz: 28472e1d5af9ab5763a15f0dd8f3b33761948d167b572f06fa084e17d882eea51c262e3d0acf16cb736fd4824cce2974d2bbd3b7d37c9efffec4ea1cbd009bc7
|
data/README.md
CHANGED
@@ -71,7 +71,7 @@ db.update(:users, {name: "Kasper Johansen"}, {name: "Kasper"})
|
|
71
71
|
|
72
72
|
### Delete
|
73
73
|
```ruby
|
74
|
-
db.delete(:users,
|
74
|
+
db.delete(:users, name: "Kasper")
|
75
75
|
```
|
76
76
|
|
77
77
|
### Upsert
|
@@ -85,11 +85,11 @@ db.upsert(:users, {name: "Kasper"}, {age: 27})
|
|
85
85
|
### Table creation
|
86
86
|
```ruby
|
87
87
|
db.tables.create(:users, {
|
88
|
-
:
|
89
|
-
{:
|
90
|
-
{:
|
88
|
+
columns: [
|
89
|
+
{name: :id, type: :int, autoincr: true, primarykey: true},
|
90
|
+
{name: :name, type: :varchar}
|
91
91
|
],
|
92
|
-
:
|
92
|
+
indexes: [
|
93
93
|
:name
|
94
94
|
]
|
95
95
|
})
|
@@ -119,6 +119,16 @@ table = db.tables[:users]
|
|
119
119
|
table.rename(:new_table_name)
|
120
120
|
```
|
121
121
|
|
122
|
+
### Table optimizing
|
123
|
+
```ruby
|
124
|
+
table.optimize
|
125
|
+
```
|
126
|
+
|
127
|
+
### Table rows counting
|
128
|
+
```ruby
|
129
|
+
table.rows_count
|
130
|
+
```
|
131
|
+
|
122
132
|
### Column listing
|
123
133
|
```ruby
|
124
134
|
table = db.tables[:users]
|
@@ -127,14 +137,47 @@ cols = table.columns
|
|
127
137
|
|
128
138
|
Or a specific column:
|
129
139
|
```ruby
|
130
|
-
|
131
|
-
puts "Column: #{
|
140
|
+
column = table.column(:id)
|
141
|
+
puts "Column: #{column.name} #{column.type}(#{column.maxlength})"
|
142
|
+
puts "Default: #{column.default}"
|
143
|
+
```
|
144
|
+
|
145
|
+
### Column altering
|
146
|
+
```ruby
|
147
|
+
column.change(name: "newname", type: :varchar, default: "")
|
148
|
+
```
|
149
|
+
|
150
|
+
### Drop column
|
151
|
+
```ruby
|
152
|
+
column.drop
|
153
|
+
```
|
154
|
+
|
155
|
+
### Get an index by name
|
156
|
+
```ruby
|
157
|
+
index = table.index("index_name")
|
158
|
+
```
|
159
|
+
|
160
|
+
### Rename index
|
161
|
+
```ruby
|
162
|
+
index.rename("new name")
|
163
|
+
```
|
164
|
+
|
165
|
+
### Dropping an index
|
166
|
+
```ruby
|
167
|
+
index.drop
|
168
|
+
```
|
169
|
+
|
170
|
+
### Getting various data from an index
|
171
|
+
```ruby
|
172
|
+
puts "Unique: #{index.unique?}"
|
173
|
+
puts "Primary: #{index.primary?}"
|
174
|
+
puts "Table: #{index.table}"
|
132
175
|
```
|
133
176
|
|
134
177
|
## Copying databases
|
135
178
|
```ruby
|
136
|
-
db_mysql = Baza::Db.new(:
|
137
|
-
db_sqlite = Baza::Db.new(:
|
179
|
+
db_mysql = Baza::Db.new(type: :mysql, subtype: :mysql2, ...)
|
180
|
+
db_sqlite = Baza::Db.new(type: :sqlite3, path: ...)
|
138
181
|
|
139
182
|
db_mysql.copy_to(db_sqlite)
|
140
183
|
```
|
@@ -142,7 +185,7 @@ db_mysql.copy_to(db_sqlite)
|
|
142
185
|
## Dumping SQL to an IO
|
143
186
|
```ruby
|
144
187
|
db = Baza::Db.new(...)
|
145
|
-
dump = Baza::Dump.new(:
|
188
|
+
dump = Baza::Dump.new(db: db)
|
146
189
|
str_io = StringIO.new
|
147
190
|
dump.dump(str_io)
|
148
191
|
```
|
@@ -151,17 +194,19 @@ dump.dump(str_io)
|
|
151
194
|
```ruby
|
152
195
|
db.transaction do
|
153
196
|
1000.times do
|
154
|
-
db.insert(:users,
|
197
|
+
db.insert(:users, name: "Kasper")
|
155
198
|
end
|
156
199
|
end
|
157
200
|
```
|
158
201
|
|
159
202
|
## 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
|
203
|
+
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 from any of the queries.
|
204
|
+
|
205
|
+
It is fairly simple do:
|
161
206
|
```ruby
|
162
207
|
db.q_buffer do |buffer|
|
163
208
|
100_000.times do |count|
|
164
|
-
buffer.insert(:table_name,
|
209
|
+
buffer.insert(:table_name, name: "Kasper #{count}")
|
165
210
|
|
166
211
|
buffer.query("UPDATE table SET ...")
|
167
212
|
buffer.query("DELETE FROM table WHERE ...")
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.15
|
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.15 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "baza"
|
9
|
-
s.version = "0.0.
|
9
|
+
s.version = "0.0.15"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Kasper Johansen"]
|
14
|
-
s.date = "
|
14
|
+
s.date = "2015-03-17"
|
15
15
|
s.description = "A database abstraction layer, model framework and database framework."
|
16
16
|
s.email = "kj@gfish.com"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -33,16 +33,28 @@ Gem::Specification.new do |s|
|
|
33
33
|
"include/driver.rb",
|
34
34
|
"include/drivers/active_record/active_record.rb",
|
35
35
|
"include/drivers/mysql/mysql.rb",
|
36
|
+
"include/drivers/mysql/mysql_column.rb",
|
36
37
|
"include/drivers/mysql/mysql_columns.rb",
|
38
|
+
"include/drivers/mysql/mysql_index.rb",
|
37
39
|
"include/drivers/mysql/mysql_indexes.rb",
|
40
|
+
"include/drivers/mysql/mysql_result.rb",
|
41
|
+
"include/drivers/mysql/mysql_result_java.rb",
|
42
|
+
"include/drivers/mysql/mysql_result_mysql2.rb",
|
43
|
+
"include/drivers/mysql/mysql_result_unbuffered.rb",
|
38
44
|
"include/drivers/mysql/mysql_sqlspecs.rb",
|
45
|
+
"include/drivers/mysql/mysql_table.rb",
|
39
46
|
"include/drivers/mysql/mysql_tables.rb",
|
40
47
|
"include/drivers/sqlite3/libknjdb_java_sqlite3.rb",
|
41
48
|
"include/drivers/sqlite3/libknjdb_sqlite3_ironruby.rb",
|
42
49
|
"include/drivers/sqlite3/sqlite3.rb",
|
50
|
+
"include/drivers/sqlite3/sqlite3_column.rb",
|
43
51
|
"include/drivers/sqlite3/sqlite3_columns.rb",
|
52
|
+
"include/drivers/sqlite3/sqlite3_index.rb",
|
44
53
|
"include/drivers/sqlite3/sqlite3_indexes.rb",
|
54
|
+
"include/drivers/sqlite3/sqlite3_result.rb",
|
55
|
+
"include/drivers/sqlite3/sqlite3_result_java.rb",
|
45
56
|
"include/drivers/sqlite3/sqlite3_sqlspecs.rb",
|
57
|
+
"include/drivers/sqlite3/sqlite3_table.rb",
|
46
58
|
"include/drivers/sqlite3/sqlite3_tables.rb",
|
47
59
|
"include/dump.rb",
|
48
60
|
"include/idquery.rb",
|