refactor: remove db package and move database logic to service layer

This commit is contained in:
2026-03-29 21:24:09 +02:00
parent 6ff013dd2a
commit 4ebcb88628
16 changed files with 163 additions and 217 deletions

View File

@@ -1,7 +1,6 @@
package cmd
import (
"axolotl/db"
"axolotl/models"
"axolotl/output"
"axolotl/service"
@@ -19,12 +18,6 @@ var cTags, cRels []string
var addCmd = &cobra.Command{
Use: "add <title>", Short: "Create a new node", Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
d, err := db.GetDB()
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
if !slices.ContainsFunc(cTags, func(e string) bool { return strings.HasPrefix(e, "_type::") }) {
cTags = append(cTags, "_type::issue")
}
@@ -49,11 +42,13 @@ var addCmd = &cobra.Command{
rels[models.RelInNamespace] = append(rels[models.RelInNamespace], cfg.GetUser())
}
svc := service.NewSQLiteNodeService(d.DB, cfg.GetUser())
if n, err := svc.Create(args[0], cContent, cDue, cTags, rels); err != nil {
svc, err := service.GetNodeService(cfg)
if err != nil {
fmt.Fprintln(os.Stderr, "failed to create:", err)
} else if n, err := svc.Create(args[0], cContent, cDue, cTags, rels); err != nil {
fmt.Fprintln(os.Stderr, "failed to create:", err)
} else {
output.PrintNode(cmd.OutOrStdout(), n, jsonFlag)
output.PrintNode(cmd.OutOrStdout(), svc, n, jsonFlag)
}
},
}