refactor: replace explicit fields with tag-based property system

This commit is contained in:
2026-03-27 02:11:46 +01:00
parent 2d4cff717b
commit b2225cff7b
17 changed files with 485 additions and 825 deletions

View File

@@ -2,35 +2,25 @@ package db
import "errors"
type Alias struct {
Name string
Command string
}
type Alias struct{ Name, Command string }
func (db *DB) GetAlias(name string) (*Alias, error) {
func (db *DB) GetAlias(n string) (*Alias, error) {
a := &Alias{}
err := db.QueryRow("SELECT name, command FROM aliases WHERE name = ?", name).Scan(&a.Name, &a.Command)
if err != nil {
return nil, err
}
return a, nil
err := db.QueryRow("SELECT name, command FROM aliases WHERE name = ?", n).Scan(&a.Name, &a.Command)
return a, err
}
func (db *DB) SetAlias(name, command string) error {
_, err := db.Exec(
"INSERT INTO aliases (name, command) VALUES (?, ?) ON CONFLICT(name) DO UPDATE SET command = excluded.command",
name, command,
)
func (db *DB) SetAlias(n, c string) error {
_, err := db.Exec("INSERT INTO aliases (name, command) VALUES (?, ?) ON CONFLICT(name) DO UPDATE SET command = excluded.command", n, c)
return err
}
func (db *DB) DeleteAlias(name string) error {
res, err := db.Exec("DELETE FROM aliases WHERE name = ?", name)
func (db *DB) DeleteAlias(n string) error {
res, err := db.Exec("DELETE FROM aliases WHERE name = ?", n)
if err != nil {
return err
}
n, _ := res.RowsAffected()
if n == 0 {
if a, _ := res.RowsAffected(); a == 0 {
return errors.New("alias not found")
}
return nil
@@ -42,7 +32,6 @@ func (db *DB) ListAliases() ([]*Alias, error) {
return nil, err
}
defer rows.Close()
var aliases []*Alias
for rows.Next() {
a := &Alias{}