implement DuckDB::InstanceCache#get_or_create
DuckDB::InstanceCache#get_or_createis wrapping C-APIduckdb_get_or_create_from_cache.
Summary by CodeRabbit
- New Features
- Introduced functionality to create database objects from existing handles.
- Implemented a caching mechanism for efficient retrieval or creation of database instances with customizable options.
- Added a new class to manage database instances with keyword arguments for path and configuration.
- Bug Fixes
- Enhanced error handling for database instance creation failures.
- Tests
- Added comprehensive tests for the
get_or_createmethod under various scenarios to ensure reliability.
- Added comprehensive tests for the
Walkthrough
This pull request adds a new function to create a Ruby database object from an existing DuckDB handle and implements a method to retrieve or create a DuckDB database instance from a cache with optional path and configuration arguments. It introduces the DuckDB::InstanceCache Ruby class with a get method, updates the Ruby interface to include this class, and adds comprehensive tests for the new caching functionality. The Windows GitHub Actions workflow is also updated to exclude testing on the 'head' Ruby version.
Changes
| File(s) | Change Summary |
|---|---|
ext/duckdb/database.cext/duckdb/database.h |
Added new function rbduckdb_create_database_obj to create a Ruby object from a DuckDB database handle, including its declaration and implementation. |
ext/duckdb/instance_cache.c |
Added method duckdb_instance_cache_get_or_create to retrieve or create a database instance from cache, handling optional path and config arguments, error checking, and registered as get_or_create. |
lib/duckdb/instance_cache.rb |
Added new DuckDB::InstanceCache class with a get method to manage database instances by path and config, delegating to the native extension method for retrieval or creation. |
lib/duckdb.rb |
Added require "duckdb/instance_cache" to load the new InstanceCache class. |
test/duckdb_test/instance_cache_test.rb |
Added multiple tests in InstanceCacheTest to verify get_or_create behavior with various arguments including path, empty path, memory, config, and multi-threading, ensuring correct instance creation. |
CHANGELOG.md |
Documented the addition of the DuckDB::InstanceCache class, highlighting new instance caching functionality. |
.github/workflows/test_on_windows.yml |
Modified Ruby version matrix to exclude the 'head' Ruby version for Windows tests, retaining other Ruby versions and Windows variants. |
Sequence Diagram(s)
sequenceDiagram
participant RubyApp
participant rbduckdb_create_database_obj
participant Allocator
participant RubyDuckDB
RubyApp->>rbduckdb_create_database_obj: Call with duckdb_database handle
rbduckdb_create_database_obj->>Allocator: Allocate cDuckDBDatabase object
Allocator-->>rbduckdb_create_database_obj: Return allocated object
rbduckdb_create_database_obj->>RubyDuckDB: Retrieve RubyDuckDB structure
rbduckdb_create_database_obj->>RubyDuckDB: Assign provided duckdb_database to db field
rbduckdb_create_database_obj->>RubyApp: Return new Ruby DB object
sequenceDiagram
participant RubyApp
participant InstanceCache
participant ArgumentProcessor
participant DuckDBCache
RubyApp->>InstanceCache: get_or_create(vpath, vconfig)
InstanceCache->>ArgumentProcessor: Validate & parse arguments
ArgumentProcessor->>DuckDBCache: Request DB instance (or create)
DuckDBCache-->>ArgumentProcessor: Return DB instance or error
ArgumentProcessor-->>InstanceCache: Pass result or raise error
InstanceCache->>RubyApp: Return DB object
Poem
I'm a hopping coder, a rabbit in the night,
Celebrating new functions shining bright.
With DuckDB objects crafted sly and neat,
And caches that cache with a rhythmic beat.
My ears twitch with every line of code,
A joyful leap on our development road! 🐇
[!TIP]
⚡️ Faster reviews with caching
- CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure
Review - Disable Cacheat either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off theData Retentionsetting under your Organization Settings.Enjoy the performance boost—your workflow just got faster.
📜 Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 5de5ba355c7a48d38a51cbdfe41e0d7e55e1215a and 9103361db0e8a28588abf2d4e05e64dc7f88b1ae.
📒 Files selected for processing (1)
.github/workflows/test_on_windows.yml(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- .github/workflows/test_on_windows.yml
⏰ Context from checks skipped due to timeout of 90000ms (17)
- GitHub Check: test (mswin, 1.1.3)
- GitHub Check: test (mswin, 1.1.1)
- GitHub Check: test (ucrt, 1.2.2)
- GitHub Check: test (3.2.6, 1.1.1)
- GitHub Check: test (mswin, 1.2.2)
- GitHub Check: test (3.3.6, 1.1.3)
- GitHub Check: test (ucrt, 1.1.3)
- GitHub Check: test (3.3.6, 1.1.1)
- GitHub Check: test (3.1.6, 1.1.1)
- GitHub Check: test (3.4.1, 1.1.3)
- GitHub Check: test (3.3.6, 1.2.2)
- GitHub Check: test (3.4.1, 1.2.2)
- GitHub Check: test (3.4.1, 1.1.1)
- GitHub Check: test (3.2.6, 1.1.3)
- GitHub Check: test (3.1.6, 1.1.3)
- GitHub Check: test (3.2.6, 1.2.2)
- GitHub Check: test (3.1.6, 1.2.2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and generate unit testing code.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.