wraithdb 0.0.2 → 0.0.3
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.
- data/lib/rails/3.0/active_record/base.rb +1 -1
- data/lib/wraithdb/adapters/default_adapter.rb +11 -0
- data/lib/wraithdb/adapters/mysql2_adapter.rb +31 -0
- data/lib/wraithdb/adapters/wraith_functionality.rb +28 -0
- data/lib/wraithdb/schema.rb +14 -4
- data/lib/wraithdb/version.rb +1 -1
- data/lib/wraithdb.rb +1 -1
- metadata +4 -2
- data/lib/wraithdb/adapter.rb +0 -43
@@ -5,7 +5,7 @@ module ActiveRecord
|
|
5
5
|
#an actual connection. The implementation provided mirrors the Mysql2Adapter
|
6
6
|
def replace_bind_variables_with_wraithdb(statement, values)
|
7
7
|
begin
|
8
|
-
replace_bind_variables_without_wraithdb
|
8
|
+
replace_bind_variables_without_wraithdb(statement, values)
|
9
9
|
rescue StandardError => e
|
10
10
|
raise e if e.kind_of? PreparedStatementInvalid
|
11
11
|
bound = values.dup
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'active_record/connection_adapters/mysql2_adapter'
|
2
|
+
|
3
|
+
module WraithDB
|
4
|
+
module Adapters
|
5
|
+
class Mysql2Adapter < ActiveRecord::ConnectionAdapters::Mysql2Adapter
|
6
|
+
include WraithFunctionality
|
7
|
+
|
8
|
+
def quote(value, column = nil)
|
9
|
+
if value.kind_of?(String) && column && column.type == :binary && column.class.respond_to?(:string_to_binary)
|
10
|
+
s = column.class.string_to_binary(value).unpack("H*")[0]
|
11
|
+
"x'#{s}'"
|
12
|
+
elsif value.kind_of?(BigDecimal)
|
13
|
+
value.to_s("F")
|
14
|
+
else
|
15
|
+
super
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Quotes a string, escaping any ' (single quote) and \ (backslash)
|
20
|
+
# characters.
|
21
|
+
def quote_string(s)
|
22
|
+
s.gsub(/\\/, '\&\&').gsub(/'/, "\\\\'") # ' (for ruby-mode)
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def adapter_name
|
27
|
+
'WraithMysql2'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module WraithDB
|
2
|
+
module Adapters
|
3
|
+
module WraithFunctionality
|
4
|
+
attr_reader :tables
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@active = true
|
8
|
+
@tables = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def support_migrations?
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_table(table_name, options = {})
|
16
|
+
table_definition = ActiveRecord::ConnectionAdapters::TableDefinition.new(self)
|
17
|
+
table_definition.primary_key(options[:primary_key] || ActiveRecord::Base.get_primary_key(table_name.to_s.singularize)) unless options[:id] == false
|
18
|
+
|
19
|
+
yield table_definition if block_given?
|
20
|
+
|
21
|
+
@tables[table_name.to_s] = table_definition
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_index(*args)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/wraithdb/schema.rb
CHANGED
@@ -10,14 +10,24 @@ module WraithDB
|
|
10
10
|
|
11
11
|
def connection
|
12
12
|
load
|
13
|
-
@connection ||=
|
13
|
+
@connection ||= build_connection
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
|
16
|
+
def build_connection
|
17
|
+
type = ActiveRecord::Base.configurations[Rails.env]['adapter']
|
18
|
+
type = 'default' unless File.exist?(adapter_path(type))
|
19
|
+
|
20
|
+
require adapter_path(type)
|
21
|
+
|
22
|
+
WraithDB::Adapters.const_get("#{type.capitalize}Adapter").new
|
18
23
|
end
|
19
24
|
|
20
|
-
def
|
25
|
+
def adapter_path(type)
|
26
|
+
"#{File.expand_path('..', __FILE__)}/adapters/#{type}_adapter.rb"
|
27
|
+
end
|
28
|
+
|
29
|
+
def tables
|
30
|
+
connection.tables
|
21
31
|
end
|
22
32
|
|
23
33
|
def load
|
data/lib/wraithdb/version.rb
CHANGED
data/lib/wraithdb.rb
CHANGED
@@ -2,7 +2,7 @@ require 'active_record/connection_adapters/abstract/schema_definitions'
|
|
2
2
|
require "wraithdb/version"
|
3
3
|
require 'wraithdb/schema'
|
4
4
|
require 'wraithdb/column'
|
5
|
-
require 'wraithdb/
|
5
|
+
require 'wraithdb/adapters/wraith_functionality'
|
6
6
|
|
7
7
|
dir_path = File.expand_path('..', __FILE__)
|
8
8
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wraithdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -53,7 +53,9 @@ files:
|
|
53
53
|
- lib/rails/3.0/arel/table.rb
|
54
54
|
- lib/rails/3.2/active_record/model_schema.rb
|
55
55
|
- lib/wraithdb.rb
|
56
|
-
- lib/wraithdb/
|
56
|
+
- lib/wraithdb/adapters/default_adapter.rb
|
57
|
+
- lib/wraithdb/adapters/mysql2_adapter.rb
|
58
|
+
- lib/wraithdb/adapters/wraith_functionality.rb
|
57
59
|
- lib/wraithdb/column.rb
|
58
60
|
- lib/wraithdb/schema.rb
|
59
61
|
- lib/wraithdb/version.rb
|
data/lib/wraithdb/adapter.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
module WraithDB
|
2
|
-
class Adapter < ActiveRecord::ConnectionAdapters::AbstractAdapter
|
3
|
-
attr_reader :tables
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
super(nil)
|
7
|
-
@active = true
|
8
|
-
@tables = {}
|
9
|
-
end
|
10
|
-
|
11
|
-
def quote(value, column = nil)
|
12
|
-
if value.kind_of?(String) && column && column.type == :binary && column.class.respond_to?(:string_to_binary)
|
13
|
-
s = column.class.string_to_binary(value).unpack("H*")[0]
|
14
|
-
"x'#{s}'"
|
15
|
-
elsif value.kind_of?(BigDecimal)
|
16
|
-
value.to_s("F")
|
17
|
-
else
|
18
|
-
super
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def adapter_name
|
23
|
-
'WraithDB'
|
24
|
-
end
|
25
|
-
|
26
|
-
def support_migrations?
|
27
|
-
true
|
28
|
-
end
|
29
|
-
|
30
|
-
def create_table(table_name, options = {})
|
31
|
-
table_definition = ActiveRecord::ConnectionAdapters::TableDefinition.new(self)
|
32
|
-
table_definition.primary_key(options[:primary_key] || ActiveRecord::Base.get_primary_key(table_name.to_s.singularize)) unless options[:id] == false
|
33
|
-
|
34
|
-
yield table_definition if block_given?
|
35
|
-
|
36
|
-
@tables[table_name.to_s] = table_definition
|
37
|
-
end
|
38
|
-
|
39
|
-
def add_index(*args)
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|