Move go-sql-queryrepo package into go-kit/sqr
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 34s

Signed-off-by: Jan Tytgat <jan.tytgat@corelayer.eu>
This commit is contained in:
Jan Tytgat
2025-05-21 21:04:53 +02:00
parent 1aca178eb3
commit 37f50324fd
7 changed files with 498 additions and 1 deletions

36
sqr/collection.go Normal file
View File

@ -0,0 +1,36 @@
package queryrepo
import (
"fmt"
)
// newCollection creates a new collection with the supplied name and returns it to the caller.
func newCollection(name string) collection {
return collection{
name: name,
queries: make(map[string]string),
}
}
type collection struct {
name string
queries map[string]string
}
// add adds a query to the collection.
func (c *collection) add(name, query string) error {
if _, ok := c.queries[name]; ok {
return fmt.Errorf("query %s already exists", name)
}
c.queries[name] = query
return nil
}
// get retrieves a query from the collection by name.
// If the query name cannot be found, get() returns an empty string and an error.
func (c *collection) get(name string) (string, error) {
if _, ok := c.queries[name]; !ok {
return "", fmt.Errorf("query %s not found in collection %s", name, c.name)
}
return c.queries[name], nil
}