gofiber / storage

📦 Premade storage drivers for 🚀 Fiber
https://docs.gofiber.io/storage/
MIT License
274 stars 62 forks source link

[Question] Storing meta data to list all a users sessions #167

Closed Jleagle closed 1 year ago

Jleagle commented 3 years ago

Hi, is it possible to store meta data such as the user id into a new column. I am looking to list all a users sessions when you are logged in to view and delete them. Other info might be useful for me such as ip or user agent but i can probably get that from the value column. However i try this, it requires changing the interface signature which is obviously a problem. Can it be done?

Thanks.

mirusky commented 2 years ago

If database support query in json a workaround would be store the metadata as JSON format. Then you could query like:

-- Postgres
SELECT *
FROM   json_array_elements('[
    { "name": "Toby", "occupation": "Software Engineer" },
    { "name": "Zaphod", "occupation": "Galactic President" }
]') AS elem
WHERE elem->>'name' = 'Toby';
gandaldf commented 1 year ago

@Jleagle I just got published my example about sessions: https://github.com/gofiber/recipes/tree/master/sessions-sqlite3 take a look!

gaby commented 1 year ago

@Jleagle Can this be closed now that an example was posted?