activerecord-tidb-adapter 6.1.2 → 7.0.0
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/.buildkite/pipeline.yml +1 -1
- data/.github/workflows/ci.yml +13 -7
- data/Gemfile +3 -1
- data/Gemfile.lock +104 -82
- data/README.md +44 -20
- data/activerecord-tidb-adapter.gemspec +2 -2
- data/lib/active_record/connection_adapters/tidb/database_statements.rb +8 -1
- data/lib/active_record/connection_adapters/tidb_adapter.rb +13 -10
- data/lib/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 77b7efd6ea4bc98b6a72a6fb761aaab270881143f79eb362369b38e6cfa8965e
|
|
4
|
+
data.tar.gz: 878ca587a425ae2dd5fbe5bd2da03518b0dc7501c1b99a8c2f92c03fa39b1e19
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c8a5a80313df31083a7c0d54f8e2145ca148293f1844c644bb7530f77e1e73d736e9c79ae5c1d3b89d3b94fae5024bc565ec80a1cb659508e105a2894734c660
|
|
7
|
+
data.tar.gz: d6004fba604462b1358166c96ed905161dfb40c38285d9050ee0c42497ec6ad32bc897640b628cdc35a7c977d36688905d78a92d84308f7ce9bb76d8cf9171eb
|
data/.buildkite/pipeline.yml
CHANGED
data/.github/workflows/ci.yml
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
name: activerecord-tidb-adapter
|
|
1
|
+
name: activerecord-tidb-adapter main
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
4
|
push:
|
|
5
5
|
branches:
|
|
6
|
-
-
|
|
6
|
+
- main
|
|
7
|
+
- 7-0-stable
|
|
7
8
|
paths-ignore:
|
|
8
9
|
- 'README*.md'
|
|
9
10
|
- 'docs/**'
|
|
10
11
|
pull_request:
|
|
11
12
|
branches:
|
|
12
|
-
-
|
|
13
|
+
- main
|
|
14
|
+
- 7-0-stable
|
|
13
15
|
paths-ignore:
|
|
14
16
|
- 'README*.md'
|
|
15
17
|
- 'docs/**'
|
|
@@ -29,7 +31,8 @@ jobs:
|
|
|
29
31
|
- uses: ruby/setup-ruby@v1
|
|
30
32
|
with:
|
|
31
33
|
ruby-version: 2.7
|
|
32
|
-
bundler-cache:
|
|
34
|
+
bundler-cache: false
|
|
35
|
+
- run: bundle install
|
|
33
36
|
- run: sleep 30 && MYSQL_USER=root MYSQL_HOST=127.0.0.1 MYSQL_PORT=4000 tidb=1 ARCONN=tidb bundle exec rake db:tidb:build
|
|
34
37
|
- run: sleep 10 && MYSQL_USER=root MYSQL_HOST=127.0.0.1 MYSQL_PORT=4000 tidb=1 ARCONN=tidb bundle exec rake test:tidb
|
|
35
38
|
|
|
@@ -47,7 +50,8 @@ jobs:
|
|
|
47
50
|
- uses: ruby/setup-ruby@v1
|
|
48
51
|
with:
|
|
49
52
|
ruby-version: 2.7
|
|
50
|
-
bundler-cache:
|
|
53
|
+
bundler-cache: false
|
|
54
|
+
- run: bundle install
|
|
51
55
|
- run: sleep 30 && MYSQL_USER=root MYSQL_HOST=127.0.0.1 MYSQL_PORT=4000 tidb=1 ARCONN=tidb bundle exec rake db:tidb:build
|
|
52
56
|
- run: mysql --host 127.0.0.1 --database activerecord_unittest --port 4000 -u root -e 'set @@global.tidb_enable_change_column_type = 1'
|
|
53
57
|
- run: mysql --host 127.0.0.1 --database activerecord_unittest2 --port 4000 -u root -e 'set @@global.tidb_enable_change_column_type = 1'
|
|
@@ -67,7 +71,8 @@ jobs:
|
|
|
67
71
|
- uses: ruby/setup-ruby@v1
|
|
68
72
|
with:
|
|
69
73
|
ruby-version: 2.7
|
|
70
|
-
bundler-cache:
|
|
74
|
+
bundler-cache: false
|
|
75
|
+
- run: bundle install
|
|
71
76
|
- run: sleep 30 && MYSQL_USER=root MYSQL_HOST=127.0.0.1 MYSQL_PORT=4000 tidb=1 ARCONN=tidb bundle exec rake db:tidb:build
|
|
72
77
|
- run: sleep 10 && MYSQL_USER=root MYSQL_HOST=127.0.0.1 MYSQL_PORT=4000 tidb=1 ARCONN=tidb bundle exec rake test:tidb
|
|
73
78
|
|
|
@@ -85,6 +90,7 @@ jobs:
|
|
|
85
90
|
- uses: ruby/setup-ruby@v1
|
|
86
91
|
with:
|
|
87
92
|
ruby-version: 2.7
|
|
88
|
-
bundler-cache:
|
|
93
|
+
bundler-cache: false
|
|
94
|
+
- run: bundle install
|
|
89
95
|
- run: sleep 30 && MYSQL_USER=root MYSQL_HOST=127.0.0.1 MYSQL_PORT=4000 tidb=1 ARCONN=tidb bundle exec rake db:tidb:build
|
|
90
96
|
- run: sleep 10 && MYSQL_USER=root MYSQL_HOST=127.0.0.1 MYSQL_PORT=4000 tidb=1 ARCONN=tidb bundle exec rake test:tidb
|
data/Gemfile
CHANGED
|
@@ -14,10 +14,12 @@ gem 'pry'
|
|
|
14
14
|
|
|
15
15
|
gem 'rubocop', '~> 1.18'
|
|
16
16
|
|
|
17
|
-
gem 'rails', git: 'https://github.com/pingcap/rails.git', branch: '
|
|
17
|
+
gem 'rails', git: 'https://github.com/pingcap/rails.git', branch: '7-0-stable'
|
|
18
18
|
|
|
19
19
|
gem 'byebug', '~> 11.1'
|
|
20
20
|
|
|
21
21
|
gem 'sqlite3', '~> 1.4'
|
|
22
22
|
|
|
23
23
|
gem 'pg', '~> 1.2'
|
|
24
|
+
|
|
25
|
+
gem "benchmark-ips", "~> 2.9"
|
data/Gemfile.lock
CHANGED
|
@@ -1,126 +1,150 @@
|
|
|
1
1
|
GIT
|
|
2
2
|
remote: https://github.com/pingcap/rails.git
|
|
3
|
-
revision:
|
|
4
|
-
branch:
|
|
3
|
+
revision: 8e88c0ecd838d642c542e8246a0b7c6e9df9c806
|
|
4
|
+
branch: 7-0-stable
|
|
5
5
|
specs:
|
|
6
|
-
actioncable (
|
|
7
|
-
actionpack (=
|
|
8
|
-
activesupport (=
|
|
6
|
+
actioncable (7.0.2.3)
|
|
7
|
+
actionpack (= 7.0.2.3)
|
|
8
|
+
activesupport (= 7.0.2.3)
|
|
9
9
|
nio4r (~> 2.0)
|
|
10
10
|
websocket-driver (>= 0.6.1)
|
|
11
|
-
actionmailbox (
|
|
12
|
-
actionpack (=
|
|
13
|
-
activejob (=
|
|
14
|
-
activerecord (=
|
|
15
|
-
activestorage (=
|
|
16
|
-
activesupport (=
|
|
11
|
+
actionmailbox (7.0.2.3)
|
|
12
|
+
actionpack (= 7.0.2.3)
|
|
13
|
+
activejob (= 7.0.2.3)
|
|
14
|
+
activerecord (= 7.0.2.3)
|
|
15
|
+
activestorage (= 7.0.2.3)
|
|
16
|
+
activesupport (= 7.0.2.3)
|
|
17
17
|
mail (>= 2.7.1)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
net-imap
|
|
19
|
+
net-pop
|
|
20
|
+
net-smtp
|
|
21
|
+
actionmailer (7.0.2.3)
|
|
22
|
+
actionpack (= 7.0.2.3)
|
|
23
|
+
actionview (= 7.0.2.3)
|
|
24
|
+
activejob (= 7.0.2.3)
|
|
25
|
+
activesupport (= 7.0.2.3)
|
|
23
26
|
mail (~> 2.5, >= 2.5.4)
|
|
27
|
+
net-imap
|
|
28
|
+
net-pop
|
|
29
|
+
net-smtp
|
|
24
30
|
rails-dom-testing (~> 2.0)
|
|
25
|
-
actionpack (
|
|
26
|
-
actionview (=
|
|
27
|
-
activesupport (=
|
|
28
|
-
rack (~> 2.0, >= 2.0
|
|
31
|
+
actionpack (7.0.2.3)
|
|
32
|
+
actionview (= 7.0.2.3)
|
|
33
|
+
activesupport (= 7.0.2.3)
|
|
34
|
+
rack (~> 2.0, >= 2.2.0)
|
|
29
35
|
rack-test (>= 0.6.3)
|
|
30
36
|
rails-dom-testing (~> 2.0)
|
|
31
37
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
32
|
-
actiontext (
|
|
33
|
-
actionpack (=
|
|
34
|
-
activerecord (=
|
|
35
|
-
activestorage (=
|
|
36
|
-
activesupport (=
|
|
38
|
+
actiontext (7.0.2.3)
|
|
39
|
+
actionpack (= 7.0.2.3)
|
|
40
|
+
activerecord (= 7.0.2.3)
|
|
41
|
+
activestorage (= 7.0.2.3)
|
|
42
|
+
activesupport (= 7.0.2.3)
|
|
43
|
+
globalid (>= 0.6.0)
|
|
37
44
|
nokogiri (>= 1.8.5)
|
|
38
|
-
actionview (
|
|
39
|
-
activesupport (=
|
|
45
|
+
actionview (7.0.2.3)
|
|
46
|
+
activesupport (= 7.0.2.3)
|
|
40
47
|
builder (~> 3.1)
|
|
41
48
|
erubi (~> 1.4)
|
|
42
49
|
rails-dom-testing (~> 2.0)
|
|
43
50
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
44
|
-
activejob (
|
|
45
|
-
activesupport (=
|
|
51
|
+
activejob (7.0.2.3)
|
|
52
|
+
activesupport (= 7.0.2.3)
|
|
46
53
|
globalid (>= 0.3.6)
|
|
47
|
-
activemodel (
|
|
48
|
-
activesupport (=
|
|
49
|
-
activerecord (
|
|
50
|
-
activemodel (=
|
|
51
|
-
activesupport (=
|
|
52
|
-
activestorage (
|
|
53
|
-
actionpack (=
|
|
54
|
-
activejob (=
|
|
55
|
-
activerecord (=
|
|
56
|
-
activesupport (=
|
|
57
|
-
marcel (~> 1.0
|
|
54
|
+
activemodel (7.0.2.3)
|
|
55
|
+
activesupport (= 7.0.2.3)
|
|
56
|
+
activerecord (7.0.2.3)
|
|
57
|
+
activemodel (= 7.0.2.3)
|
|
58
|
+
activesupport (= 7.0.2.3)
|
|
59
|
+
activestorage (7.0.2.3)
|
|
60
|
+
actionpack (= 7.0.2.3)
|
|
61
|
+
activejob (= 7.0.2.3)
|
|
62
|
+
activerecord (= 7.0.2.3)
|
|
63
|
+
activesupport (= 7.0.2.3)
|
|
64
|
+
marcel (~> 1.0)
|
|
58
65
|
mini_mime (>= 1.1.0)
|
|
59
|
-
activesupport (
|
|
66
|
+
activesupport (7.0.2.3)
|
|
60
67
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
61
68
|
i18n (>= 1.6, < 2)
|
|
62
69
|
minitest (>= 5.1)
|
|
63
70
|
tzinfo (~> 2.0)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
activesupport (= 6.1.4)
|
|
71
|
+
rails (7.0.2.3)
|
|
72
|
+
actioncable (= 7.0.2.3)
|
|
73
|
+
actionmailbox (= 7.0.2.3)
|
|
74
|
+
actionmailer (= 7.0.2.3)
|
|
75
|
+
actionpack (= 7.0.2.3)
|
|
76
|
+
actiontext (= 7.0.2.3)
|
|
77
|
+
actionview (= 7.0.2.3)
|
|
78
|
+
activejob (= 7.0.2.3)
|
|
79
|
+
activemodel (= 7.0.2.3)
|
|
80
|
+
activerecord (= 7.0.2.3)
|
|
81
|
+
activestorage (= 7.0.2.3)
|
|
82
|
+
activesupport (= 7.0.2.3)
|
|
77
83
|
bundler (>= 1.15.0)
|
|
78
|
-
railties (=
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
activesupport (= 6.1.4)
|
|
84
|
+
railties (= 7.0.2.3)
|
|
85
|
+
railties (7.0.2.3)
|
|
86
|
+
actionpack (= 7.0.2.3)
|
|
87
|
+
activesupport (= 7.0.2.3)
|
|
83
88
|
method_source
|
|
84
|
-
rake (>=
|
|
89
|
+
rake (>= 12.2)
|
|
85
90
|
thor (~> 1.0)
|
|
91
|
+
zeitwerk (~> 2.5)
|
|
86
92
|
|
|
87
93
|
PATH
|
|
88
94
|
remote: .
|
|
89
95
|
specs:
|
|
90
|
-
activerecord-tidb-adapter (
|
|
91
|
-
activerecord (~>
|
|
96
|
+
activerecord-tidb-adapter (7.0.0)
|
|
97
|
+
activerecord (~> 7.0.1)
|
|
92
98
|
mysql2
|
|
93
99
|
|
|
94
100
|
GEM
|
|
95
101
|
remote: https://rubygems.org/
|
|
96
102
|
specs:
|
|
97
103
|
ast (2.4.2)
|
|
104
|
+
benchmark-ips (2.9.1)
|
|
98
105
|
builder (3.2.4)
|
|
99
106
|
byebug (11.1.3)
|
|
100
107
|
coderay (1.1.3)
|
|
101
|
-
concurrent-ruby (1.1.
|
|
108
|
+
concurrent-ruby (1.1.10)
|
|
102
109
|
crass (1.0.6)
|
|
110
|
+
digest (3.1.0)
|
|
103
111
|
erubi (1.10.0)
|
|
104
|
-
globalid (0.
|
|
112
|
+
globalid (1.0.0)
|
|
105
113
|
activesupport (>= 5.0)
|
|
106
|
-
i18n (1.
|
|
114
|
+
i18n (1.10.0)
|
|
107
115
|
concurrent-ruby (~> 1.0)
|
|
108
|
-
|
|
116
|
+
io-wait (0.2.1)
|
|
117
|
+
loofah (2.15.0)
|
|
109
118
|
crass (~> 1.0.2)
|
|
110
119
|
nokogiri (>= 1.5.9)
|
|
111
120
|
mail (2.7.1)
|
|
112
121
|
mini_mime (>= 0.1.1)
|
|
113
|
-
marcel (1.0.
|
|
122
|
+
marcel (1.0.2)
|
|
114
123
|
method_source (1.0.0)
|
|
115
|
-
mini_mime (1.1.
|
|
124
|
+
mini_mime (1.1.2)
|
|
116
125
|
minitest (5.14.4)
|
|
117
126
|
minitest-excludes (2.0.1)
|
|
118
127
|
minitest (~> 5.0)
|
|
119
128
|
mysql2 (0.5.3)
|
|
129
|
+
net-imap (0.2.3)
|
|
130
|
+
digest
|
|
131
|
+
net-protocol
|
|
132
|
+
strscan
|
|
133
|
+
net-pop (0.1.1)
|
|
134
|
+
digest
|
|
135
|
+
net-protocol
|
|
136
|
+
timeout
|
|
137
|
+
net-protocol (0.1.2)
|
|
138
|
+
io-wait
|
|
139
|
+
timeout
|
|
140
|
+
net-smtp (0.3.1)
|
|
141
|
+
digest
|
|
142
|
+
net-protocol
|
|
143
|
+
timeout
|
|
120
144
|
nio4r (2.5.8)
|
|
121
|
-
nokogiri (1.
|
|
145
|
+
nokogiri (1.13.3-x86_64-darwin)
|
|
122
146
|
racc (~> 1.4)
|
|
123
|
-
nokogiri (1.
|
|
147
|
+
nokogiri (1.13.3-x86_64-linux)
|
|
124
148
|
racc (~> 1.4)
|
|
125
149
|
parallel (1.20.1)
|
|
126
150
|
parser (3.0.2.0)
|
|
@@ -129,14 +153,14 @@ GEM
|
|
|
129
153
|
pry (0.14.1)
|
|
130
154
|
coderay (~> 1.1)
|
|
131
155
|
method_source (~> 1.0)
|
|
132
|
-
racc (1.
|
|
156
|
+
racc (1.6.0)
|
|
133
157
|
rack (2.2.3)
|
|
134
158
|
rack-test (1.1.0)
|
|
135
159
|
rack (>= 1.0, < 3)
|
|
136
160
|
rails-dom-testing (2.0.3)
|
|
137
161
|
activesupport (>= 4.2.0)
|
|
138
162
|
nokogiri (>= 1.6)
|
|
139
|
-
rails-html-sanitizer (1.4.
|
|
163
|
+
rails-html-sanitizer (1.4.2)
|
|
140
164
|
loofah (~> 2.3)
|
|
141
165
|
rainbow (3.0.0)
|
|
142
166
|
rake (13.0.6)
|
|
@@ -154,29 +178,27 @@ GEM
|
|
|
154
178
|
rubocop-ast (1.10.0)
|
|
155
179
|
parser (>= 3.0.1.1)
|
|
156
180
|
ruby-progressbar (1.11.0)
|
|
157
|
-
sprockets (4.0.2)
|
|
158
|
-
concurrent-ruby (~> 1.0)
|
|
159
|
-
rack (> 1, < 3)
|
|
160
|
-
sprockets-rails (3.2.2)
|
|
161
|
-
actionpack (>= 4.0)
|
|
162
|
-
activesupport (>= 4.0)
|
|
163
|
-
sprockets (>= 3.0.0)
|
|
164
181
|
sqlite3 (1.4.2)
|
|
165
|
-
|
|
182
|
+
strscan (3.0.1)
|
|
183
|
+
thor (1.2.1)
|
|
184
|
+
timeout (0.2.0)
|
|
166
185
|
tzinfo (2.0.4)
|
|
167
186
|
concurrent-ruby (~> 1.0)
|
|
168
187
|
unicode-display_width (2.0.0)
|
|
169
188
|
websocket-driver (0.7.5)
|
|
170
189
|
websocket-extensions (>= 0.1.0)
|
|
171
190
|
websocket-extensions (0.1.5)
|
|
172
|
-
zeitwerk (2.4
|
|
191
|
+
zeitwerk (2.5.4)
|
|
173
192
|
|
|
174
193
|
PLATFORMS
|
|
175
194
|
x86_64-darwin-18
|
|
195
|
+
x86_64-darwin-20
|
|
196
|
+
x86_64-darwin-21
|
|
176
197
|
x86_64-linux
|
|
177
198
|
|
|
178
199
|
DEPENDENCIES
|
|
179
200
|
activerecord-tidb-adapter!
|
|
201
|
+
benchmark-ips (~> 2.9)
|
|
180
202
|
byebug (~> 11.1)
|
|
181
203
|
minitest (~> 5.0)
|
|
182
204
|
minitest-excludes (~> 2.0)
|
|
@@ -188,4 +210,4 @@ DEPENDENCIES
|
|
|
188
210
|
sqlite3 (~> 1.4)
|
|
189
211
|
|
|
190
212
|
BUNDLED WITH
|
|
191
|
-
2.
|
|
213
|
+
2.3.10
|
data/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# ActiveRecord TiDB Adapter
|
|
2
2
|
|
|
3
|
+
[](https://badge.fury.io/rb/activerecord-tidb-adapter)
|
|
4
|
+
[](https://github.com/pingcap/activerecord-tidb-adapter/actions/workflows/ci.yml)
|
|
5
|
+
|
|
3
6
|
TiDB adapter for ActiveRecord 5.2, 6.1 and 7.0
|
|
4
7
|
This is a lightweight extension of the mysql2 adapter that establishes compatibility with [TiDB](https://github.com/pingcap/tidb).
|
|
5
8
|
|
|
@@ -9,12 +12,12 @@ This is a lightweight extension of the mysql2 adapter that establishes compatibi
|
|
|
9
12
|
Add this line to your application's Gemfile:
|
|
10
13
|
|
|
11
14
|
```ruby
|
|
12
|
-
gem 'activerecord-tidb-adapter',
|
|
15
|
+
gem 'activerecord-tidb-adapter', '~> 6.1.0'
|
|
13
16
|
```
|
|
14
17
|
|
|
15
18
|
If you're using Rails 5.2, use the 5.2.x versions of this gem.
|
|
16
19
|
|
|
17
|
-
If you're using Rails
|
|
20
|
+
If you're using Rails 6.1, use the 6.1.x versions of this gem.
|
|
18
21
|
|
|
19
22
|
And then execute:
|
|
20
23
|
|
|
@@ -73,24 +76,6 @@ class TestSeq < ActiveRecord::Migration[6.1]
|
|
|
73
76
|
end
|
|
74
77
|
```
|
|
75
78
|
|
|
76
|
-
Generated DDL
|
|
77
|
-
```sql
|
|
78
|
-
mysql> show create table orders_seq\G;
|
|
79
|
-
*************************** 1. row ***************************
|
|
80
|
-
Sequence: orders_seq
|
|
81
|
-
Create Sequence: CREATE SEQUENCE `orders_seq` start with 1024 minvalue 1 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=InnoDB
|
|
82
|
-
|
|
83
|
-
mysql> show create table orders\G;
|
|
84
|
-
*************************** 1. row ***************************
|
|
85
|
-
Table: orders
|
|
86
|
-
Create Table: CREATE TABLE `orders` (
|
|
87
|
-
`id` bigint(20) NOT NULL DEFAULT nextval(`activerecord_tidb_adapter_demo_development`.`orders_seq`),
|
|
88
|
-
`name` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL,
|
|
89
|
-
PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */
|
|
90
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
|
|
91
|
-
|
|
92
|
-
```
|
|
93
|
-
|
|
94
79
|
This gem also adds a few helpers to interact with `SEQUENCE`
|
|
95
80
|
|
|
96
81
|
```ruby
|
|
@@ -104,6 +89,41 @@ ActiveRecord::Base.lastval("numbers")
|
|
|
104
89
|
ActiveRecord::Base.setval("numbers", 1234)
|
|
105
90
|
```
|
|
106
91
|
|
|
92
|
+
**[CTE](https://docs.pingcap.com/tidb/dev/sql-statement-with#with)**
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
$ bundle add activerecord-cte
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
```ruby
|
|
100
|
+
require 'activerecord/cte'
|
|
101
|
+
|
|
102
|
+
Post
|
|
103
|
+
.with(posts_with_tags: "SELECT * FROM posts WHERE tags_count > 0")
|
|
104
|
+
.from("posts_with_tags AS posts")
|
|
105
|
+
# WITH posts_with_tags AS (
|
|
106
|
+
# SELECT * FROM posts WHERE (tags_count > 0)
|
|
107
|
+
# )
|
|
108
|
+
# SELECT * FROM posts_with_tags AS posts
|
|
109
|
+
|
|
110
|
+
Post
|
|
111
|
+
.with(posts_with_tags: "SELECT * FROM posts WHERE tags_count > 0")
|
|
112
|
+
.from("posts_with_tags AS posts")
|
|
113
|
+
.count
|
|
114
|
+
|
|
115
|
+
# WITH posts_with_tags AS (
|
|
116
|
+
# SELECT * FROM posts WHERE (tags_count > 0)
|
|
117
|
+
# )
|
|
118
|
+
# SELECT COUNT(*) FROM posts_with_tags AS posts
|
|
119
|
+
|
|
120
|
+
Post
|
|
121
|
+
.with(posts_with_tags: Post.where("tags_count > 0"))
|
|
122
|
+
.from("posts_with_tags AS posts")
|
|
123
|
+
.count
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
|
|
107
127
|
|
|
108
128
|
## Setting up local TiDB server
|
|
109
129
|
|
|
@@ -118,6 +138,10 @@ Starting TiDB playground
|
|
|
118
138
|
$ tiup playground nightly
|
|
119
139
|
```
|
|
120
140
|
|
|
141
|
+
## Tutorials
|
|
142
|
+
|
|
143
|
+
* [Build a Rails App with TiDB and the ActiveRecord TiDB Adapter](https://gist.github.com/hooopo/83db933ab07a054f70e23da0ff945747)
|
|
144
|
+
|
|
121
145
|
## Development
|
|
122
146
|
|
|
123
147
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
|
12
12
|
spec.description = 'Allows the use of TiDB as a backend for ActiveRecord and Rails apps.'
|
|
13
13
|
spec.homepage = 'https://github.com/pingcap/activerecord-tidb-adapter'
|
|
14
14
|
spec.license = 'Apache-2.0'
|
|
15
|
-
spec.required_ruby_version = '>= 2.
|
|
15
|
+
spec.required_ruby_version = '>= 2.7.0'
|
|
16
16
|
|
|
17
17
|
# spec.metadata["allowed_push_host"] = "TODO: Set to 'https://mygemserver.com'"
|
|
18
18
|
|
|
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
|
|
|
29
29
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
30
30
|
spec.require_paths = ['lib']
|
|
31
31
|
|
|
32
|
-
spec.add_dependency 'activerecord', '~>
|
|
32
|
+
spec.add_dependency 'activerecord', '~> 7.0.1'
|
|
33
33
|
spec.add_dependency 'mysql2'
|
|
34
34
|
|
|
35
35
|
# Uncomment to register a new dependency of your gem
|
|
@@ -38,18 +38,22 @@ module ActiveRecord
|
|
|
38
38
|
ADAPTER_NAME = 'Tidb'
|
|
39
39
|
|
|
40
40
|
def supports_savepoints?
|
|
41
|
+
# https://github.com/pingcap/tidb/issues/6840 support is required
|
|
41
42
|
false
|
|
42
43
|
end
|
|
43
44
|
|
|
44
45
|
def supports_foreign_keys?
|
|
46
|
+
# https://github.com/pingcap/tidb/issues/18209 support is required
|
|
45
47
|
false
|
|
46
48
|
end
|
|
47
49
|
|
|
48
50
|
def supports_bulk_alter?
|
|
51
|
+
# https://github.com/pingcap/tidb/issues/14766 support is required
|
|
49
52
|
false
|
|
50
53
|
end
|
|
51
54
|
|
|
52
55
|
def supports_advisory_locks?
|
|
56
|
+
# https://github.com/pingcap/tidb/issues/14994 support is required
|
|
53
57
|
false
|
|
54
58
|
end
|
|
55
59
|
|
|
@@ -62,25 +66,23 @@ module ActiveRecord
|
|
|
62
66
|
end
|
|
63
67
|
|
|
64
68
|
def supports_index_sort_order?
|
|
65
|
-
#
|
|
66
|
-
|
|
69
|
+
# https://github.com/pingcap/tidb/issues/2519 support is required
|
|
70
|
+
false
|
|
67
71
|
end
|
|
68
72
|
|
|
69
73
|
def supports_expression_index?
|
|
70
|
-
|
|
74
|
+
sql = <<~SQL
|
|
75
|
+
SELECT VALUE
|
|
76
|
+
FROM INFORMATION_SCHEMA.CLUSTER_CONFIG
|
|
77
|
+
WHERE `KEY` = 'experimental.allow-expression-index' AND `TYPE` = 'tidb'
|
|
78
|
+
SQL
|
|
79
|
+
query_value(sql) == 'true'
|
|
71
80
|
end
|
|
72
81
|
|
|
73
82
|
def supports_common_table_expressions?
|
|
74
83
|
tidb_version >= '5.1.0'
|
|
75
84
|
end
|
|
76
85
|
|
|
77
|
-
def transaction_isolation_levels
|
|
78
|
-
{
|
|
79
|
-
read_committed: 'READ COMMITTED',
|
|
80
|
-
repeatable_read: 'REPEATABLE READ'
|
|
81
|
-
}
|
|
82
|
-
end
|
|
83
|
-
|
|
84
86
|
def initialize(connection, logger, conn_params, config)
|
|
85
87
|
super(connection, logger, conn_params, config)
|
|
86
88
|
|
|
@@ -108,6 +110,7 @@ module ActiveRecord
|
|
|
108
110
|
default_function = nil
|
|
109
111
|
|
|
110
112
|
if type_metadata.type == :datetime && /\ACURRENT_TIMESTAMP(?:\([0-6]?\))?\z/i.match?(default)
|
|
113
|
+
default = "#{default} ON UPDATE #{default}" if /on update CURRENT_TIMESTAMP/i.match?(field[:Extra])
|
|
111
114
|
default_function = default
|
|
112
115
|
default = nil
|
|
113
116
|
elsif type_metadata.extra == 'DEFAULT_GENERATED'
|
data/lib/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activerecord-tidb-adapter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 7.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hooopo Wang
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-03-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
19
|
+
version: 7.0.1
|
|
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: 7.0.1
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: mysql2
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -87,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
87
87
|
requirements:
|
|
88
88
|
- - ">="
|
|
89
89
|
- !ruby/object:Gem::Version
|
|
90
|
-
version: 2.
|
|
90
|
+
version: 2.7.0
|
|
91
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
requirements:
|
|
93
93
|
- - ">="
|