-
Notifications
You must be signed in to change notification settings - Fork 2
/
node.go
45 lines (40 loc) · 1.51 KB
/
node.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package nestedset
import (
"github.com/satori/go.uuid"
)
type (
// Node represents a node of nested set tree
Node struct {
_tableName string `sql:"-"`
ID uuid.UUID `sql:"type:varbinary(36);NOT NULL" gorm:"primary_key;column:id" json:"-"` //
Left int32 `sql:"type:int;NOT NULL" gorm:"column:lft" json:"-"` //
Right int32 `sql:"type:int;NOT NULL" gorm:"column:rgt" json:"-"` //
Name string `sql:"type:varchar(50);NOT NULL" gorm:"column:name" json:"name,omitempty"` //
Type int32 `sql:"type:int;NOT NULL" gorm:"column:type" json:"type,omitempty"` //
JSONData string `sql:"type:JSON;default:NULL" gorm:"column:data" json:"-"` //
Data interface{} `sql:"-" json:"data,omitempty"` //
Depth int32 `sql:"-" json:"depth,omitempty"` //
Children NodeCollection `sql:"-" json:"children,omitempty"` //
}
)
// NeWNode returns pointer to newly initialized Node
func NeWNode(left, right int32, name string) *Node {
n := &Node{
ID: uuid.Must(uuid.NewV4()),
Left: left,
Right: right,
Name: name,
}
return n
}
// TableName ::
func (n *Node) TableName() string {
if n._tableName != "" {
return n._tableName
}
return "nodes"
}
// SetTableName ::
func (n *Node) SetTableName(name string) {
n._tableName = name
}