Running in the background?
james-bowers opened this issue · comments
Hi, thanks for this library, it's extremely helpful.
This might be a more general Go question so I apologise in advance if it is, or a really silly question... how do I go about running this in-memory database on a webserver, so code executed from an inbound HTTP request can access it and run queries & insert data into an already established column database?
For context, I'm new to GoLang and come from an Elixir background, where we'd spin up a lightweight process to keep the ets
(in-memory) cache alive, and then each HTTP request is handled by a separate lightweight process and would be allowed access to that ets memory space or send messages to the process with the in-memory db. Is there something similar in GoLang to achieve this? 🤔
Thanks so much 🙏🏼
Working off of https://gobyexample.com/http-servers, here's a super simple example of using column in a web service (not fully implemented) -
package main
import (
"fmt"
"net/http"
)
type MyService struct {
requestCounter int
dataILike *column.Collection
}
func NewService() *MyService {
return &MyService{
requestCounter: 0,
dataILike: createCollection(), //some helper function for creating your cols & indexes
}
}
func (s *MyService) hello(w http.ResponseWriter, req *http.Request) {
s.requestCounter = s.requestCounter + 1
s.dataILike.Query(func (txn *column.Txn) {
// column txn stuff
})
fmt.Fprintf(w, "hello with data %v\n", someDataYouGotAbove)
}
func main() {
s := NewService()
http.HandleFunc("/hello", s.hello)
http.ListenAndServe(":8090", nil)
}
Thanks!