work on loading tags
This commit is contained in:
parent
b5489c4d6b
commit
2d6a58f5e7
33
tags/tags.go
33
tags/tags.go
|
@ -3,6 +3,9 @@ package tags
|
|||
import (
|
||||
"database/sql"
|
||||
_ "github.com/lib/pq"
|
||||
"fmt"
|
||||
"strings"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Tag struct {
|
||||
|
@ -13,6 +16,32 @@ type Tag struct {
|
|||
|
||||
var Tags map[int]*Tag
|
||||
|
||||
func LoadTags(DB *sql.DB) {
|
||||
|
||||
func LoadTags(db *sql.DB) {
|
||||
rows, err := db.Query("select tag_id, name, parent_id, array_agg(distinct(parent_of.tag_id)) from tags join tags as parent_of on tags.parent_id=parent_of.tag_id group by tags.tag_id")
|
||||
|
||||
|
||||
for rows.Next() {
|
||||
tag := &Tag{Children: nil}
|
||||
|
||||
var children sql.NullString
|
||||
var tag_id int
|
||||
err = rows.Scan(&tag_id, &tag.Name, &tag.Name, &tag.Parent, &children)
|
||||
if err != nil {
|
||||
fmt.Println("tags DB Error: ", err)
|
||||
}
|
||||
|
||||
if children.Valid {
|
||||
var childrenStr = children.String[1 : len(children.String)-1]
|
||||
if childrenStr != "NULL" {
|
||||
pids := strings.Split(childrenStr, ",")
|
||||
for _, spid := range pids {
|
||||
pid, _ := strconv.Atoi(spid)
|
||||
|
||||
tags.C
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tags[tag_d] = tag
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue