sequelizer 0.1.6 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +60 -0
- data/LICENSE +21 -0
- data/README.md +28 -14
- data/config/platforms/base.csv +5 -0
- data/config/platforms/rdbms/athena.csv +4 -0
- data/config/platforms/rdbms/postgres.csv +3 -0
- data/config/platforms/rdbms/snowflake.csv +1 -0
- data/config/platforms/rdbms/spark.csv +3 -0
- data/lib/sequel/extensions/cold_col.rb +41 -17
- data/lib/sequel/extensions/funky.rb +136 -0
- data/lib/sequel/extensions/make_readyable.rb +18 -10
- data/lib/sequel/extensions/platform.rb +300 -0
- data/lib/sequel/extensions/smart_select_remove.rb +101 -0
- data/lib/sequelizer/options.rb +15 -6
- data/lib/sequelizer/version.rb +1 -1
- data/lib/sequelizer/yaml_config.rb +0 -1
- metadata +90 -57
- data/.claude/settings.local.json +0 -64
- data/.devcontainer/.p10k.zsh +0 -1713
- data/.devcontainer/.zshrc +0 -29
- data/.devcontainer/Dockerfile +0 -137
- data/.devcontainer/copy-claude-credentials.sh +0 -32
- data/.devcontainer/devcontainer.json +0 -102
- data/.devcontainer/init-firewall.sh +0 -123
- data/.devcontainer/setup-credentials.sh +0 -95
- data/.github/workflows/test.yml +0 -14
- data/.gitignore +0 -40
- data/.overcommit.yml +0 -73
- data/.rubocop.yml +0 -167
- data/CLAUDE.md +0 -219
- data/Gemfile +0 -12
- data/Gemfile.lock +0 -158
- data/Guardfile +0 -28
- data/LICENSE.txt +0 -22
- data/Rakefile +0 -35
- data/examples/database.with_one_set_of_options.yml +0 -15
- data/examples/database.yml +0 -30
- data/examples/dot_env.txt +0 -10
- data/sequelizer.gemspec +0 -35
- data/test/lib/sequel/extensions/test_cold_col.rb +0 -251
- data/test/lib/sequel/extensions/test_db_opts.rb +0 -42
- data/test/lib/sequel/extensions/test_make_readyable.rb +0 -259
- data/test/lib/sequel/extensions/test_more_sql.rb +0 -132
- data/test/lib/sequel/extensions/test_settable.rb +0 -109
- data/test/lib/sequel/extensions/test_sql_recorder.rb +0 -231
- data/test/lib/sequel/extensions/test_unionize.rb +0 -76
- data/test/lib/sequel/extensions/test_usable.rb +0 -15
- data/test/lib/sequelizer/test_connection_maker.rb +0 -123
- data/test/lib/sequelizer/test_env_config.rb +0 -37
- data/test/lib/sequelizer/test_gemfile_modifier.rb +0 -88
- data/test/lib/sequelizer/test_options.rb +0 -83
- data/test/lib/sequelizer/test_yaml_config.rb +0 -83
- data/test/test_helper.rb +0 -44
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
require_relative '../../test_helper'
|
|
2
|
-
require 'sequelizer'
|
|
3
|
-
|
|
4
|
-
class TestEnvConfig < Minitest::Test
|
|
5
|
-
|
|
6
|
-
def setup
|
|
7
|
-
@env_config = Sequelizer::EnvConfig.new
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def test_loads_dotenv
|
|
11
|
-
mock = Minitest::Mock.new
|
|
12
|
-
stub_const(Sequelizer::EnvConfig, :Dotenv, mock) do
|
|
13
|
-
mock.expect :load, nil
|
|
14
|
-
@env_config.options
|
|
15
|
-
mock.verify
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def test_options_default_to_empty_hash
|
|
20
|
-
assert_empty(@env_config.options)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def test_converts_sequelizer_vars_to_options
|
|
24
|
-
ENV['SEQUELIZER_ADAPTER'] = 'sqlite'
|
|
25
|
-
|
|
26
|
-
assert_equal({ 'adapter' => 'sqlite' }, @env_config.options)
|
|
27
|
-
ENV.delete('SEQUELIZER_ADAPTER')
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def test_converts_db_opts_to_options
|
|
31
|
-
ENV['POSTGRES_DB_OPT_HEY'] = 'there'
|
|
32
|
-
|
|
33
|
-
assert_equal({ 'postgres_db_opt_hey' => 'there' }, @env_config.options)
|
|
34
|
-
ENV.delete('POSTGRES_DB_OPT_HEY')
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
end
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
require_relative '../../test_helper'
|
|
2
|
-
require 'sequelizer/gemfile_modifier'
|
|
3
|
-
|
|
4
|
-
class TestGemfileModifier < Minitest::Test
|
|
5
|
-
|
|
6
|
-
def setup
|
|
7
|
-
@gm = Sequelizer::GemfileModifier.new
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def test_dies_if_gemfile_missing
|
|
11
|
-
pn_mock = Minitest::Mock.new
|
|
12
|
-
pn_mock.expect(:exist?, false)
|
|
13
|
-
|
|
14
|
-
Pathname.stub(:new, pn_mock) do
|
|
15
|
-
assert_raises(RuntimeError) { @gm.modify }
|
|
16
|
-
end
|
|
17
|
-
pn_mock.verify
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def test_quits_if_no_modification_needed
|
|
21
|
-
opts_mock = Minitest::Mock.new
|
|
22
|
-
pn_mock = standard_pn_mock
|
|
23
|
-
opts_mock.expect(:adapter, 'postgres')
|
|
24
|
-
file_mock = Minitest::Mock.new
|
|
25
|
-
file_mock.expect(:readlines, ["gem 'pg'"], [pn_mock])
|
|
26
|
-
|
|
27
|
-
Pathname.stub(:new, pn_mock) do
|
|
28
|
-
Sequelizer::Options.stub(:new, opts_mock) do
|
|
29
|
-
stub_const(Sequelizer::GemfileModifier, :File, file_mock) do
|
|
30
|
-
stub_modifying_methods(@gm) do
|
|
31
|
-
@gm.modify
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def test_quits_if_no_modification_needed2
|
|
39
|
-
opts_mock = Minitest::Mock.new
|
|
40
|
-
pn_mock = standard_pn_mock
|
|
41
|
-
opts_mock.expect(:adapter, 'postgres')
|
|
42
|
-
file_mock = Minitest::Mock.new
|
|
43
|
-
file_mock.expect(:readlines, ["gem 'pg' # ADDED BY SEQUELIZER"], [pn_mock])
|
|
44
|
-
|
|
45
|
-
Pathname.stub(:new, pn_mock) do
|
|
46
|
-
Sequelizer::Options.stub(:new, opts_mock) do
|
|
47
|
-
stub_const(Sequelizer::GemfileModifier, :File, file_mock) do
|
|
48
|
-
stub_modifying_methods(@gm) do
|
|
49
|
-
@gm.modify
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def test_writes_if_modification_needed
|
|
57
|
-
opts_mock = Minitest::Mock.new
|
|
58
|
-
pn_mock = standard_pn_mock
|
|
59
|
-
opts_mock.expect(:adapter, 'postgres')
|
|
60
|
-
file_mock = Minitest::Mock.new
|
|
61
|
-
file_mock.expect(:readlines, ['#comment line', "gem 'sqlite3' # ADDED BY SEQUELIZER"], [pn_mock])
|
|
62
|
-
file_mock.expect(:write, nil, [pn_mock, ['#comment line', "gem 'pg' # ADDED BY SEQUELIZER"].join("\n")])
|
|
63
|
-
|
|
64
|
-
Pathname.stub(:new, pn_mock) do
|
|
65
|
-
Sequelizer::Options.stub(:new, opts_mock) do
|
|
66
|
-
stub_const(Sequelizer::GemfileModifier, :File, file_mock) do
|
|
67
|
-
stub_modifying_methods(@gm) do
|
|
68
|
-
@gm.modify
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
private
|
|
76
|
-
|
|
77
|
-
def standard_pn_mock
|
|
78
|
-
pn_mock = Minitest::Mock.new
|
|
79
|
-
pn_mock.expect(:exist?, true)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def stub_modifying_methods(obj, &block)
|
|
83
|
-
obj.stub(:system, nil) do
|
|
84
|
-
obj.stub(:puts, nil, &block)
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
end
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
require_relative '../../test_helper'
|
|
2
|
-
require 'sequelizer/options'
|
|
3
|
-
|
|
4
|
-
class TestOptions < Minitest::Test
|
|
5
|
-
|
|
6
|
-
def test_changes_postgresql_adapter_to_postgres
|
|
7
|
-
options = Sequelizer::Options.new(Sequelizer::OptionsHash.new(adapter: 'postgresql'))
|
|
8
|
-
|
|
9
|
-
assert_equal('postgres', options.adapter)
|
|
10
|
-
assert_equal('postgres', options.to_hash[:adapter])
|
|
11
|
-
assert_equal('postgres', options.to_hash['adapter'])
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def test_finds_search_path_as_search_path
|
|
15
|
-
options = Sequelizer::Options.new(Sequelizer::OptionsHash.new(adapter: 'postgres', search_path: 'path'))
|
|
16
|
-
|
|
17
|
-
assert_equal('path', options.search_path)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def test_finds_schema_as_search_path
|
|
21
|
-
options = Sequelizer::Options.new(Sequelizer::OptionsHash.new(adapter: 'postgres', schema: 'path'))
|
|
22
|
-
|
|
23
|
-
assert_equal('path', options.search_path)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def test_finds_schema_search_path_as_search_path
|
|
27
|
-
options = Sequelizer::Options.new(Sequelizer::OptionsHash.new(adapter: 'postgres', schema_search_path: 'path'))
|
|
28
|
-
|
|
29
|
-
assert_equal('path', options.search_path)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def test_prefers_search_path_over_schema_search_path
|
|
33
|
-
options = Sequelizer::Options.new(Sequelizer::OptionsHash.new(adapter: 'postgres', search_path: 'path',
|
|
34
|
-
schema_search_path: 'path2'))
|
|
35
|
-
|
|
36
|
-
assert_equal('path', options.search_path)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def test_returns_timeout_as_an_integer_even_if_given_string
|
|
40
|
-
options = Sequelizer::Options.new({ timeout: '30' })
|
|
41
|
-
|
|
42
|
-
assert_equal(30, options.to_hash[:timeout])
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def test_returns_a_hash_even_if_given_nil
|
|
46
|
-
Sequelizer::YamlConfig.stub :user_config_path, Pathname.new('/completely/made/up/path/that/does/not/exist') do
|
|
47
|
-
options = Sequelizer::Options.new
|
|
48
|
-
|
|
49
|
-
assert_equal(1, options.to_hash.length)
|
|
50
|
-
assert_instance_of(Proc, options.to_hash[:after_connect])
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def test_handles_symbolized_search_path
|
|
55
|
-
options = Sequelizer::Options.new(search_path: 'passed', adapter: 'postgres')
|
|
56
|
-
|
|
57
|
-
assert_equal 'passed', options.search_path
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def test_handles_existing_after_connect
|
|
61
|
-
db = Sequel.mock(host: :postgres)
|
|
62
|
-
conny = Minitest::Mock.new
|
|
63
|
-
conny.expect :db, db
|
|
64
|
-
conny.expect :db, db
|
|
65
|
-
conny.expect :db, db
|
|
66
|
-
|
|
67
|
-
procky = proc { |conn| conn.db[:table].to_a }
|
|
68
|
-
|
|
69
|
-
options = Sequelizer::Options.new(after_connect: procky)
|
|
70
|
-
options.to_hash[:after_connect].call(conny, :default, db)
|
|
71
|
-
|
|
72
|
-
assert_equal(['SELECT * FROM "table"'], db.sqls)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def test_handles_extensions_passed_in
|
|
76
|
-
options = Sequelizer::Options.new(extension_example_one: 1, extension_example_two: 1, not_an_extension_example: 1)
|
|
77
|
-
|
|
78
|
-
assert_equal 1, options.to_hash[:not_an_extension_example]
|
|
79
|
-
assert_includes options.extensions, :example_one, 'Failed to find example_one in extensions'
|
|
80
|
-
assert_includes options.extensions, :example_two, 'Failed to find example_two in extensions'
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
end
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
require_relative '../../test_helper'
|
|
2
|
-
require 'sequelizer/yaml_config'
|
|
3
|
-
|
|
4
|
-
class TestYamlConfig < Minitest::Test
|
|
5
|
-
|
|
6
|
-
def setup
|
|
7
|
-
@yaml_config = Sequelizer::YamlConfig.new
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def with_empty_env(&)
|
|
11
|
-
env_mock = Minitest::Mock.new
|
|
12
|
-
env_mock.expect :[], nil, ['SEQUELIZER_ENV']
|
|
13
|
-
env_mock.expect :[], nil, ['RAILS_ENV']
|
|
14
|
-
env_mock.expect :[], nil, ['RACK_ENV']
|
|
15
|
-
|
|
16
|
-
stub_const(Sequelizer::YamlConfig, :ENV, env_mock, &)
|
|
17
|
-
|
|
18
|
-
env_mock.verify
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def test_loads_from_yaml_file_if_present
|
|
22
|
-
mock = Minitest::Mock.new
|
|
23
|
-
file_mock = Minitest::Mock.new
|
|
24
|
-
|
|
25
|
-
stub_const(Sequelizer::YamlConfig, :File, mock) do
|
|
26
|
-
mock.expect :read, 'adapter: <%= "sqlite" %>', [file_mock]
|
|
27
|
-
file_mock.expect :exist?, true
|
|
28
|
-
|
|
29
|
-
@yaml_config.stub :config_file_path, file_mock do
|
|
30
|
-
assert_equal({ 'adapter' => 'sqlite' }, @yaml_config.options)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
file_mock.verify
|
|
34
|
-
mock.verify
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def test_loads_by_environment_if_present
|
|
39
|
-
file_mock = Minitest::Mock.new
|
|
40
|
-
file_mock.expect :exist?, true
|
|
41
|
-
@yaml_config.stub :config_file_path, file_mock do
|
|
42
|
-
@yaml_config.stub :config, { 'development' => { 'adapter' => 'sqlite' } } do
|
|
43
|
-
with_empty_env do
|
|
44
|
-
assert_equal({ 'adapter' => 'sqlite' }, @yaml_config.options)
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
file_mock.verify
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def test_options_default_to_empty_hash
|
|
52
|
-
assert_empty(@yaml_config.options)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def test_path_defaults_to_local_config
|
|
56
|
-
assert_equal(@yaml_config.config_file_path, Pathname.pwd.join('config', 'sequelizer.yml'))
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def test_path_can_be_fed_pathanem_from_initialize
|
|
60
|
-
assert_equal(Sequelizer::YamlConfig.new(Pathname.new('~').join('.config')).config_file_path,
|
|
61
|
-
Pathname.new('~').expand_path.join('.config'))
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def test_path_can_be_fed_string_from_initialize
|
|
65
|
-
assert_equal(Sequelizer::YamlConfig.new('~/.config').config_file_path, Pathname.new('~/.config').expand_path)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def test_local_is_current_directory
|
|
69
|
-
assert_equal(Sequelizer::YamlConfig.local_config.config_file_path, Pathname.pwd.join('config', 'sequelizer.yml'))
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def test_home_uses_home_directory
|
|
73
|
-
assert_equal(Sequelizer::YamlConfig.user_config.config_file_path,
|
|
74
|
-
Pathname.new(Dir.home).join('.config', 'sequelizer', 'database.yml'))
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def test_environment_checks_environment_variables
|
|
78
|
-
with_empty_env do
|
|
79
|
-
assert_equal 'development', @yaml_config.environment
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
end
|
data/test/test_helper.rb
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# Disable Rails plugins for Minitest to avoid version conflicts
|
|
2
|
-
ENV['MT_NO_PLUGINS'] = '1'
|
|
3
|
-
|
|
4
|
-
# SimpleCov must be loaded before application code
|
|
5
|
-
require 'simplecov'
|
|
6
|
-
|
|
7
|
-
SimpleCov.start do
|
|
8
|
-
add_filter '/test/'
|
|
9
|
-
add_filter '/vendor/'
|
|
10
|
-
|
|
11
|
-
add_group 'Core', 'lib/sequelizer'
|
|
12
|
-
add_group 'Sequel Extensions', 'lib/sequel'
|
|
13
|
-
|
|
14
|
-
# Temporarily lower minimum coverage to see what we're working with
|
|
15
|
-
minimum_coverage 70
|
|
16
|
-
minimum_coverage_by_file 40
|
|
17
|
-
|
|
18
|
-
# Generate both HTML and JSON for easier analysis
|
|
19
|
-
formatter SimpleCov::Formatter::MultiFormatter.new([
|
|
20
|
-
SimpleCov::Formatter::HTMLFormatter,
|
|
21
|
-
SimpleCov::Formatter::SimpleFormatter,
|
|
22
|
-
])
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
require 'minitest/autorun'
|
|
26
|
-
require 'sequel'
|
|
27
|
-
|
|
28
|
-
module Minitest
|
|
29
|
-
class Test
|
|
30
|
-
|
|
31
|
-
def stub_const(klass, const, replace)
|
|
32
|
-
klass.send(:const_set, const, replace)
|
|
33
|
-
return unless block_given?
|
|
34
|
-
|
|
35
|
-
yield
|
|
36
|
-
remove_stubbed_const(klass, const)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def remove_stubbed_const(klass, const)
|
|
40
|
-
klass.send(:remove_const, const)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
end
|
|
44
|
-
end
|