Skip to content

Refactor sqlite layer creation to use local variable in makeSqlitePersistenceLive#7

Open
Josh-wt wants to merge 3 commits intomainfrom
codex/fix-service-not-found-error-z7i8rm
Open

Refactor sqlite layer creation to use local variable in makeSqlitePersistenceLive#7
Josh-wt wants to merge 3 commits intomainfrom
codex/fix-service-not-found-error-z7i8rm

Conversation

@Josh-wt
Copy link
Copy Markdown
Owner

@Josh-wt Josh-wt commented Apr 11, 2026

Motivation

  • Improve readability and make the sqlite layer easier to reference and extend in makeSqlitePersistenceLive by naming the layer before merging it with setup.

Description

  • Create a sqliteLayer constant from makeRuntimeSqliteLayer({...}) and return Layer.provideMerge(setup, sqliteLayer) instead of inlining the call.
  • Preserve existing PRAGMA setup and span attributes; no changes to runtime detection or configuration values.
  • Apply minor formatting cleanup around the returned expression.

Testing

  • No automated tests were executed as part of this change.

Codex Task


Summary by cubic

Refactors sqlite persistence by introducing a shared builder and documenting layer ordering to prevent regressions. No behavior change; improves clarity and reuse.

  • Refactors
    • Added makeSqlitePersistenceLayer(config) to merge setup with makeRuntimeSqliteLayer.
    • Updated makeSqlitePersistenceLive and SqlitePersistenceMemory to use the builder.
    • Documented dependency order (provide SqlClient into setup); preserved PRAGMA setup and span attributes.

Written for commit d90deec. Summary will update on new commits.

Summary by CodeRabbit

  • Refactor
    • Simplified and consolidated database persistence layer initialization for clearer internal structure. No changes to behavior, public interfaces, or user-facing functionality.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 11, 2026

📝 Walkthrough

Walkthrough

A new makeSqlitePersistenceLayer(config) helper was added to encapsulate Layer.provideMerge(setup, makeRuntimeSqliteLayer(config)). makeSqlitePersistenceLive and SqlitePersistenceMemory were updated to use this helper; no changes to setup, runtime creation, or passed filename/spanAttributes.

Changes

Cohort / File(s) Summary
Sqlite persistence helper & usages
apps/server/src/persistence/Layers/Sqlite.ts
Added makeSqlitePersistenceLayer(config) to wrap Layer.provideMerge(setup, makeRuntimeSqliteLayer(config)); updated makeSqlitePersistenceLive and SqlitePersistenceMemory to call the helper instead of inlining provideMerge. No behavior or config value changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hop through code with nimble cheer,
I tuck a helper warm and near,
Merge once inlined now neatly spun,
A tidy path for layers done.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: refactoring sqlite layer creation to use a local variable in makeSqlitePersistenceLive, which aligns with the actual code modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The PR description covers all required sections: motivation, description, and testing. It clearly explains what changed and why.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-service-not-found-error-z7i8rm

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
apps/server/src/persistence/Layers/Sqlite.ts (1)

56-59: Consider extracting the layer for consistency.

For consistency with the refactored makeSqlitePersistenceLive, consider extracting the makeRuntimeSqliteLayer call into a named constant:

const memoryLayer = makeRuntimeSqliteLayer({ filename: ":memory:" });
export const SqlitePersistenceMemory = Layer.provideMerge(setup, memoryLayer);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/server/src/persistence/Layers/Sqlite.ts` around lines 56 - 59, Extract
the inline makeRuntimeSqliteLayer({ filename: ":memory:" }) call into a named
constant (e.g., memoryLayer) and use that constant in the Layer.provideMerge
call for SqlitePersistenceMemory so it matches the refactor style of
makeSqlitePersistenceLive; update the export to call Layer.provideMerge(setup,
memoryLayer) and keep the constant name clear and adjacent to the
SqlitePersistenceMemory declaration for readability.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apps/server/src/persistence/Layers/Sqlite.ts`:
- Around line 56-59: Extract the inline makeRuntimeSqliteLayer({ filename:
":memory:" }) call into a named constant (e.g., memoryLayer) and use that
constant in the Layer.provideMerge call for SqlitePersistenceMemory so it
matches the refactor style of makeSqlitePersistenceLive; update the export to
call Layer.provideMerge(setup, memoryLayer) and keep the constant name clear and
adjacent to the SqlitePersistenceMemory declaration for readability.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b7783313-6f2f-430c-9d10-857eeec527d9

📥 Commits

Reviewing files that changed from the base of the PR and between b62aeb4 and 15a3b5f.

📒 Files selected for processing (1)
  • apps/server/src/persistence/Layers/Sqlite.ts

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

Copy link
Copy Markdown

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/server/src/persistence/Layers/Sqlite.ts`:
- Around line 48-56: The generator for Effect.fn("makeSqlitePersistenceLive") is
missing its closing brace and the Layer.unwrap export, leaving export const
SqlitePersistenceMemory syntactically inside that function; close the Effect.fn
block properly and return/unwrap the Layer (use Layer.unwrap or the same pattern
used for other persistence layers) so the live layer definition is complete
(ensure the function name makeSqlitePersistenceLive and the Layer.unwrap call
are added/closed) and then the top-level export const SqlitePersistenceMemory
can appear after the closed block.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8d416cd8-40af-4055-ac00-4f043290c176

📥 Commits

Reviewing files that changed from the base of the PR and between 15a3b5f and 042849c.

📒 Files selected for processing (1)
  • apps/server/src/persistence/Layers/Sqlite.ts

Comment on lines +48 to +56
return makeSqlitePersistenceLayer({
filename: dbPath,
spanAttributes: {
"db.name": path.basename(dbPath),
"service.name": "t3-server",
},
});

export const SqlitePersistenceMemory = Layer.provideMerge(
setup,
makeRuntimeSqliteLayer({ filename: ":memory:" }),
);
export const SqlitePersistenceMemory = makeSqlitePersistenceLayer({ filename: ":memory:" });
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Read-only verification: show the affected block and confirm missing closure before Line 56.
nl -ba apps/server/src/persistence/Layers/Sqlite.ts | sed -n '41,62p'

Repository: Josh-wt/t3code

Length of output: 98


🏁 Script executed:

cat -n apps/server/src/persistence/Layers/Sqlite.ts | sed -n '40,65p'

Repository: Josh-wt/t3code

Length of output: 870


Blocker: makeSqlitePersistenceLive is not closed, causing a parse error at Line 56.

The generator function for Effect.fn("makeSqlitePersistenceLive") is missing its closing brace and the Layer.unwrap configuration. export const SqlitePersistenceMemory at line 56 cannot be parsed as a top-level statement because it remains syntactically nested inside the unclosed function.

Proposed fix
  return makeSqlitePersistenceLayer({
    filename: dbPath,
    spanAttributes: {
      "db.name": path.basename(dbPath),
      "service.name": "t3-server",
    },
  });
+}, Layer.unwrap);

 export const SqlitePersistenceMemory = makeSqlitePersistenceLayer({ filename: ":memory:" });
🧰 Tools
🪛 Biome (2.4.10)

[error] 56-56: Illegal use of an export declaration not at the top level

(parse)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/server/src/persistence/Layers/Sqlite.ts` around lines 48 - 56, The
generator for Effect.fn("makeSqlitePersistenceLive") is missing its closing
brace and the Layer.unwrap export, leaving export const SqlitePersistenceMemory
syntactically inside that function; close the Effect.fn block properly and
return/unwrap the Layer (use Layer.unwrap or the same pattern used for other
persistence layers) so the live layer definition is complete (ensure the
function name makeSqlitePersistenceLive and the Layer.unwrap call are
added/closed) and then the top-level export const SqlitePersistenceMemory can
appear after the closed block.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant