activerecord-duckdb 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 97d9df88d9ae4959d62c3013357973776dc52924ef38a0fadfd40fc402adb24f
4
+ data.tar.gz: c4606b422388e260c70522896dc14773d01c963e3cbdb77dc1fbb03e3676904a
5
+ SHA512:
6
+ metadata.gz: 0ec798db2626955dc20f0f5b531d669bb9352669f8fc3f25975da97f3ec8a083fd110c266dcd58e3167a4e0a4a6b516ee7ad128b17537a530508ffba25fd1bd9
7
+ data.tar.gz: 48674bbaaf8518907bfaec87833c0547706d2c5d05d117972f045496977a4edf32a8ee2c0d9c4ffa96c3eee11c2e8236eb374728e7fbb3656afdd4081d71f8e5
data/.fasterer.yml ADDED
@@ -0,0 +1,31 @@
1
+ speedups:
2
+ rescue_vs_respond_to: true
3
+ module_eval: true
4
+ shuffle_first_vs_sample: true
5
+ for_loop_vs_each: true
6
+ each_with_index_vs_while: false
7
+ map_flatten_vs_flat_map: true
8
+ reverse_each_vs_reverse_each: true
9
+ select_first_vs_detect: true
10
+ sort_vs_sort_by: true
11
+ fetch_with_argument_vs_block: false
12
+ keys_each_vs_each_key: true
13
+ hash_merge_bang_vs_hash_brackets: true
14
+ block_vs_symbol_to_proc: true
15
+ proc_call_vs_yield: true
16
+ gsub_vs_tr: true
17
+ select_last_vs_reverse_detect: true
18
+ getter_vs_attr_reader: true
19
+ setter_vs_attr_writer: true
20
+
21
+ exclude_paths:
22
+ - ".yardoc/"
23
+ - "bin/"
24
+ - "coverage/"
25
+ - "docs/"
26
+ - "log/"
27
+ - "sorbet/"
28
+ - "tmp/**/**"
29
+ - "vendor/**/**"
30
+ - "**.yml"
31
+ - "**.md"
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format Fuubar
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,105 @@
1
+ plugins:
2
+ - rubocop-performance
3
+ - rubocop-rake
4
+ - rubocop-rspec
5
+ - rubocop-thread_safety
6
+
7
+ AllCops:
8
+ TargetRubyVersion: 3.4
9
+ NewCops: enable
10
+ UseCache: true
11
+
12
+ Gemspec/RequiredRubyVersion:
13
+ Enabled: false
14
+
15
+ Layout/LineLength:
16
+ Enabled: false
17
+
18
+ Lint/DuplicateBranch:
19
+ Exclude:
20
+ - lib/active_record/connection_adapters/duckdb_adapter.rb
21
+
22
+ Lint/UnusedMethodArgument:
23
+ Enabled: false
24
+
25
+ Metrics/AbcSize:
26
+ Enabled: false
27
+
28
+ Metrics/BlockLength:
29
+ Enabled: false
30
+
31
+ Metrics/ClassLength:
32
+ Enabled: false
33
+
34
+ Metrics/CyclomaticComplexity:
35
+ Enabled: false
36
+
37
+ Metrics/MethodLength:
38
+ Enabled: false
39
+
40
+ Metrics/ModuleLength:
41
+ Enabled: false
42
+
43
+ Metrics/ParameterLists:
44
+ Enabled: false
45
+
46
+ Naming/FileName:
47
+ Exclude:
48
+ - lib/activerecord-duckdb.rb
49
+ - spec/activerecord-duckdb_spec.rb
50
+
51
+ Metrics/PerceivedComplexity:
52
+ Enabled: false
53
+
54
+ Naming/MethodParameterName:
55
+ Enabled: false
56
+
57
+ Naming/PredicatePrefix:
58
+ Enabled: false
59
+
60
+ Style/Documentation:
61
+ Enabled: false
62
+
63
+ Style/ParallelAssignment:
64
+ Enabled: false
65
+
66
+ Style/RedundantAssignment:
67
+ Enabled: false
68
+
69
+ Style/StringLiterals:
70
+ EnforcedStyle: single_quotes
71
+
72
+ Style/StringLiteralsInInterpolation:
73
+ EnforcedStyle: double_quotes
74
+
75
+ ##### RSpec specific
76
+ RSpec/DescribeClass:
77
+ Exclude:
78
+ - spec/activerecord-duckdb_spec.rb
79
+
80
+ RSpec/ExampleLength:
81
+ Enabled: false
82
+
83
+ RSpec/IndexedLet:
84
+ Enabled: false
85
+
86
+ RSpec/MultipleExpectations:
87
+ Enabled: false
88
+
89
+ RSpec/MultipleMemoizedHelpers:
90
+ Enabled: false
91
+
92
+ RSpec/VerifiedDoubles:
93
+ Exclude:
94
+ - spec/activerecord-duckdb_spec.rb
95
+
96
+ RSpec/UnspecifiedException:
97
+ Exclude:
98
+ - spec/support/shared_examples.rb
99
+
100
+ ThreadSafety/NewThread:
101
+ Exclude:
102
+ - spec/**/*
103
+
104
+ ThreadSafety/ClassAndModuleAttributes:
105
+ Enabled: false
data/.simplecov ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'simplecov' unless defined?(SimpleCov)
4
+ require 'simplecov-tailwindcss' unless defined?(SimpleCov::Formatter::TailwindFormatter)
5
+
6
+ SimpleCov.start do
7
+ add_filter('/bin/')
8
+ add_filter('/docs/')
9
+ add_filter('/lib/activerecord/duckdb/version.rb')
10
+ add_filter('/spec')
11
+ add_filter('/spec/support/')
12
+ end
13
+ SimpleCov.minimum_coverage(70)
14
+ SimpleCov.use_merging(false)
15
+ SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([
16
+ SimpleCov::Formatter::HTMLFormatter,
17
+ SimpleCov::Formatter::TailwindFormatter
18
+ ])
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.4.2
data/.yardopts ADDED
@@ -0,0 +1,2 @@
1
+ --title 'ActiveRecord-DuckDB'
2
+ --exclude /lib/activerecord/duckdb/version.rb
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-06-18
4
+
5
+ - Initial release
@@ -0,0 +1,131 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ - Demonstrating empathy and kindness toward other people
21
+ - Being respectful of differing opinions, viewpoints, and experiences
22
+ - Giving and gracefully accepting constructive feedback
23
+ - Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ - Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ - The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ - Trolling, insulting or derogatory comments, and personal or political attacks
33
+ - Public or private harassment
34
+ - Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ - Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement by the project maintainers.
63
+ All complaints will be reviewed and investigated promptly and fairly.
64
+
65
+ All community leaders are obligated to respect the privacy and security of the
66
+ reporter of any incident.
67
+
68
+ ## Enforcement Guidelines
69
+
70
+ Community leaders will follow these Community Impact Guidelines in determining
71
+ the consequences for any action they deem in violation of this Code of Conduct:
72
+
73
+ ### 1. Correction
74
+
75
+ **Community Impact**: Use of inappropriate language or other behavior deemed
76
+ unprofessional or unwelcome in the community.
77
+
78
+ **Consequence**: A private, written warning from community leaders, providing
79
+ clarity around the nature of the violation and an explanation of why the
80
+ behavior was inappropriate. A public apology may be requested.
81
+
82
+ ### 2. Warning
83
+
84
+ **Community Impact**: A violation through a single incident or series of
85
+ actions.
86
+
87
+ **Consequence**: A warning with consequences for continued behavior. No
88
+ interaction with the people involved, including unsolicited interaction with
89
+ those enforcing the Code of Conduct, for a specified period of time. This
90
+ includes avoiding interactions in community spaces as well as external channels
91
+ like social media. Violating these terms may lead to a temporary or permanent
92
+ ban.
93
+
94
+ ### 3. Temporary Ban
95
+
96
+ **Community Impact**: A serious violation of community standards, including
97
+ sustained inappropriate behavior.
98
+
99
+ **Consequence**: A temporary ban from any sort of interaction or public
100
+ communication with the community for a specified period of time. No public or
101
+ private interaction with the people involved, including unsolicited interaction
102
+ with those enforcing the Code of Conduct, is allowed during this period.
103
+ Violating these terms may lead to a permanent ban.
104
+
105
+ ### 4. Permanent Ban
106
+
107
+ **Community Impact**: Demonstrating a pattern of violation of community
108
+ standards, including sustained inappropriate behavior, harassment of an
109
+ individual, or aggression toward or disparagement of classes of individuals.
110
+
111
+ **Consequence**: A permanent ban from any sort of public interaction within the
112
+ community.
113
+
114
+ ## Attribution
115
+
116
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
117
+ version 2.1, available at
118
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
119
+
120
+ Community Impact Guidelines were inspired by
121
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
122
+
123
+ For answers to common questions about this code of conduct, see the FAQ at
124
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
125
+ [https://www.contributor-covenant.org/translations][translations].
126
+
127
+ [homepage]: https://www.contributor-covenant.org
128
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
129
+ [Mozilla CoC]: https://github.com/mozilla/diversity
130
+ [FAQ]: https://www.contributor-covenant.org/faq
131
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Brandon Hicks
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,168 @@
1
+ # Activerecord::Duckdb
2
+
3
+ This gem is a DuckDB database adapter for ActiveRecord.
4
+
5
+ ## Description
6
+
7
+ Activerecord::Duckdb providers DuckDB database access for Ruby on Rails applications.
8
+
9
+ ~ **NOTE:** This gem is still a work in progress, so it might not work exactly as expected just yet. Some ActiveRecord features haven’t been added and/or fully tested.
10
+
11
+ ## Requirements
12
+
13
+ This gem relies on the [ruby-duckdb](https://github.com/suketa/ruby-duckdb) ruby gem as its database adapter. Thus it provides a seamless integration with the DuckDB database.
14
+
15
+ Both gems requires that you have [duckdb](https://duckdb.org). DuckDB has many installation options available that can be found on their [installation page](https://duckdb.org/docs/installation/).
16
+
17
+ ```ruby
18
+ # OSx
19
+ brew install duckdb
20
+
21
+ # Most Linux distributions
22
+ curl https://install.duckdb.org | sh
23
+ ```
24
+
25
+ ## Installation
26
+
27
+ Install the gem and add to the application's Gemfile by executing:
28
+
29
+ ```bash
30
+ bundle add "activerecord-duckdb"
31
+ ```
32
+
33
+ If bundler is not being used to manage dependencies, install the gem by executing:
34
+
35
+ ```bash
36
+ gem install activerecord-duckdb
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ ### Configuration
42
+
43
+ Adjust your `database.yml` file to use the duckdb adapter.
44
+
45
+ ```yaml
46
+ development:
47
+ adapter: duckdb
48
+ database: db/development.duckdb
49
+
50
+ test:
51
+ adapter: duckdb
52
+ database: db/test.duckdb
53
+
54
+ production:
55
+ adapter: duckdb
56
+ database: db/production.duckdb
57
+ ```
58
+
59
+ Run some migrations to ensure the database is ready.
60
+
61
+ ```bash
62
+ rails g model Notice name:string email:string content:string
63
+ ```
64
+
65
+ ```ruby
66
+ Notice.create(name: 'John Doe', email: 'john@example.com', content: 'Something happened at work today!')
67
+ Notice.find_by(email: 'john@example.com')
68
+ Notice.all
69
+ Notice.last.delete
70
+ ```
71
+
72
+ ~ At the moment using an in-memory database is very limited and still in development.
73
+ **NOTE:** When using a memory database, any transactional operations will be lost when the process exits.
74
+ The only reason I can think of is that you might want to use an in-memory database for testing purposes, data analysis, or some sort of quick calculations where the data is not critical.
75
+
76
+ ```yaml
77
+ temporary_database:
78
+ adapter: duckdb
79
+ database: :memory
80
+ ```
81
+
82
+ ```ruby
83
+ class User < ApplicationRecord
84
+ establish_connection(:temporary_database)
85
+ end
86
+ ```
87
+
88
+ Of you can set your own database configuration in the `config/database.yml` file.
89
+ When using temporary databases you'll also have to generate your own schema on the fly rather than migrations creating them automatically.
90
+
91
+ ```yml
92
+ test:
93
+ adapter: duckdb
94
+ database: :memory
95
+
96
+ production:
97
+ adapter: duckdb
98
+ database: :memory
99
+ ```
100
+
101
+ ### Sample App setup
102
+
103
+ The following steps are required to setup a sample application using the `activerecord-duckdb` gem:
104
+
105
+ 1. Create a new Rails application:
106
+
107
+ ```bash
108
+ rails new sample_app --database=sqlite3
109
+ ```
110
+
111
+ 2. Add the `activerecord-duckdb` gem to your Gemfile:
112
+
113
+ ```ruby
114
+ gem 'activerecord-duckdb'
115
+ ```
116
+
117
+ 3. Run `bundle install` to install the gem.
118
+
119
+ 4. Update the `config/database.yml` file to use the `duckdb` adapter:
120
+
121
+ ```yaml
122
+ development:
123
+ adapter: duckdb
124
+ database: db/development.db
125
+
126
+ test:
127
+ adapter: duckdb
128
+ database: :memory
129
+
130
+ production:
131
+ adapter: duckdb
132
+ database: :memory
133
+ ```
134
+
135
+ 5. Generate a model for the sample application:
136
+
137
+ ```bash
138
+ rails g model User name:string email:string
139
+ ```
140
+
141
+ 5. Run some migrations to ensure the database is ready:
142
+
143
+ ```bash
144
+ rails db:create; rails db:migrate
145
+ ```
146
+
147
+ 6. Create some sample data:
148
+
149
+ ```ruby
150
+ User.create(name: 'John Doe', email: 'john@example.com')
151
+ User.create(name: 'Jane Doe', email: 'jane@example.com')
152
+ ```
153
+
154
+ 7. Run some queries:
155
+
156
+ ```ruby
157
+ User.all
158
+ User.find_by(email: 'john@example.com')
159
+ User.last.delete
160
+ ```
161
+
162
+ ## Contributing
163
+
164
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tarellel/activerecord-duckdb.
165
+
166
+ ## License
167
+
168
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rubocop/rake_task'
5
+ begin
6
+ require 'rspec/core/rake_task'
7
+
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.pattern = Dir.glob('spec/**/*_spec.rb')
10
+ t.rspec_opts = '--format documentation'
11
+ end
12
+ rescue LoadError
13
+ # If RSpec is not available, handle appropriately
14
+ puts 'RSpec gem not found. Please add it to your Gemfile.'
15
+ end
16
+
17
+ RuboCop::RakeTask.new
18
+
19
+ task default: %i[rubocop spec]
data/TODO.md ADDED
@@ -0,0 +1,16 @@
1
+ # TODO:
2
+
3
+ - Implement support DuckDB's UUID type for primary keys
4
+ - At the moment we use nextval because we always assume it will be a sequence Integer ID
5
+ - https://duckdb.org/docs/stable/sql/functions/utility#gen_random_uuid
6
+ - Add support for additional Data Types
7
+ - Blob
8
+ - https://duckdb.org/docs/stable/sql/data_types/blob
9
+ - Enum
10
+ - https://duckdb.org/docs/stable/sql/data_types/enum
11
+ - List
12
+ - https://duckdb.org/docs/stable/sql/data_types/list
13
+ - Map
14
+ - https://duckdb.org/docs/stable/sql/data_types/map
15
+ - Struct
16
+ - https://duckdb.org/docs/stable/sql/data_types/struct