summaryrefslogtreecommitdiff
path: root/pkg/db/client.go
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2024-06-19 11:04:03 -0600
committermo khan <mo@mokhan.ca>2024-06-19 11:04:03 -0600
commit77bddf64c1991acf97c7c8896203bc9872012918 (patch)
tree44c80a5deccf9dbe412a6b0813b0aa86bdf1ebc4 /pkg/db/client.go
parentee8260d57d8194288c52056ee27b0d0a7c111bdd (diff)
Rename Paramable to Entity
Diffstat (limited to 'pkg/db/client.go')
-rw-r--r--pkg/db/client.go43
1 files changed, 0 insertions, 43 deletions
diff --git a/pkg/db/client.go b/pkg/db/client.go
deleted file mode 100644
index 4f43403..0000000
--- a/pkg/db/client.go
+++ /dev/null
@@ -1,43 +0,0 @@
-package db
-
-import (
- "bytes"
- "fmt"
- "io/ioutil"
- "os"
- "path/filepath"
-
- "github.com/xlgmokha/x/pkg/env"
- "github.com/xlgmokha/x/pkg/serde"
- "github.com/xlgmokha/x/pkg/x"
-)
-
-type Paramable interface {
- ToParam() string
-}
-
-type Storage[T Paramable] struct {
- dir string
-}
-
-func New[T Paramable](dir string) *Storage[T] {
- fullPath := x.Must(filepath.Abs(dir))
- x.Check(os.MkdirAll(fullPath, 0700))
-
- return &Storage[T]{
- dir: fullPath,
- }
-}
-
-func (db *Storage[T]) Save(item T) error {
- w := new(bytes.Buffer)
- x.Check(serde.To(w, item, serde.YAML))
- if env.Fetch("DUMP", "") != "" {
- fmt.Println(w.String())
- }
- return ioutil.WriteFile(
- fmt.Sprintf("%v/%v.yaml", db.dir, item.ToParam()),
- w.Bytes(),
- 0700,
- )
-}