File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ package nestedset
2+
3+ import (
4+ "github.com/satori/go.uuid"
5+ )
6+
7+ type (
8+ // Node represents a node of nested set tree
9+ Node struct {
10+ _tableName string `sql:"-"`
11+ ID uuid.UUID `sql:"type:varbinary(36);NOT NULL" gorm:"primary_key;column:id" json:"-"` //
12+ Left int32 `sql:"type:int;NOT NULL" gorm:"column:lft" json:"-"` //
13+ Right int32 `sql:"type:int;NOT NULL" gorm:"column:rgt" json:"-"` //
14+ Name string `sql:"type:varchar(50);NOT NULL" gorm:"column:name" json:"name,omitempty"` //
15+ Type int32 `sql:"type:int;NOT NULL" gorm:"column:type" json:"type,omitempty"` //
16+ JSONData string `sql:"type:JSON;default:NULL" gorm:"column:data" json:"-"` //
17+ Data interface {} `sql:"-" json:"data,omitempty"` //
18+ Depth int32 `sql:"-" json:"depth,omitempty"` //
19+ Children NodeCollection `sql:"-" json:"children,omitempty"` //
20+ }
21+ )
22+
23+ // NeWNode returns pointer to newly initialized Node
24+ func NeWNode (left , right int32 , name string ) * Node {
25+ n := & Node {
26+ ID : uuid .Must (uuid .NewV4 ()),
27+ Left : left ,
28+ Right : right ,
29+ Name : name ,
30+ }
31+ return n
32+ }
33+
34+ // TableName ::
35+ func (n * Node ) TableName () string {
36+ if n ._tableName != "" {
37+ return n ._tableName
38+ }
39+ return "nodes"
40+ }
41+
42+ // SetTableName ::
43+ func (n * Node ) SetTableName (name string ) {
44+ n ._tableName = name
45+ }
You can’t perform that action at this time.
0 commit comments