sequelizer 0.2.0 → 0.3.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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +43 -0
  3. data/LICENSE +21 -0
  4. data/README.md +28 -14
  5. data/lib/sequel/extensions/cold_col.rb +39 -15
  6. data/lib/sequel/extensions/funky.rb +1 -1
  7. data/lib/sequel/extensions/make_readyable.rb +18 -8
  8. data/lib/sequel/extensions/platform.rb +8 -9
  9. data/lib/sequel/extensions/smart_select_remove.rb +101 -0
  10. data/lib/sequelizer/options.rb +10 -5
  11. data/lib/sequelizer/version.rb +1 -1
  12. metadata +7 -52
  13. data/.beads/.gitignore +0 -54
  14. data/.beads/.jsonl.lock +0 -0
  15. data/.beads/.migration-hint-ts +0 -1
  16. data/.beads/README.md +0 -81
  17. data/.beads/config.yaml +0 -42
  18. data/.beads/issues.jsonl +0 -20
  19. data/.beads/metadata.json +0 -7
  20. data/.coderabbit.yaml +0 -94
  21. data/.devcontainer/.p10k.zsh +0 -1713
  22. data/.devcontainer/.zshrc +0 -29
  23. data/.devcontainer/Dockerfile +0 -137
  24. data/.devcontainer/copy-claude-credentials.sh +0 -32
  25. data/.devcontainer/devcontainer.json +0 -102
  26. data/.devcontainer/init-firewall.sh +0 -123
  27. data/.devcontainer/setup-credentials.sh +0 -95
  28. data/.github/dependabot.yml +0 -18
  29. data/.github/workflows/dependabot-auto-merge.yml +0 -36
  30. data/.github/workflows/test.yml +0 -49
  31. data/.gitignore +0 -40
  32. data/.overcommit.yml +0 -73
  33. data/.rubocop.yml +0 -167
  34. data/AGENTS.md +0 -126
  35. data/CLAUDE.md +0 -230
  36. data/Gemfile +0 -12
  37. data/Gemfile.lock +0 -189
  38. data/Guardfile +0 -28
  39. data/LICENSE.txt +0 -22
  40. data/Rakefile +0 -35
  41. data/examples/database.with_one_set_of_options.yml +0 -15
  42. data/examples/database.yml +0 -30
  43. data/examples/dot_env.txt +0 -10
  44. data/sequelizer.gemspec +0 -38
  45. data/test/lib/sequel/extensions/test_cold_col.rb +0 -251
  46. data/test/lib/sequel/extensions/test_db_opts.rb +0 -42
  47. data/test/lib/sequel/extensions/test_make_readyable.rb +0 -258
  48. data/test/lib/sequel/extensions/test_more_sql.rb +0 -132
  49. data/test/lib/sequel/extensions/test_platform.rb +0 -222
  50. data/test/lib/sequel/extensions/test_settable.rb +0 -109
  51. data/test/lib/sequel/extensions/test_sql_recorder.rb +0 -231
  52. data/test/lib/sequel/extensions/test_unionize.rb +0 -76
  53. data/test/lib/sequel/extensions/test_usable.rb +0 -15
  54. data/test/lib/sequelizer/test_connection_maker.rb +0 -123
  55. data/test/lib/sequelizer/test_env_config.rb +0 -37
  56. data/test/lib/sequelizer/test_gemfile_modifier.rb +0 -88
  57. data/test/lib/sequelizer/test_options.rb +0 -111
  58. data/test/lib/sequelizer/test_yaml_config.rb +0 -83
  59. data/test/test_helper.rb +0 -45
data/Gemfile.lock DELETED
@@ -1,189 +0,0 @@
1
- GIT
2
- remote: https://github.com/outcomesinsights/sequel-hexspace.git
3
- revision: 91ff040fac46380e2b35406ab4c8a7041beacd25
4
- branch: master
5
- specs:
6
- sequel-hexspace (1.0.0)
7
- hexspace (>= 0.2.1)
8
- sequel (~> 5.0)
9
-
10
- PATH
11
- remote: .
12
- specs:
13
- sequelizer (0.2.0)
14
- activesupport (>= 7, < 9)
15
- dotenv (>= 2.1, < 4.0)
16
- hashie (>= 3.2, < 6.0)
17
- kvcsv (~> 0.1)
18
- pp
19
- sequel (~> 5.93)
20
- thor (~> 1.0)
21
-
22
- GEM
23
- remote: https://rubygems.org/
24
- specs:
25
- activesupport (8.1.2)
26
- base64
27
- bigdecimal
28
- concurrent-ruby (~> 1.0, >= 1.3.1)
29
- connection_pool (>= 2.2.5)
30
- drb
31
- i18n (>= 1.6, < 2)
32
- json
33
- logger (>= 1.4.2)
34
- minitest (>= 5.1)
35
- securerandom (>= 0.3)
36
- tzinfo (~> 2.0, >= 2.0.5)
37
- uri (>= 0.13.1)
38
- addressable (2.8.8)
39
- public_suffix (>= 2.0.2, < 8.0)
40
- ast (2.4.3)
41
- base64 (0.3.0)
42
- bigdecimal (4.0.1)
43
- childprocess (5.1.0)
44
- logger (~> 1.5)
45
- coderay (1.1.3)
46
- concurrent-ruby (1.3.6)
47
- connection_pool (3.0.2)
48
- csv (3.3.5)
49
- docile (1.4.1)
50
- dotenv (3.2.0)
51
- drb (2.2.3)
52
- ffi (1.17.3-x86_64-linux-gnu)
53
- formatador (1.2.3)
54
- reline
55
- guard (2.20.1)
56
- formatador (>= 0.2.4)
57
- listen (>= 2.7, < 4.0)
58
- logger (~> 1.6)
59
- lumberjack (>= 1.0.12, < 2.0)
60
- nenv (~> 0.1)
61
- notiffany (~> 0.0)
62
- pry (>= 0.13.0)
63
- shellany (~> 0.0)
64
- thor (>= 0.18.1)
65
- guard-compat (1.2.1)
66
- guard-minitest (3.0.0)
67
- guard-compat (~> 1.2)
68
- minitest (>= 5.0.4, < 7.0)
69
- hashie (5.1.0)
70
- logger
71
- hexspace (0.3.0)
72
- bigdecimal
73
- thrift (>= 0.18)
74
- i18n (1.14.8)
75
- concurrent-ruby (~> 1.0)
76
- iniparse (1.5.0)
77
- io-console (0.8.2)
78
- json (2.18.1)
79
- json-schema (6.1.0)
80
- addressable (~> 2.8)
81
- bigdecimal (>= 3.1, < 5)
82
- kvcsv (0.1.0)
83
- csv (~> 3.0)
84
- language_server-protocol (3.17.0.5)
85
- lint_roller (1.1.0)
86
- listen (3.10.0)
87
- logger
88
- rb-fsevent (~> 0.10, >= 0.10.3)
89
- rb-inotify (~> 0.9, >= 0.9.10)
90
- logger (1.7.0)
91
- lumberjack (1.4.2)
92
- mcp (0.7.1)
93
- json-schema (>= 4.1)
94
- method_source (1.1.0)
95
- minitest (6.0.2)
96
- drb (~> 2.0)
97
- prism (~> 1.5)
98
- minitest-mock (5.27.0)
99
- nenv (0.3.0)
100
- notiffany (0.1.3)
101
- nenv (~> 0.1)
102
- shellany (~> 0.0)
103
- overcommit (0.68.0)
104
- childprocess (>= 0.6.3, < 6)
105
- iniparse (~> 1.4)
106
- rexml (>= 3.3.9)
107
- parallel (1.27.0)
108
- parser (3.3.10.2)
109
- ast (~> 2.4.1)
110
- racc
111
- pg (1.6.3-x86_64-linux)
112
- pp (0.6.3)
113
- prettyprint
114
- prettyprint (0.2.0)
115
- prism (1.9.0)
116
- pry (0.16.0)
117
- coderay (~> 1.1)
118
- method_source (~> 1.0)
119
- reline (>= 0.6.0)
120
- public_suffix (7.0.2)
121
- racc (1.8.1)
122
- rainbow (3.1.1)
123
- rake (13.3.1)
124
- rb-fsevent (0.11.2)
125
- rb-inotify (0.11.1)
126
- ffi (~> 1.0)
127
- regexp_parser (2.11.3)
128
- reline (0.6.3)
129
- io-console (~> 0.5)
130
- rexml (3.4.4)
131
- rubocop (1.85.0)
132
- json (~> 2.3)
133
- language_server-protocol (~> 3.17.0.2)
134
- lint_roller (~> 1.1.0)
135
- mcp (~> 0.6)
136
- parallel (~> 1.10)
137
- parser (>= 3.3.0.2)
138
- rainbow (>= 2.2.2, < 4.0)
139
- regexp_parser (>= 2.9.3, < 3.0)
140
- rubocop-ast (>= 1.49.0, < 2.0)
141
- ruby-progressbar (~> 1.7)
142
- unicode-display_width (>= 2.4.0, < 4.0)
143
- rubocop-ast (1.49.0)
144
- parser (>= 3.3.7.2)
145
- prism (~> 1.7)
146
- rubocop-minitest (0.39.1)
147
- lint_roller (~> 1.1)
148
- rubocop (>= 1.75.0, < 2.0)
149
- rubocop-ast (>= 1.38.0, < 2.0)
150
- ruby-progressbar (1.13.0)
151
- securerandom (0.4.1)
152
- sequel (5.101.0)
153
- bigdecimal
154
- shellany (0.0.1)
155
- simplecov (0.22.0)
156
- docile (~> 1.1)
157
- simplecov-html (~> 0.11)
158
- simplecov_json_formatter (~> 0.1)
159
- simplecov-html (0.13.2)
160
- simplecov_json_formatter (0.1.4)
161
- thor (1.5.0)
162
- thrift (0.22.0)
163
- tzinfo (2.0.6)
164
- concurrent-ruby (~> 1.0)
165
- unicode-display_width (3.2.0)
166
- unicode-emoji (~> 4.1)
167
- unicode-emoji (4.2.0)
168
- uri (1.1.1)
169
-
170
- PLATFORMS
171
- x86_64-linux
172
-
173
- DEPENDENCIES
174
- bundler (>= 2.0)
175
- guard (~> 2.0)
176
- guard-minitest (~> 3.0)
177
- minitest (~> 6.0)
178
- minitest-mock (~> 5.27)
179
- overcommit (~> 0.68)
180
- pg (~> 1.0)
181
- rake (~> 13.3)
182
- rubocop (~> 1.0)
183
- rubocop-minitest (~> 0.25)
184
- sequel-hexspace!
185
- sequelizer!
186
- simplecov (~> 0.22)
187
-
188
- BUNDLED WITH
189
- 2.6.9
data/Guardfile DELETED
@@ -1,28 +0,0 @@
1
- # A sample Guardfile
2
- # More info at https://github.com/guard/guard#readme
3
-
4
- guard :minitest do
5
- # with Minitest::Unit
6
- watch(%r{^test/(.*)/?test_(.*)\.rb$})
7
- watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
8
- watch(%r{^test/test_helper\.rb$}) { 'test' }
9
-
10
- # with Minitest::Spec
11
- # watch(%r{^spec/(.*)_spec\.rb$})
12
- # watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
13
- # watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
14
-
15
- # Rails 4
16
- # watch(%r{^app/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
17
- # watch(%r{^app/controllers/application_controller\.rb$}) { 'test/controllers' }
18
- # watch(%r{^app/controllers/(.+)_controller\.rb$}) { |m| "test/integration/#{m[1]}_test.rb" }
19
- # watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
20
- # watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" }
21
- # watch(%r{^test/.+_test\.rb$})
22
- # watch(%r{^test/test_helper\.rb$}) { 'test' }
23
-
24
- # Rails < 4
25
- # watch(%r{^app/controllers/(.*)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" }
26
- # watch(%r{^app/helpers/(.*)\.rb$}) { |m| "test/helpers/#{m[1]}_test.rb" }
27
- # watch(%r{^app/models/(.*)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" }
28
- end
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2014 Outcomes Insights, Inc.
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile DELETED
@@ -1,35 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rake/testtask'
3
-
4
- Rake::TestTask.new do |t|
5
- t.libs = %w[lib test]
6
- t.warning = true
7
- t.test_files = FileList['test/**/test_*.rb']
8
- end
9
-
10
- begin
11
- require 'rubocop/rake_task'
12
-
13
- RuboCop::RakeTask.new(:lint) do |task|
14
- task.options = ['--display-cop-names']
15
- end
16
-
17
- RuboCop::RakeTask.new(:format) do |task|
18
- task.options = ['--auto-correct-all']
19
- end
20
-
21
- desc 'Run RuboCop with safe autocorrect'
22
- task :lint_fix do
23
- system('bundle exec rubocop --autocorrect')
24
- end
25
- rescue LoadError
26
- # RuboCop not available
27
- end
28
-
29
- desc 'Run tests with coverage report'
30
- task :coverage do
31
- ENV['COVERAGE'] = 'true'
32
- Rake::Task[:test].invoke
33
- end
34
-
35
- task default: :test
@@ -1,15 +0,0 @@
1
- # A normal database.yml file contains a file with many different database
2
- # configurations specified, one for each "environment".
3
- #
4
- # This is a Rails convention, but frankly, most of the time I have a single
5
- # environment in my one-off scripts and don't want to bother with specifying
6
- # different environments.
7
- #
8
- # So I can just define my database options like so:
9
- ---
10
- adapter: postgres # Note: postgresql also works, but Sequel prefers postgres
11
- database: my_database
12
- host: localhost
13
- username: my_user
14
- password: my_great_password
15
-
@@ -1,30 +0,0 @@
1
- # An example of a database.yml file that is very much like the kind we'd
2
- # find in a Rails app.
3
- #
4
- # There are three environments defined.
5
- #
6
- # Sequelizer will look for which environment to use by reading the contents
7
- # of your environment variables in the following order:
8
- # SEQUELIZER_ENV
9
- # RAILS_ENV
10
- # RACK_ENV
11
- #
12
- # If all of those are nil, we'll default to development
13
- common: &common
14
- adapter: postgres
15
- host: localhost
16
- username: my_username
17
- password: my_password
18
- schema_search_path: list,of,schemas
19
-
20
- development:
21
- <<: *common
22
- database: dev_database
23
-
24
- test:
25
- adapter: sqlite
26
- database: test.sqlite
27
-
28
- production:
29
- <<: *common
30
- database: production_database
data/examples/dot_env.txt DELETED
@@ -1,10 +0,0 @@
1
- # Normally you'd name this file '.env' and place it in
2
- # the root of your project's directoryo
3
- #
4
- # Then you'd specify your database options like so:
5
- SEQUELIZER_ADAPTER=postgres
6
- SEQUELIZER_USERNAME=my_username
7
- SEQUELIZER_PASSWORD=super_secret_password
8
- SEQUELIZER_DATABASE=name_of_database
9
- SEQUELIZER_HOST=localhost
10
- SEQUELIZER_SEARCH_PATH=list,of,schemas
data/sequelizer.gemspec DELETED
@@ -1,38 +0,0 @@
1
- lib = File.expand_path('lib', __dir__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'sequelizer/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'sequelizer'
7
- spec.version = Sequelizer::VERSION
8
- spec.authors = ['Ryan Duryea']
9
- spec.email = ['aguynamedryan@gmail.com']
10
- spec.summary = 'Sequel database connections via config/database.yml or .env'
11
- spec.description = 'Easily establish a connection to a database via Sequel gem using options specified in config/database.yml or .env files'
12
- spec.homepage = 'https://github.com/outcomesinsights/sequelizer'
13
- spec.license = 'MIT'
14
-
15
- spec.files = `git ls-files -z`.split("\x0")
16
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
- spec.require_paths = ['lib']
18
- spec.required_ruby_version = '>= 3.2.0'
19
-
20
- spec.add_development_dependency 'bundler', '>= 2.0'
21
- spec.add_development_dependency 'guard', '~> 2.0'
22
- spec.add_development_dependency 'guard-minitest', '~> 3.0'
23
- spec.add_development_dependency 'minitest', '~> 6.0'
24
- spec.add_development_dependency 'minitest-mock', '~> 5.27'
25
- spec.add_development_dependency 'pg', '~> 1.0'
26
- spec.add_development_dependency 'rake', '~> 13.3'
27
- spec.add_development_dependency 'rubocop', '~> 1.0'
28
- spec.add_development_dependency 'rubocop-minitest', '~> 0.25'
29
- spec.add_development_dependency 'simplecov', '~> 0.22'
30
- spec.add_dependency 'activesupport', '>= 7', '< 9'
31
- spec.add_dependency 'dotenv', '>= 2.1', '< 4.0'
32
- spec.add_dependency 'hashie', '>= 3.2', '< 6.0'
33
- spec.add_dependency 'kvcsv', '~> 0.1'
34
- spec.add_dependency 'pp'
35
- spec.add_dependency 'sequel', '~> 5.93'
36
- spec.add_dependency 'thor', '~> 1.0'
37
- spec.metadata['rubygems_mfa_required'] = 'true'
38
- end
@@ -1,251 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../../test_helper'
4
- require_relative '../../../../lib/sequel/extensions/cold_col'
5
-
6
- describe Sequel::ColdColDatabase do
7
- let(:db) do
8
- @db = Sequel.mock.extension(:cold_col)
9
- @db.cold_col_registry.set_schemas({
10
- Sequel.lit('tab1') => [[:col1]],
11
- Sequel.lit('tab2') => [[:col2]],
12
- Sequel.lit('tab3') => [[:col3], [:col4]],
13
- Sequel.lit('q.tab4') => [[:col5]],
14
- })
15
- @db.extend_datasets do
16
- def supports_cte?
17
- true
18
- end
19
- end
20
-
21
- # Add with method to mock database to support CTEs
22
- def @db.with(*)
23
- dataset.with(*)
24
- end
25
-
26
- @db
27
- end
28
-
29
- def expect_columns(ds, *cols)
30
- _(ds.columns).must_equal(cols)
31
- end
32
-
33
- it 'should know columns from select * FROM tab' do
34
- expect_columns(db[:tab1], :col1)
35
- end
36
-
37
- it 'should know columns after append' do
38
- expect_columns(db[:tab1].select_append(Sequel.function(:min, :col1).as(:mini)), :col1, :mini)
39
- end
40
-
41
- it 'should know columns after select_all' do
42
- expect_columns(db[:tab1].select_all, :col1)
43
- end
44
-
45
- it 'should know columns after select_all(:tab1)' do
46
- expect_columns(db[:tab1].select_all(:tab1), :col1)
47
- end
48
-
49
- it 'should know columns after from_self' do
50
- expect_columns(db[:tab1].from_self, :col1)
51
- end
52
-
53
- it 'should know columns after a CTE' do
54
- ds = db[:cte1]
55
- .with(:cte1, db[:tab1])
56
- expect_columns(ds, :col1)
57
- end
58
-
59
- it 'should know columns after a JOIN' do
60
- ds = db[:tab1]
61
- .join(:tab2)
62
- expect_columns(ds, :col1, :col2)
63
- end
64
-
65
- it 'should know columns after a different kind of JOIN' do
66
- ds = db[:tab1]
67
- .join(db[:tab2])
68
- expect_columns(ds, :col1, :col2)
69
- end
70
-
71
- it 'should know columns from a JOIN and CTE' do
72
- ds = db[:tab1]
73
- .with(:cte1, db[:tab2])
74
- .join(db[:cte1])
75
- expect_columns(ds, :col1, :col2)
76
- end
77
-
78
- it 'should know columns from a select_all JOIN' do
79
- ds = db[:tab1]
80
- .join(db[:tab2], { Sequel[:tab1][:col1] => Sequel[:tab2][:col3] })
81
- .select_all(:tab1)
82
- expect_columns(ds, :col1)
83
- end
84
-
85
- it 'should know columns from an aliased select_all JOIN' do
86
- ds = db[:tab1].from_self(alias: :l)
87
- .join(db[:tab2], { col3: :col1 })
88
- .select_all(:l)
89
- expect_columns(ds, :col1)
90
- end
91
-
92
- it 'should know columns from an aliased select_all and added rhs column JOIN' do
93
- ds = db[:tab1].from_self(alias: :l)
94
- .join(db[:tab2], { col3: :col1 }, table_alias: :r)
95
- .select_all(:l)
96
- .select_append(Sequel[:r][:col4])
97
- expect_columns(ds, :col1, :col4)
98
- end
99
-
100
- it 'should know columns from an aliased select_all rhs JOIN' do
101
- ds = db[:tab1].from_self(alias: :l)
102
- .join(db[:tab2], { col3: :col1 }, table_alias: :r)
103
- .select_all(:r)
104
- expect_columns(ds, :col2)
105
- end
106
-
107
- it 'should know columns from a directly aliased select_all rhs JOIN' do
108
- ds = db[:tab1].from_self(alias: :l)
109
- .join(:tab2, { col3: :col1 }, table_alias: :r)
110
- .select_all(:r)
111
- expect_columns(ds, :col2)
112
- end
113
-
114
- it 'should know columns from a a qualified JOIN' do
115
- ds = db[:tab1].from_self(alias: :l)
116
- .join(Sequel[:q][:tab4], { col3: :col1 }, table_alias: :r)
117
- .select_all(:r)
118
- expect_columns(ds, :col5)
119
- end
120
- it 'should remember columns from ctas' do
121
- db.create_table(:ctas_table, as: db.select(Sequel[1].as(:a)))
122
- ds = db[:ctas_table]
123
- expect_columns(ds, :a)
124
- end
125
-
126
- it 'should remember columns from create table' do
127
- db.create_table(:ddl_table) do
128
- String :a
129
- end
130
- ds = db[:ddl_table]
131
- expect_columns(ds, :a)
132
- end
133
-
134
- it 'should remember columns from view' do
135
- db.create_view(:ctas_view, db.select(Sequel[1].as(:a)))
136
- ds = db[:ctas_view]
137
- expect_columns(ds, :a)
138
- end
139
-
140
- it 'should ignore columns when asked, thus avoiding an issue with string-only SQL' do
141
- assert_raises(NoMethodError) { db.create_view(:ctas_view, 'SELECT 1 AS A') }
142
- db.create_view(:ctas_view, 'SELECT 1 AS A', dont_record: true)
143
- end
144
-
145
- it 'should handle load_schema with empty file' do
146
- require 'tempfile'
147
- require 'yaml'
148
-
149
- Tempfile.create(['schema', '.yml']) do |f|
150
- f.write({}.to_yaml)
151
- f.flush
152
-
153
- db.load_schema(f.path)
154
- # Should not raise error and schemas should remain unchanged
155
- expect_columns(db[:tab1], :col1)
156
- end
157
- end
158
-
159
- it 'should handle add_table_schema with symbol and string table names' do
160
- db.add_table_schema(:new_table, [[:col_a, {}], [:col_b, {}]])
161
- db.add_table_schema('string_table', [[:col_c, {}]])
162
-
163
- expect_columns(db[:new_table], :col_a, :col_b)
164
- expect_columns(db[:string_table], :col_c)
165
- end
166
-
167
- it 'should handle complex nested CTEs' do
168
- ds = db.with(:cte1, db[:tab1])
169
- .with(:cte2, db[:cte1].select(:col1))
170
- .from(:cte2)
171
- expect_columns(ds, :col1)
172
- end
173
-
174
- it 'should handle qualified table names in schema' do
175
- expect_columns(db[Sequel[:q][:tab4]], :col5)
176
- end
177
-
178
- it 'should handle aliased expressions in select' do
179
- ds = db[:tab1].select(Sequel[:col1].as(:renamed_col))
180
- expect_columns(ds, :renamed_col)
181
- end
182
-
183
- it 'should handle function calls with aliases' do
184
- ds = db[:tab1].select(Sequel.function(:count, :col1).as(:count_col1))
185
- expect_columns(ds, :count_col1)
186
- end
187
-
188
- it 'should handle multiple table joins with mixed syntax' do
189
- ds = db[:tab1]
190
- .join(:tab2, { col2: :col1 })
191
- .join(db[:tab3].as(:t3), { col3: :col1 })
192
- expect_columns(ds, :col1, :col2, :col3, :col4)
193
- end
194
-
195
- it 'should handle recursive schema merging with load_schema' do
196
- require 'tempfile'
197
- require 'yaml'
198
-
199
- # First schema file
200
- Tempfile.create(['schema1', '.yml']) do |f1|
201
- f1.write({ 'initial_table' => { columns: { 'col_x' => {} } } }.to_yaml)
202
- f1.flush
203
- db.load_schema(f1.path)
204
-
205
- # Second schema file
206
- Tempfile.create(['schema2', '.yml']) do |f2|
207
- f2.write({ 'second_table' => { columns: { 'col_y' => {} } } }.to_yaml)
208
- f2.flush
209
- db.load_schema(f2.path)
210
-
211
- # Both schemas should be available
212
- expect_columns(db[:initial_table], :col_x)
213
- expect_columns(db[:second_table], :col_y)
214
- end
215
- end
216
- end
217
-
218
- # Additional tests to ensure refactoring preserves behavior
219
- describe 'Internal schema lookup behavior' do
220
- it 'should prioritize created tables over schemas' do
221
- db.add_table_schema(:priority_test, [[:schema_col, {}]])
222
- db.create_table(:priority_test) do
223
- String :created_col
224
- end
225
- expect_columns(db[:priority_test], :created_col)
226
- end
227
-
228
- it 'should handle deeply nested WITH clauses' do
229
- ds = db[:cte1]
230
- .with(:cte1, db[:tab1])
231
- .with(:cte2, db[:cte1])
232
- .with(:cte3, db[:cte2])
233
- .from(:cte3)
234
- expect_columns(ds, :col1)
235
- end
236
-
237
- it 'should handle mixed aliased and non-aliased sources' do
238
- ds = db[:tab1].from_self(alias: :t1)
239
- .join(:tab2, { col2: :col1 })
240
- .join(db[:tab3].as(:t3), { col3: :col1 })
241
- .select_all(:t1)
242
- .select_append(Sequel[:t3][:col4])
243
- expect_columns(ds, :col1, :col4)
244
- end
245
-
246
- it 'should handle column lookup with empty select lists' do
247
- ds = db.from(db[:tab1].where(id: 1))
248
- expect_columns(ds, :col1)
249
- end
250
- end
251
- end
@@ -1,42 +0,0 @@
1
- require_relative '../../../test_helper'
2
- require 'sequel'
3
- require 'sequel/extensions/db_opts'
4
-
5
- class TestDbOpts < Minitest::Test
6
-
7
- def with_fake_database_type_and_options(db_type, opts = {})
8
- db = Sequel.mock
9
- db.define_singleton_method(:database_type) { db_type }
10
- db.define_singleton_method(:opts) { opts }
11
- db.extension :db_opts
12
- yield db
13
- end
14
-
15
- def sql_for(db_type, options)
16
- with_fake_database_type_and_options(db_type, options) do |db|
17
- db.synchronize do |conn|
18
- db.db_opts.apply(conn)
19
- return db.sqls
20
- end
21
- end
22
- end
23
-
24
- def test_should_detect_options_for_appropriate_db
25
- assert_equal(['SET flim=flam'], sql_for(:postgres, postgres_db_opt_flim: :flam))
26
- end
27
-
28
- def test_should_ignore_options_for_inappropriate_db
29
- assert_equal(['SET flim=flam'], sql_for(:postgres, postgres_db_opt_flim: :flam, other_db_opt_foo: :bar))
30
- end
31
-
32
- def test_should_ignore_non_db_opts
33
- assert_empty(sql_for(:postgres, postgres_flim: :flam))
34
- end
35
-
36
- def test_should_properly_quote_awkward_values
37
- assert_equal(["SET str='hello there'", "SET hyphen='i-like-hyphens-though-they-are-dumb'"],
38
- sql_for(:postgres, postgres_db_opt_str: 'hello there',
39
- postgres_db_opt_hyphen: 'i-like-hyphens-though-they-are-dumb'))
40
- end
41
-
42
- end