Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(storage): default data storage for node and dev presets #1352

Merged
merged 3 commits into from Jun 30, 2023

Conversation

pi0
Copy link
Member

@pi0 pi0 commented Jun 27, 2023

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

The storage interface from useStorage is by default all in memory. In order to write stateful KV logic, users therefore require to configure storage mountpoints.

This PR adds a default data mountpoint using fs driver for all node based presets and development mode. (only if not configured by user) This way data will be persisted in .data/kv by default only for data: .

export default eventHandler(async (event) => {
  const kvStorage = useStorage("data");
  const counter = (Number(await kvStorage.getItem("counter")) || 0) + 1;
  await kvStorage.setItem("counter", counter);
  return {
    counter,
  };
});

Next steps:

  • Support auto config storage for other worker presets when env/binding exits
  • Document this feature + .data dir and gitignore
  • Use data storage for cache as well (or consider persisting .nitro/.nuxt partially)

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codecov
Copy link

codecov bot commented Jun 27, 2023

Codecov Report

Merging #1352 (486172e) into main (a915422) will decrease coverage by 0.28%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1352      +/-   ##
==========================================
- Coverage   76.68%   76.40%   -0.28%     
==========================================
  Files          70       70              
  Lines        7162     7179      +17     
  Branches      710      710              
==========================================
- Hits         5492     5485       -7     
- Misses       1669     1693      +24     
  Partials        1        1              
Impacted Files Coverage Ξ”
src/options.ts 94.65% <100.00%> (+0.21%) ⬆️

... and 2 files with indirect coverage changes

@pi0 pi0 merged commit 1d0c120 into main Jun 30, 2023
7 checks passed
@pi0 pi0 deleted the feat/persistant-storage branch June 30, 2023 11:56
@pi0 pi0 mentioned this pull request Aug 4, 2023
@4F2E4A2E
Copy link

Could this be related? Default Persistent Data Storage Import is broken nuxt/nuxt#23484

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants