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(free): add readKeys method to free session storage adapter #242

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nullhq
Copy link

@nullhq nullhq commented Feb 21, 2025

Adding the readAllKeys Method to the Free Session Storage Adapter

Problem

Right now, we have a read method that lets you read a session, but it requires a key. The question is... how do you get that key? Well, I don't know ;)

Solution

The new readAllKeys method helps you fetch all available keys, which you can then use with read to get specific session data.

Changes Due to readAllKeys

  • key in call is now optional, allowing global requests.
  • The URL structure now depends on key:
    • If key is provided, you want to read a specific session (like read does now).
    • If key is missing, you want to retrieve all session keys (which readAllKeys now handles).

Notes

The endpoint /sessions used for readAllKeys is provided by the storage adapter server here:
https://github.com/grammyjs/free-session-backend/blob/778a383057e7b8a244fdb2beee20542d8ce0867b/src/main.ts#L89

PS: Hope this helps someone in the future, just like it helped me today! Hihihi

Adding the readKeys Method to the Free Session Storage Adapter  

-Problem
Right now, we have a read method that lets you read a session, but it requires a key. The question is... how do you get that key? Well, I have no idea.  

-Solution
The new readKeys method helps you fetch all available keys, which you can then use with read to get specific session data.  

-Changes Due to readKeys
- key in call is now optional, allowing global calls.  
- The URL structure now depends on key:  
  - If key is provided, you want to read a specific session (like read does now).  
  - If key is missing, you want to retrieve all session keys (which readKeys now handles).  

-Notes  
The endpoint /sessions used for readKeys is provided by the free storage adapter server here:  
https://github.com/grammyjs/free-session-backend/blob/778a383057e7b8a244fdb2beee20542d8ce0867b/src/main.ts#L89

PS: Hope this helps someone in the future, just like it helped me today! Hihihi
Copy link
Member

@KnorpelSenf KnorpelSenf left a comment

Choose a reason for hiding this comment

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

Great stuff! Thanks! Let's wait for another review by @Satont who maintains the storage adapters before merging this

@KnorpelSenf KnorpelSenf requested a review from Satont February 21, 2025 09:34
@nullhq
Copy link
Author

nullhq commented Feb 21, 2025

ok well ;)

@nullhq
Copy link
Author

nullhq commented Feb 21, 2025

I think that here also a readSessions method could be implemented, to directly provide all available sessions.

I currently need to retrieve all my sessions and migrate to mongodb.

by looping the read method with the keys it is possible but it would be more efficient if a readSessions was implemented.
@KnorpelSenf what do you think about that ?

https://github.com/grammyjs/free-session-backend/blob/778a383057e7b8a244fdb2beee20542d8ce0867b/src/session.ts

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.

2 participants