refactor: remove unused db relational methods
This commit is contained in:
31
db/rel.go
31
db/rel.go
@@ -2,37 +2,6 @@ package db
|
|||||||
|
|
||||||
import "axolotl/models"
|
import "axolotl/models"
|
||||||
|
|
||||||
func (db *DB) AddRel(f, t string, r models.RelType) error {
|
|
||||||
_, err := db.Exec("INSERT OR IGNORE INTO rels (from_id, to_id, rel_type) VALUES (?, ?, ?)", f, t, r)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
func (db *DB) RemoveRel(f, t string, r models.RelType) error {
|
|
||||||
_, err := db.Exec("DELETE FROM rels WHERE from_id = ? AND to_id = ? AND rel_type = ?", f, t, r)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func getIDs(db *DB, q, id string, r models.RelType) ([]string, error) {
|
|
||||||
rows, err := db.Query(q, id, r)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer rows.Close()
|
|
||||||
var ids []string
|
|
||||||
for rows.Next() {
|
|
||||||
var i string
|
|
||||||
rows.Scan(&i)
|
|
||||||
ids = append(ids, i)
|
|
||||||
}
|
|
||||||
return ids, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (db *DB) GetRelated(id string, r models.RelType) ([]string, error) {
|
|
||||||
return getIDs(db, "SELECT to_id FROM rels WHERE from_id = ? AND rel_type = ?", id, r)
|
|
||||||
}
|
|
||||||
func (db *DB) GetIncomingRels(id string, r models.RelType) ([]string, error) {
|
|
||||||
return getIDs(db, "SELECT from_id FROM rels WHERE to_id = ? AND rel_type = ?", id, r)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (db *DB) GetRelNames(n *models.Node, r models.RelType) ([]string, error) {
|
func (db *DB) GetRelNames(n *models.Node, r models.RelType) ([]string, error) {
|
||||||
ids := n.Relations[string(r)]
|
ids := n.Relations[string(r)]
|
||||||
if len(ids) == 0 {
|
if len(ids) == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user