nested

package module
v0.0.0-...-cb20f4b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2020 License: MIT Imports: 4 Imported by: 0

README

GORM Nested Set Tree Go Report Card Build Status Coverage Status

Do not use in production. This is an experiment!!!
Install

go get github.com/vcraescu/gorm-nested

How to use
type Taxon struct {
	ID        uint `gorm:"primary_key"`
	Name      string
	ParentID  uint
	Parent    *Taxon `gorm:"association_autoupdate:false"`
	TreeLeft  int    `gorm-nested:"left"`
	TreeRight int    `gorm-nested:"right"`
	TreeLevel int    `gorm-nested:"level"`
}

func (t Taxon) GetParentID() interface{} {
	return t.ParentID
}

func (t Taxon) GetParent() nested.Interface {
	return t.Parent
}

func main() {
	db, err := gorm.Open("sqlite3", "my_dbname")
	if err != nil {
		panic(err)
	}

	db.AutoMigrate(&Taxon{})

	_, err = nested.Register(db)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface interface {
	GetParentID() interface{}
	GetParent() Interface
}

Interface must be implemented by the gorm model

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

Plugin gorm nested set plugin

func Register

func Register(db *gorm.DB) (Plugin, error)

Register registers nested set plugin

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL