{"id":25286266,"url":"https://github.com/thecomputerm/surrealstore","last_synced_at":"2025-04-06T15:34:42.609Z","repository":{"id":275205304,"uuid":"925396304","full_name":"TheComputerM/surrealstore","owner":"TheComputerM","description":"A SurrealDB session store backend for gorilla/sessions","archived":false,"fork":false,"pushed_at":"2025-01-31T20:34:34.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-08T08:44:48.056Z","etag":null,"topics":["golang","gorilla-sessions","surrealdb"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TheComputerM.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-31T19:54:08.000Z","updated_at":"2025-01-31T20:25:40.000Z","dependencies_parsed_at":"2025-01-31T21:33:59.729Z","dependency_job_id":null,"html_url":"https://github.com/TheComputerM/surrealstore","commit_stats":null,"previous_names":["thecomputerm/surrealstore"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheComputerM%2Fsurrealstore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheComputerM%2Fsurrealstore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheComputerM%2Fsurrealstore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheComputerM%2Fsurrealstore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TheComputerM","download_url":"https://codeload.github.com/TheComputerM/surrealstore/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247503777,"owners_count":20949504,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","gorilla-sessions","surrealdb"],"created_at":"2025-02-12T21:35:09.676Z","updated_at":"2025-04-06T15:34:42.577Z","avatar_url":"https://github.com/TheComputerM.png","language":"Go","readme":"# surrealstore\n\nA session store backend for [gorilla/sessions](https://github.com/gorilla/sessions) using [SurrealDB](https://surrealdb.com/).\n\n```sh\ngo get -u github.com/thecomputerm/surrealstore\n```\n\n## Example\n\n```go\npackage examples\n\nimport (\n\t\"log\"\n\t\"net/http\"\n\t\"time\"\n\n\t\"github.com/surrealdb/surrealdb.go\"\n\t\"github.com/thecomputerm/surrealstore\"\n)\n\n// ExampleHandler is an example that displays the usage of PGStore.\nfunc ExampleHandler(w http.ResponseWriter, r *http.Request) {\n\tdb, err := surrealdb.New(\"ws://localhost:8000\")\n\tif err != nil {\n\t\tlog.Fatalln(\"Requires a real instance of surrealdb listening on localhost:8000.\")\n\t}\n\n\tif _, err = db.SignIn(\u0026surrealdb.Auth{\n\t\tUsername: \"root\",\n\t\tPassword: \"root\",\n\t}); err != nil {\n\t\tlog.Fatalf(\"Failed to sign in to surrealdb: %v\", err)\n\t}\n\n\tif err = db.Use(\"default\", \"auth\"); err != nil {\n\t\tlog.Fatalf(\"Failed to use correct namespace and db: %v\", err)\n\t}\n\n\t// Fetch new store.\n\tstore, err := surrealstore.NewSurrealStore(db, []byte(\"secret-key\"))\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to create a store: %v\", err)\n\t}\n\n\t// Run a background goroutine to clean up expired sessions from the database.\n\tdefer store.StopCleanup(store.Cleanup(time.Minute * 5))\n\n\t// Get a session.\n\tsession, err := store.Get(r, \"session-key\")\n\tif err != nil {\n\t\tlog.Fatalf(\"Error getting session: %v\", err)\n\t}\n\n\t// Add a value.\n\tsession.Values[\"foo\"] = \"bar\"\n\n\t// Save.\n\tif err = session.Save(r, w); err != nil {\n\t\tlog.Fatalf(\"Error saving session: %v\", err)\n\t}\n\n\t// Delete session.\n\tsession.Options.MaxAge = -1\n\tif err = session.Save(r, w); err != nil {\n\t\tlog.Fatalf(\"Error saving session: %v\", err)\n\t}\n}\n```\n\nTo integrate it with [Gin](https://github.com/gin-gonic/gin), create a store mimicking the [postgres driver](https://github.com/gin-contrib/sessions/blob/master/postgres/postgres.go).\n\n## Thanks\n\nI've primarily just snatched and modified the code from [pgstore](https://github.com/antonlindstrom/pgstore) because it was the one [gin-sessions](https://github.com/gin-contrib/sessions) was using.\n\n## Notes\n\n- Wrapping the time.Time object in a models.CustomDateTime struct because of [this issue](https://github.com/surrealdb/surrealdb.go/issues/181).","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecomputerm%2Fsurrealstore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthecomputerm%2Fsurrealstore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecomputerm%2Fsurrealstore/lists"}