storage icon indicating copy to clipboard operation
storage copied to clipboard

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

Open Jleagle opened this issue 2 years ago • 1 comments

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.

Jleagle avatar Jul 20 '21 15:07 Jleagle

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';

mirusky avatar Apr 09 '22 17:04 mirusky

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

gandaldf avatar Nov 22 '22 13:11 gandaldf

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

gaby avatar Dec 11 '22 05:12 gaby