Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
## [Unreleased]
# Changelog

## [0.1.0] - 2022-02-21
## [0.2.0]

- Initial release
### Added

- Complete basic ActiveRecord adapter functionality
- Test structure with unit, integration, and functional tests
- Modernize parameter binding using DuckDB's native parameter binding
- Support for migrations, associations, and validations

## [0.1.0]

### Added
- Initial project structure
- Basic gem setup
11 changes: 8 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ Rake::TestTask.new(:test) do |t|
t.verbose = true
end

require "rubocop/rake_task"

task default: %i[test rubocop]
begin
require "rubocop/rake_task"
RuboCop::RakeTask.new
task default: %i[test rubocop]
rescue LoadError
# RuboCop not available, skip it
task default: %i[test]
end

49 changes: 28 additions & 21 deletions activerecord-duckdb-adapter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,38 @@ require_relative "lib/activerecord_duckdb_adapter/version"
Gem::Specification.new do |spec|
spec.name = "activerecord-duckdb-adapter"
spec.version = ActiveRecordDuckdbAdapter::VERSION
spec.authors = ["okadakk"]
spec.email = ["[email protected]"]
spec.authors = ["okadakk", "Eddie A Tejeda"]
spec.email = ["[email protected]", "[email protected]"]

spec.summary = "https://github.com"
spec.description = "https://github.com"
spec.homepage = "https://github.com"
spec.summary = "ActiveRecord adapter for DuckDB database"
spec.description = "A Ruby gem that provides an ActiveRecord adapter for DuckDB, enabling Ruby and Rails applications to use DuckDB as their database backend."
spec.homepage = "https://github.com/red-data-tools/activerecord-duckdb-adapter"
spec.license = "MIT"
spec.required_ruby_version = ">= 2.4.0"
spec.required_ruby_version = ">= 3.1.0"

spec.metadata["allowed_push_host"] = "'https://mygemserver.com'"
spec.metadata = {
"bug_tracker_uri" => "https://github.com/red-data-tools/activerecord-duckdb-adapter/issues",
"changelog_uri" => "https://github.com/red-data-tools/activerecord-duckdb-adapter/blob/main/CHANGELOG.md",
"source_code_uri" => "https://github.com/red-data-tools/activerecord-duckdb-adapter",
"rubygems_mfa_required" => "true"
}

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "https://github.com"
spec.metadata["changelog_uri"] = "https://github.com"

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
# Specify files to include in the gem
spec.files = Dir[
"lib/**/*",
"README.md",
"LICENSE.txt",
"CHANGELOG.md"
].select { |f| File.file?(f) }

spec.require_paths = ["lib"]

# Uncomment to register a new dependency of your gem
spec.add_dependency('activerecord')
spec.add_dependency('duckdb')
# Development dependencies with bounded versions
spec.add_development_dependency "bundler", "~> 2.0"
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rspec", "~> 3.13"

# Runtime dependencies with bounded versions
spec.add_dependency "activerecord", "~> 7.1"
spec.add_dependency "duckdb", "~> 1.1"
end
68 changes: 67 additions & 1 deletion bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,77 @@
# frozen_string_literal: true

require "bundler/setup"
require "activerecord/duckdb/adapter"
require "activerecord-duckdb-adapter"
require "active_support/logger"
require "yaml"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

puts "Setting up ActiveRecord DuckDB Adapter console..."

# Setup database connection
ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT, level: Logger::INFO)
ActiveRecord::Base.configurations = {
'duckdb' => { adapter: 'duckdb' }
}
ActiveRecord::Base.establish_connection :duckdb

puts "✓ Database connection established"

# Load the schema
load File.expand_path("../../test/schema/schema.rb", __FILE__)
puts "✓ Database schema loaded"

# Load the models
require File.expand_path("../../test/models/author.rb", __FILE__)
require File.expand_path("../../test/models/post.rb", __FILE__)
puts "✓ Models loaded (Author, Post)"

# Set up base directory for file paths
BASE_DIR = File.expand_path("../../", __FILE__)

# Helper method to load fixtures
def load_fixtures
# Clear existing data
Post.delete_all
Author.delete_all

# Load authors from YAML
authors_data = YAML.load_file(File.join(BASE_DIR, "test/fixtures/authors.yml"))
authors_data.each do |key, attrs|
Author.create!(attrs)
end

# Load posts from YAML
posts_data = YAML.load_file(File.join(BASE_DIR, "test/fixtures/posts.yml"))
posts_data.each do |key, attrs|
# Skip posts with author_id: 0 as they don't have valid authors
next if attrs['author_id'] == 0
Post.create!(attrs)
end

puts "✓ Fixtures loaded: #{Author.count} authors, #{Post.count} posts"
end

# Load the fixtures
load_fixtures

puts "\n" + "="*60
puts "ActiveRecord DuckDB Adapter Console Ready!"
puts "="*60
puts "\nAvailable models:"
puts " - Author (#{Author.count} records)"
puts " - Post (#{Post.count} records)"
puts "\nExample usage:"
puts " Author.all"
puts " Post.includes(:author).all"
puts " Author.first.posts"
puts " Post.where(enabled: true)"
puts "\nHelper methods:"
puts " load_fixtures # Reload all fixture data"
puts "\n" + "="*60

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start
Expand Down
Loading