Skip to content

Conversation

@avelino
Copy link
Member

@avelino avelino commented Apr 8, 2025

This commit improves the documentation and implementation of the storage structure in ChronDB:

  1. Adds detailed documentation about the storage structure in README.md:

    • Explains how tables are represented as directories
    • Documents how files are organized within table directories
    • Provides examples of file paths with and without data directory
  2. Updates git.clj implementation to better handle table-based storage:

    • Improves path handling for table-based document storage
    • Ensures proper encoding of table names and document IDs
    • Maintains backward compatibility with existing document paths

The changes make the storage structure more explicit and easier to understand while maintaining compatibility with existing data.

Summary by CodeRabbit

  • Documentation
    • Introduced a new section explaining how documents are organized using a structured, table-based directory system with clear examples.
  • New Features
    • Enhanced document management for improved organization and backward compatibility, resulting in more reliable data retrieval and handling.

This commit improves the documentation and implementation of the storage structure in ChronDB:

1. Adds detailed documentation about the storage structure in README.md:
   - Explains how tables are represented as directories
   - Documents how files are organized within table directories
   - Provides examples of file paths with and without data directory

2. Updates git.clj implementation to better handle table-based storage:
   - Improves path handling for table-based document storage
   - Ensures proper encoding of table names and document IDs
   - Maintains backward compatibility with existing document paths

The changes make the storage structure more explicit and easier to understand while maintaining compatibility with existing data.

Signed-off-by: Avelino <[email protected]>
@avelino avelino added :bug Something isn't working :enhancement New feature or request labels Apr 8, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 8, 2025

📝 Walkthrough

Walkthrough

This pull request updates ChronDB’s storage system. The README now includes a new "Storage Structure" section that explains the organization of documents within table directories as JSON files, using document IDs as filenames. In the source code, the get-file-path function is enhanced to support an extra table name parameter for improved backward compatibility and organization. A new get-document-path function is added to traverse the repository for documents, and related methods (save-document, get-document, delete-document, and get-documents-by-table) are updated accordingly.

Changes

File(s) Change Summary
README.md Added new "Storage Structure" section detailing document organization: directories per table, JSON file naming using document IDs, and inclusion of a _table field.
src/chrondb/storage/git.clj Enhanced get-file-path with overloaded arity accepting table-name for backward compatibility; added get-document-path for directory traversal; updated save-document, get-document, get-documents-by-table, and delete-document to use new path logic and logging.

Sequence Diagram(s)

sequenceDiagram
    participant App as Application
    participant Storage as ChronDB Storage
    participant Git as Git Repository

    App->>Storage: Call save-document(document)
    Storage->>Storage: Extract table name from document
    Storage->>Storage: Call get-file-path(data-dir, id, table-name)
    Storage->>Git: Write JSON document at constructed path
    Storage-->>App: Confirm document saved
Loading
sequenceDiagram
    participant App as Application
    participant Storage as ChronDB Storage
    participant Git as Git Repository

    App->>Storage: Call get-document(id)
    Storage->>Storage: Invoke get-document-path(repository, id)
    Storage->>Git: Traverse directories to locate JSON file
    Git-->>Storage: Return file path or nil
    Storage-->>App: Return retrieved document or null
Loading

Possibly related PRs

Poem

I'm a rabbit in the codefield, hopping by,
Rejoicing in paths where JSON files lie.
Tables and directories aligned in a row,
With logs and new flows that smoothly go.
Carrot-code delights in each new tweak,
ChronDB blossoms with a structure so sleek!


🪧 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 @coderabbitai in 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 @coderabbitai in 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.

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 pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file 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.

@avelino avelino merged commit 15dd5dd into main Apr 8, 2025
8 of 9 checks passed
@avelino avelino deleted the avelino/sql-table-is-folder-in-repo branch April 8, 2025 01:25
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
README.md (3)

45-45: Consider using more descriptive verbs in the documentation.
Stating "Documents are stored in a directory..." could be made more assertive or direct by using "organized" or "maintained." This is purely stylistic, but may read more smoothly.

🧰 Tools
🪛 LanguageTool

[style] ~45-~45: Consider using a different verb to strengthen your wording.
Context: ...re stored in a directory structure that follows these rules: - Each table is a directo...

(FOLLOW_OBEY)


54-56: Specify a language for your fenced code block.
According to markdownlint (MD040), it's recommended to include a language identifier after the triple backticks.

Here's a possible fix:

-```
+```plaintext
 user/123.json
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

54-54: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


60-62: Add a language identifier to the fenced code block.
Similarly, consider specifying plaintext here for clarity and consistency.

Here's a possible fix:

-```
+```plaintext
 {data-dir}/user/123.json
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

60-60: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

src/chrondb/storage/git.clj (1)

241-266: Potential improvement in searching for the document path.
Using .contains(path, (str encoded-id ".json")) works, but might be more explicit with something like .endsWith(path, (str encoded-id ".json")) to avoid any edge-case collisions. Otherwise, the approach is straightforward and likely sufficient for typical usage.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c4febe3 and 349d4af.

📒 Files selected for processing (2)
  • README.md (1 hunks)
  • src/chrondb/storage/git.clj (7 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md

[style] ~45-~45: Consider using a different verb to strengthen your wording.
Context: ...re stored in a directory structure that follows these rules: - Each table is a directo...

(FOLLOW_OBEY)

🪛 markdownlint-cli2 (0.17.2)
README.md

54-54: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


60-60: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (5)
src/chrondb/storage/git.clj (5)

222-230: Good approach for backward compatibility with old ID format.
This fallback to a "default" table is helpful and ensures existing documents remain accessible. However, consider verifying how the code handles IDs with multiple colons (e.g., "foo:bar:baz"). If needed, add tests or a note in the documentation to clarify expected behavior.


231-239: Solid implementation of the table-based file path.
This is a clear and maintainable approach to building consistent file paths.


393-405: Clean approach to table-based document filtering.
Logging the table path prefix helps with debugging, and checking for .json extension plus .startsWith(path, table-path-prefix + "/") ensures robust filtering.

Also applies to: 417-419


436-480: Improved delete-document flow with table identification logic.
Fetching the document first to retrieve its _table greatly improves correctness and consistency with the rest of the storage approach.


496-496: Constructing GitStorage with a custom data directory is a nice enhancement.
This addition aligns well with the new table-based structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:bug Something isn't working :enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants