baza 0.0.15 → 0.0.16
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 +4 -4
- data/Gemfile +14 -7
- data/Gemfile.lock +19 -14
- data/README.md +1 -1
- data/VERSION +1 -1
- data/baza.gemspec +24 -21
- data/include/cloner.rb +18 -0
- data/include/column.rb +9 -0
- data/include/db.rb +2 -2
- data/include/drivers/active_record/active_record.rb +14 -4
- data/include/drivers/mysql/mysql.rb +56 -36
- data/include/drivers/mysql/mysql_column.rb +1 -1
- data/include/drivers/mysql/mysql_index.rb +2 -10
- data/include/drivers/mysql/mysql_table.rb +11 -11
- data/include/drivers/mysql/mysql_tables.rb +5 -7
- data/include/drivers/sqlite3/sqlite3.rb +43 -23
- data/include/drivers/sqlite3/sqlite3_column.rb +1 -1
- data/include/drivers/sqlite3/sqlite3_index.rb +5 -8
- data/include/drivers/sqlite3/sqlite3_result_java.rb +1 -1
- data/include/drivers/sqlite3/sqlite3_table.rb +17 -18
- data/include/drivers/sqlite3/sqlite3_tables.rb +4 -7
- data/include/index.rb +9 -0
- data/include/model.rb +1 -1
- data/include/model_handler.rb +162 -162
- data/include/table.rb +9 -0
- data/lib/baza.rb +19 -1
- data/shippable.yml +4 -1
- data/spec/include/cloner_spec.rb +10 -0
- data/spec/info_active_record.rb +20 -8
- data/spec/info_active_record_shippable.rb +18 -7
- data/spec/info_mysql_shippable.rb +16 -7
- data/spec/info_sqlite3.rb +1 -1
- data/spec/support/driver_indexes_collection.rb +16 -2
- metadata +28 -25
- data/include/drivers/sqlite3/libknjdb_java_sqlite3.rb +0 -78
- data/include/drivers/sqlite3/libknjdb_sqlite3_ironruby.rb +0 -69
data/include/table.rb
ADDED
data/lib/baza.rb
CHANGED
@@ -5,7 +5,25 @@ class Baza
|
|
5
5
|
def self.const_missing(name)
|
6
6
|
file_name = name.to_s.gsub(/(.)([A-Z])/,'\1_\2').downcase
|
7
7
|
require "#{File.dirname(__FILE__)}/../include/#{file_name}.rb"
|
8
|
-
raise "Still not defined: '#{name}'."
|
8
|
+
raise "Still not defined: '#{name}'." unless Baza.const_defined?(name)
|
9
9
|
return Baza.const_get(name)
|
10
10
|
end
|
11
|
+
|
12
|
+
def self.default_db=(db)
|
13
|
+
@default_db = db
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.default_db
|
17
|
+
unless @default_db
|
18
|
+
config_file = "#{Dir.pwd}/config/baza_database.rb"
|
19
|
+
|
20
|
+
load(config_file)
|
21
|
+
|
22
|
+
unless @default_db.is_a?(Baza::Db)
|
23
|
+
raise "Config file didn't return a Baza::Db: #{@default_db.class.name}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
return @default_db
|
28
|
+
end
|
11
29
|
end
|
data/shippable.yml
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
-
|
3
|
+
- ruby-1.9.3
|
4
|
+
- ruby-2.1.2
|
5
|
+
- jruby-head
|
4
6
|
before_script:
|
7
|
+
- sudo apt-get -f install libmysql-java
|
5
8
|
- cp spec/info_mysql_shippable.rb spec/info_mysql.rb
|
6
9
|
- cp spec/info_active_record_shippable.rb spec/info_active_record.rb
|
7
10
|
- mysql -e 'CREATE DATABASE baza;'
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Baza::Cloner do
|
4
|
+
it 'can clone drivers' do
|
5
|
+
require 'info_active_record'
|
6
|
+
conn = Baza::InfoActiveRecord.connection
|
7
|
+
baza_db = Baza::Cloner.from_active_record_connection(conn[:conn])
|
8
|
+
expect(baza_db.query('SELECT 1 AS test').fetch[:test]).to eq 1
|
9
|
+
end
|
10
|
+
end
|
data/spec/info_active_record.rb
CHANGED
@@ -4,14 +4,26 @@ class Baza::InfoActiveRecord
|
|
4
4
|
def self.connection
|
5
5
|
require "active_record"
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
if RUBY_ENGINE == "jruby"
|
8
|
+
require "/usr/share/java/mysql-connector-java.jar" if File.exists?("/usr/share/java/mysql-connector-java.jar")
|
9
|
+
@conn_pool ||= ::ActiveRecord::Base.establish_connection(
|
10
|
+
adapter: "mysql",
|
11
|
+
host: "localhost",
|
12
|
+
database: "baza-test",
|
13
|
+
username: "baza-test",
|
14
|
+
password: "BBH7djRUKzL5nmG3"
|
15
|
+
)
|
16
|
+
@conn ||= @conn_pool.connection
|
17
|
+
else
|
18
|
+
@conn_pool ||= ::ActiveRecord::Base.establish_connection(
|
19
|
+
adapter: "mysql2",
|
20
|
+
host: "localhost",
|
21
|
+
database: "baza-test",
|
22
|
+
username: "baza-test",
|
23
|
+
password: "BBH7djRUKzL5nmG3"
|
24
|
+
)
|
25
|
+
@conn ||= @conn_pool.connection
|
26
|
+
end
|
15
27
|
|
16
28
|
return {pool: @conn_pool, conn: @conn}
|
17
29
|
end
|
@@ -4,13 +4,24 @@ class Baza::InfoActiveRecord
|
|
4
4
|
def self.connection
|
5
5
|
require "active_record"
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
if RUBY_ENGINE == "jruby"
|
8
|
+
require "/usr/share/java/mysql-connector-java.jar" if File.exists?("/usr/share/java/mysql-connector-java.jar")
|
9
|
+
@conn_pool ||= ::ActiveRecord::Base.establish_connection(
|
10
|
+
adapter: "mysql",
|
11
|
+
host: "localhost",
|
12
|
+
database: "baza",
|
13
|
+
username: "shippa"
|
14
|
+
)
|
15
|
+
@conn ||= @conn_pool.connection
|
16
|
+
else
|
17
|
+
@conn_pool ||= ::ActiveRecord::Base.establish_connection(
|
18
|
+
adapter: "mysql2",
|
19
|
+
host: "localhost",
|
20
|
+
database: "baza",
|
21
|
+
username: "shippa"
|
22
|
+
)
|
23
|
+
@conn ||= @conn_pool.connection
|
24
|
+
end
|
14
25
|
|
15
26
|
return {pool: @conn_pool, conn: @conn}
|
16
27
|
end
|
@@ -2,13 +2,22 @@ class Baza::InfoMysql
|
|
2
2
|
attr_reader :db
|
3
3
|
|
4
4
|
def initialize
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
if RUBY_ENGINE == "jruby"
|
6
|
+
@db = Baza::Db.new(
|
7
|
+
type: :mysql,
|
8
|
+
host: "localhost",
|
9
|
+
user: "shippa",
|
10
|
+
db: "baza"
|
11
|
+
)
|
12
|
+
else
|
13
|
+
@db = Baza::Db.new(
|
14
|
+
type: :mysql,
|
15
|
+
subtype: :mysql2,
|
16
|
+
host: "localhost",
|
17
|
+
user: "shippa",
|
18
|
+
db: "baza"
|
19
|
+
)
|
20
|
+
end
|
12
21
|
end
|
13
22
|
|
14
23
|
def before
|
data/spec/info_sqlite3.rb
CHANGED
@@ -12,7 +12,12 @@ shared_examples_for "a baza indexes driver" do
|
|
12
12
|
db.tables.create("test", {
|
13
13
|
columns: [
|
14
14
|
{name: "id", type: :int, autoincr: true, primarykey: true},
|
15
|
-
{name: "text", type: :varchar}
|
15
|
+
{name: "text", type: :varchar},
|
16
|
+
{name: "email", type: :varchar}
|
17
|
+
],
|
18
|
+
indexes: [
|
19
|
+
:text,
|
20
|
+
{name: :email, unique: true, columns: [:email]}
|
16
21
|
]
|
17
22
|
})
|
18
23
|
db.tables[:test]
|
@@ -33,7 +38,6 @@ shared_examples_for "a baza indexes driver" do
|
|
33
38
|
|
34
39
|
test_table.create_indexes([{name: "index_on_text", columns: [:text]}])
|
35
40
|
test_table.rename("test2")
|
36
|
-
|
37
41
|
test_table.index("index_on_text").rename("index_on_text2")
|
38
42
|
|
39
43
|
table = db.tables[:test2]
|
@@ -46,4 +50,14 @@ shared_examples_for "a baza indexes driver" do
|
|
46
50
|
test_table.index("index_that_doesnt_exist")
|
47
51
|
}.to raise_error(Errno::ENOENT)
|
48
52
|
end
|
53
|
+
|
54
|
+
describe "#unique?" do
|
55
|
+
it "returns true when it is unique" do
|
56
|
+
test_table.index("email").unique?.should eq true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "returns false when it isn't unique" do
|
60
|
+
test_table.index("text").unique?.should eq false
|
61
|
+
end
|
62
|
+
end
|
49
63
|
end
|
metadata
CHANGED
@@ -1,85 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: baza
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kasper Johansen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: datet
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.0.25
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.0.25
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: wref
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.0.8
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.0.8
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: knjrbfw
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 0.0.111
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 0.0.111
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: array_enumerator
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.0.7
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 0.0.7
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: string-cases
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 0.0.1
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 0.0.1
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -195,6 +195,8 @@ files:
|
|
195
195
|
- Rakefile
|
196
196
|
- VERSION
|
197
197
|
- baza.gemspec
|
198
|
+
- include/cloner.rb
|
199
|
+
- include/column.rb
|
198
200
|
- include/db.rb
|
199
201
|
- include/dbtime.rb
|
200
202
|
- include/driver.rb
|
@@ -211,8 +213,6 @@ files:
|
|
211
213
|
- include/drivers/mysql/mysql_sqlspecs.rb
|
212
214
|
- include/drivers/mysql/mysql_table.rb
|
213
215
|
- include/drivers/mysql/mysql_tables.rb
|
214
|
-
- include/drivers/sqlite3/libknjdb_java_sqlite3.rb
|
215
|
-
- include/drivers/sqlite3/libknjdb_sqlite3_ironruby.rb
|
216
216
|
- include/drivers/sqlite3/sqlite3.rb
|
217
217
|
- include/drivers/sqlite3/sqlite3_column.rb
|
218
218
|
- include/drivers/sqlite3/sqlite3_columns.rb
|
@@ -225,6 +225,7 @@ files:
|
|
225
225
|
- include/drivers/sqlite3/sqlite3_tables.rb
|
226
226
|
- include/dump.rb
|
227
227
|
- include/idquery.rb
|
228
|
+
- include/index.rb
|
228
229
|
- include/model.rb
|
229
230
|
- include/model_custom.rb
|
230
231
|
- include/model_handler.rb
|
@@ -233,8 +234,10 @@ files:
|
|
233
234
|
- include/revision.rb
|
234
235
|
- include/row.rb
|
235
236
|
- include/sqlspecs.rb
|
237
|
+
- include/table.rb
|
236
238
|
- lib/baza.rb
|
237
239
|
- shippable.yml
|
240
|
+
- spec/include/cloner_spec.rb
|
238
241
|
- spec/include/drivers/active_record_spec.rb
|
239
242
|
- spec/include/drivers/mysql_spec.rb
|
240
243
|
- spec/include/drivers/sqlite3_spec.rb
|
@@ -270,7 +273,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
270
273
|
version: '0'
|
271
274
|
requirements: []
|
272
275
|
rubyforge_project:
|
273
|
-
rubygems_version: 2.
|
276
|
+
rubygems_version: 2.2.2
|
274
277
|
signing_key:
|
275
278
|
specification_version: 4
|
276
279
|
summary: A database abstraction layer, model framework and database framework.
|
@@ -1,78 +0,0 @@
|
|
1
|
-
class KnjDB_java_sqlite3
|
2
|
-
def escape_table
|
3
|
-
return "`"
|
4
|
-
end
|
5
|
-
|
6
|
-
def escape_col
|
7
|
-
return "`"
|
8
|
-
end
|
9
|
-
|
10
|
-
def escape_val
|
11
|
-
return "'"
|
12
|
-
end
|
13
|
-
|
14
|
-
def initialize(baza_db_obj)
|
15
|
-
@baza_db = baza_db_obj
|
16
|
-
|
17
|
-
if @baza_db.opts[:sqlite_driver]
|
18
|
-
require @baza_db.opts[:sqlite_driver]
|
19
|
-
else
|
20
|
-
require File.dirname(__FILE__) + "/sqlitejdbc-v056.jar"
|
21
|
-
end
|
22
|
-
|
23
|
-
require "java"
|
24
|
-
import "org.sqlite.JDBC"
|
25
|
-
@conn = java.sql.DriverManager::getConnection("jdbc:sqlite:" + @baza_db.opts[:path])
|
26
|
-
@stat = @conn.createStatement
|
27
|
-
end
|
28
|
-
|
29
|
-
def query(string)
|
30
|
-
begin
|
31
|
-
return KnjDB_java_sqlite3_result.new(@stat.executeQuery(string))
|
32
|
-
rescue java.sql.SQLException => e
|
33
|
-
if e.message == "java.sql.SQLException: query does not return ResultSet"
|
34
|
-
#ignore it.
|
35
|
-
else
|
36
|
-
raise e
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def fetch(result)
|
42
|
-
return result.fetch
|
43
|
-
end
|
44
|
-
|
45
|
-
def escape(string)
|
46
|
-
return "" unless string
|
47
|
-
string = string.gsub("'", "\\'")
|
48
|
-
return string
|
49
|
-
end
|
50
|
-
|
51
|
-
def last_id
|
52
|
-
return @conn.last_insert_row_id
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
class KnjDB_java_sqlite3_result
|
57
|
-
def initialize(rs)
|
58
|
-
@rs = rs
|
59
|
-
@index = 0
|
60
|
-
|
61
|
-
if rs
|
62
|
-
@metadata = rs.getMetaData
|
63
|
-
@columns_count = @metadata.getColumnCount
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def fetch
|
68
|
-
return false unless @rs.next
|
69
|
-
|
70
|
-
tha_return = {}
|
71
|
-
for i in (1..@columns_count)
|
72
|
-
col_name = @metadata.getColumnName(i)
|
73
|
-
tha_return.store(col_name, @rs.getString(i))
|
74
|
-
end
|
75
|
-
|
76
|
-
return tha_return
|
77
|
-
end
|
78
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require "Mono.Data.Sqlite, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756"
|
2
|
-
require "Mono.Data.SqliteClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756"
|
3
|
-
|
4
|
-
class Baza::Driver::Sqlite3_ironruby
|
5
|
-
def escape_table
|
6
|
-
return "`"
|
7
|
-
end
|
8
|
-
|
9
|
-
def escape_col
|
10
|
-
return "`"
|
11
|
-
end
|
12
|
-
|
13
|
-
def escape_val
|
14
|
-
return "'"
|
15
|
-
end
|
16
|
-
|
17
|
-
def initialize(baza_db_obj)
|
18
|
-
@baza_db = baza_db_obj
|
19
|
-
@conn = Mono::Data::SqliteClient::SqliteConnection.new("URI=file:" + @baza_db.opts[:path] + ",version=3")
|
20
|
-
@conn.Open
|
21
|
-
end
|
22
|
-
|
23
|
-
def query(string)
|
24
|
-
dbcmd = @conn.CreateCommand
|
25
|
-
dbcmd.CommandText = string
|
26
|
-
reader = dbcmd.ExecuteReader
|
27
|
-
return Baza::Driver::Sqlite3_ironruby_result.new(reader)
|
28
|
-
end
|
29
|
-
|
30
|
-
def escape(string)
|
31
|
-
if (!string)
|
32
|
-
return ""
|
33
|
-
end
|
34
|
-
|
35
|
-
string = string.gsub("'", "\\'")
|
36
|
-
return string
|
37
|
-
end
|
38
|
-
|
39
|
-
def last_id
|
40
|
-
return @conn.last_insert_row_id
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
class Baza::Driver::Sqlite3_ironruby_result
|
45
|
-
def initialize(reader)
|
46
|
-
@reader = reader
|
47
|
-
end
|
48
|
-
|
49
|
-
def fetch
|
50
|
-
if !@reader.Read
|
51
|
-
return false
|
52
|
-
end
|
53
|
-
|
54
|
-
ret = {}
|
55
|
-
|
56
|
-
count = 0
|
57
|
-
while true
|
58
|
-
begin
|
59
|
-
ret[@reader.get_name(count)] = @reader.get_string(count)
|
60
|
-
rescue IndexError => e
|
61
|
-
break
|
62
|
-
end
|
63
|
-
|
64
|
-
count += 1
|
65
|
-
end
|
66
|
-
|
67
|
-
return ret
|
68
|
-
end
|
69
|
-
end
|