activerecord-nuodb-adapter 1.0.0.rc.1
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/.buildpath +5 -0
- data/.gitignore +3 -0
- data/AUTHORS +4 -0
- data/COPYING +25 -0
- data/Gemfile +9 -0
- data/History.txt +4 -0
- data/LICENSE +26 -0
- data/Manifest.txt +11 -0
- data/README.rdoc +69 -0
- data/Rakefile +134 -0
- data/activerecord-nuodb-adapter.gemspec +25 -0
- data/lib/active_record/connection_adapters/nuodb/version.rb +35 -0
- data/lib/active_record/connection_adapters/nuodb_adapter.rb +778 -0
- data/lib/activerecord-nuodb-adapter.rb +29 -0
- data/lib/arel/visitors/nuodb.rb +55 -0
- data/test/test_simple.rb +181 -0
- metadata +130 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2012, NuoDB, Inc.
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# * Redistributions of source code must retain the above copyright
|
9
|
+
# notice, this list of conditions and the following disclaimer.
|
10
|
+
# * Redistributions in binary form must reproduce the above copyright
|
11
|
+
# notice, this list of conditions and the following disclaimer in the
|
12
|
+
# documentation and/or other materials provided with the distribution.
|
13
|
+
# * Neither the name of NuoDB, Inc. nor the names of its contributors may
|
14
|
+
# be used to endorse or promote products derived from this software
|
15
|
+
# without specific prior written permission.
|
16
|
+
#
|
17
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
18
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20
|
+
# DISCLAIMED. IN NO EVENT SHALL NUODB, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
|
21
|
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22
|
+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
23
|
+
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
24
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
25
|
+
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
26
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
#
|
28
|
+
|
29
|
+
require 'active_record/connection_adapters/nuodb_adapter'
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2012, NuoDB, Inc.
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# * Redistributions of source code must retain the above copyright
|
9
|
+
# notice, this list of conditions and the following disclaimer.
|
10
|
+
# * Redistributions in binary form must reproduce the above copyright
|
11
|
+
# notice, this list of conditions and the following disclaimer in the
|
12
|
+
# documentation and/or other materials provided with the distribution.
|
13
|
+
# * Neither the name of NuoDB, Inc. nor the names of its contributors may
|
14
|
+
# be used to endorse or promote products derived from this software
|
15
|
+
# without specific prior written permission.
|
16
|
+
#
|
17
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
18
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20
|
+
# DISCLAIMED. IN NO EVENT SHALL NUODB, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
|
21
|
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22
|
+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
23
|
+
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
24
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
25
|
+
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
26
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
#
|
28
|
+
|
29
|
+
module Arel
|
30
|
+
|
31
|
+
module Visitors
|
32
|
+
|
33
|
+
class NuoDB < Arel::Visitors::ToSql
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def visit_Arel_Nodes_SelectStatement o
|
38
|
+
[
|
39
|
+
(visit(o.with) if o.with),
|
40
|
+
o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join,
|
41
|
+
("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?),
|
42
|
+
(visit(o.offset) if o.offset),
|
43
|
+
(visit(o.limit) if o.limit),
|
44
|
+
(visit(o.lock) if o.lock),
|
45
|
+
].compact.join ' '
|
46
|
+
end
|
47
|
+
|
48
|
+
def visit_Arel_Nodes_Limit(o)
|
49
|
+
"FETCH FIRST #{visit o.expr} ROWS ONLY"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
data/test/test_simple.rb
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2012, NuoDB, Inc.
|
3
|
+
# All rights reserved.
|
4
|
+
#
|
5
|
+
# Redistribution and use in source and binary forms, with or without
|
6
|
+
# modification, are permitted provided that the following conditions are met:
|
7
|
+
#
|
8
|
+
# * Redistributions of source code must retain the above copyright
|
9
|
+
# notice, this list of conditions and the following disclaimer.
|
10
|
+
# * Redistributions in binary form must reproduce the above copyright
|
11
|
+
# notice, this list of conditions and the following disclaimer in the
|
12
|
+
# documentation and/or other materials provided with the distribution.
|
13
|
+
# * Neither the name of NuoDB, Inc. nor the names of its contributors may
|
14
|
+
# be used to endorse or promote products derived from this software
|
15
|
+
# without specific prior written permission.
|
16
|
+
#
|
17
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
18
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20
|
+
# DISCLAIMED. IN NO EVENT SHALL NUODB, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
|
21
|
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22
|
+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
23
|
+
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
24
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
25
|
+
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
26
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
#
|
28
|
+
|
29
|
+
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), '../lib'))
|
30
|
+
|
31
|
+
require "test/unit"
|
32
|
+
require 'rubygems'
|
33
|
+
require 'active_record'
|
34
|
+
|
35
|
+
class User < ActiveRecord::Base
|
36
|
+
has_one :addr, :class_name => 'Addr'
|
37
|
+
|
38
|
+
def to_s
|
39
|
+
return "User(#{@id}), Username: #{@user_name}, Name: #{@first_name} #{@last_name}, #{@admin ? "admin" : "member"}\n" +
|
40
|
+
" Address: #{@addr}\n"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class Addr < ActiveRecord::Base
|
45
|
+
belongs_to :User
|
46
|
+
|
47
|
+
def to_s
|
48
|
+
return "Addr(#{@id}:#{@user_id}) Street: #{@street} City: #{@city} Zip: #{@zip}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class NuoSimpleTest < Test::Unit::TestCase
|
53
|
+
|
54
|
+
def setup()
|
55
|
+
|
56
|
+
ActiveRecord::Base.establish_connection(
|
57
|
+
:adapter => 'nuodb',
|
58
|
+
:database => 'test',
|
59
|
+
:schema => 'test',
|
60
|
+
:username => 'cloud',
|
61
|
+
:password => 'user'
|
62
|
+
)
|
63
|
+
|
64
|
+
ActiveRecord::Schema.drop_table(User.table_name) rescue nil
|
65
|
+
|
66
|
+
ActiveRecord::Schema.drop_table(Addr.table_name) rescue nil
|
67
|
+
|
68
|
+
ActiveRecord::Schema.define do
|
69
|
+
create_table User.table_name do |t|
|
70
|
+
t.string :first_name, :limit => 20
|
71
|
+
t.string :last_name, :limit => 20
|
72
|
+
t.string :email, :limit => 20
|
73
|
+
t.string :user_name, :limit => 20
|
74
|
+
t.boolean :admin
|
75
|
+
end
|
76
|
+
create_table Addr.table_name do |t|
|
77
|
+
t.integer :user_id
|
78
|
+
t.string :street, :limit => 20
|
79
|
+
t.string :city, :limit => 20
|
80
|
+
t.string :zip, :limit => 6
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
def test_create_user_records
|
88
|
+
|
89
|
+
fred = User.create do |u|
|
90
|
+
u.first_name = "Fred"
|
91
|
+
u.last_name = "Flintstone"
|
92
|
+
u.email = "fredf@example.com"
|
93
|
+
u.user_name = "fred"
|
94
|
+
u.admin = true
|
95
|
+
end
|
96
|
+
|
97
|
+
assert_not_nil fred
|
98
|
+
assert_not_nil fred.id
|
99
|
+
|
100
|
+
fred.create_addr do |a|
|
101
|
+
a.street = "301 Cobblestone Way"
|
102
|
+
a.city = "Bedrock"
|
103
|
+
a.zip = "00001"
|
104
|
+
end
|
105
|
+
|
106
|
+
assert_not_nil fred.addr
|
107
|
+
|
108
|
+
barney = User.create do |u|
|
109
|
+
u.first_name = "Barney"
|
110
|
+
u.last_name = "Rubble"
|
111
|
+
u.email = "barney@example.com"
|
112
|
+
u.user_name = "barney"
|
113
|
+
u.admin = false
|
114
|
+
end
|
115
|
+
|
116
|
+
assert_not_nil barney
|
117
|
+
assert_not_nil barney.id
|
118
|
+
|
119
|
+
barney.create_addr do |a|
|
120
|
+
a.street = "303 Cobblestone Way"
|
121
|
+
a.city = "Bedrock"
|
122
|
+
a.zip = "00001"
|
123
|
+
end
|
124
|
+
|
125
|
+
assert_not_nil barney.addr
|
126
|
+
|
127
|
+
assert_equal 2, User.count
|
128
|
+
|
129
|
+
assert_equal 2, Addr.count
|
130
|
+
|
131
|
+
mask = 0
|
132
|
+
User.find do |entry|
|
133
|
+
case entry.id
|
134
|
+
when fred.id
|
135
|
+
assert_equal 'Fred', entry.first_name
|
136
|
+
assert_equal 'Flintstone', entry.last_name
|
137
|
+
assert_equal '301 Cobblestone Way', entry.addr.street
|
138
|
+
mask += 1
|
139
|
+
nil
|
140
|
+
when barney.id
|
141
|
+
assert_equal 'Barney', entry.first_name
|
142
|
+
assert_equal 'Rubble', entry.last_name
|
143
|
+
assert_equal '303 Cobblestone Way', entry.addr.street
|
144
|
+
mask += 10
|
145
|
+
nil
|
146
|
+
else
|
147
|
+
raise "unknown entry.id: #{entry.id}"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
assert_equal 11, mask
|
152
|
+
|
153
|
+
User.all.each do |entry|
|
154
|
+
entry.first_name = entry.first_name.upcase
|
155
|
+
entry.last_name = entry.last_name.upcase
|
156
|
+
# TODO entry.admin = !entry.admin
|
157
|
+
entry.addr.street = entry.addr.street.upcase
|
158
|
+
entry.addr.save
|
159
|
+
entry.save
|
160
|
+
end
|
161
|
+
|
162
|
+
assert_equal 2, User.count
|
163
|
+
|
164
|
+
User.find do |entry|
|
165
|
+
case entry.id
|
166
|
+
when fred.id
|
167
|
+
assert_equal 'FRED', entry.first_name
|
168
|
+
assert_equal '301 COBBLESTONE WAY', entry.addr.street
|
169
|
+
nil
|
170
|
+
when barney.id
|
171
|
+
assert_equal 'BARNEY', entry.first_name
|
172
|
+
assert_equal '303 COBBLESTONE WAY', entry.addr.street
|
173
|
+
nil
|
174
|
+
else
|
175
|
+
raise 'unknown entry.id'
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activerecord-nuodb-adapter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.rc.1
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Robert Buck
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activerecord
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.2.8
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.2.8
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0.9'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.9'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rdoc
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.10'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.10'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: nuodb
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.0.0.rc.1
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.0.0.rc.1
|
78
|
+
description: An adapter for ActiveRecord and AREL to support the NuoDB distributed
|
79
|
+
database backend.
|
80
|
+
email:
|
81
|
+
- support@nuodb.com
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files:
|
85
|
+
- README.rdoc
|
86
|
+
files:
|
87
|
+
- .buildpath
|
88
|
+
- .gitignore
|
89
|
+
- AUTHORS
|
90
|
+
- COPYING
|
91
|
+
- Gemfile
|
92
|
+
- History.txt
|
93
|
+
- LICENSE
|
94
|
+
- Manifest.txt
|
95
|
+
- README.rdoc
|
96
|
+
- Rakefile
|
97
|
+
- activerecord-nuodb-adapter.gemspec
|
98
|
+
- lib/active_record/connection_adapters/nuodb/version.rb
|
99
|
+
- lib/active_record/connection_adapters/nuodb_adapter.rb
|
100
|
+
- lib/activerecord-nuodb-adapter.rb
|
101
|
+
- lib/arel/visitors/nuodb.rb
|
102
|
+
- test/test_simple.rb
|
103
|
+
homepage: http://nuodb.github.com/ruby-activerecord-nuodb-adapter/
|
104
|
+
licenses:
|
105
|
+
- BSD
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options:
|
108
|
+
- --charset=UTF-8
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ! '>'
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 1.3.1
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 1.8.24
|
126
|
+
signing_key:
|
127
|
+
specification_version: 3
|
128
|
+
summary: ActiveRecord adapter with AREL support for NuoDB.
|
129
|
+
test_files:
|
130
|
+
- test/test_simple.rb
|