Anyway I can lookup username:email format in KV using worker (without list) ?
For example, i have a format username:email
if user logins with their username it can use READ and able to get username even with username:email format, however, with email I can't manage to get the email prefix
12 Replies
Can you give some example? I don't get what you'd like to achieve
in KV Database
I have a key lets say (password is in value thats not a problem)
flutch2:[email protected]
I use cf worker api to login to the account
so if i login as
flutch2
Testing123!@#
it is able to find the key flutch2:[email protected]
and logs me in
if i login as
[email protected] Testing123!@# it isnt able to find the key flutch2:[email protected] and doesn't log me in
[email protected] Testing123!@# it isnt able to find the key flutch2:[email protected] and doesn't log me in
I use cf worker api to login to the accountPlease precise what kind of API you use
CF Worker using KV Bindings
As far as I understand the key must be fully accurate with the one stored in namespace - you cannot query the namespace with only the part of key (only email or login).
In your case I'd store it in D1 with some hashing on the password value for extra security.
Then you can freely query the database with only the login or email.
So D1's the only route
Got it, thanks!
That's how I'd aproach it. Mixing KV and D1 together here is overkill imo.
D1 gives you much more flexibility in quering the data.
So what's the point for KV then?
It gives the same speed etc.
If you could precisely determine the
key
- KV would work here great. Unfortunately you can't.
So the issue is you need more flexibility on querying and KV doesn't offer it.
KV has simple data shape: the key and associated value. And the only way to get the value is by knowing the key.
D1 is the SQL database so table shape can be more complex having separate columns for login, email and password so each column can be separately referenced. That way you can query it having only partial information - an email or login.I see
For your case I'd store data in two tables:
Oh dont worry I got it figured out and migrated it already, thanks for the help :D