nestedset

package module
v0.0.0-...-359b39c Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2020 License: MIT Imports: 14 Imported by: 0

README

sql-nested-set

Nested set Model over SQL with Go! Lang

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultScheme = Scheme{
	Columns: SchemeColumns{
		ID:           SchemeColumn{"id", "INTEGER PRIMARY KEY AUTOINCREMENT"},
		Lft:          SchemeColumn{"lft", "INT NOT NULL"},
		Rgt:          SchemeColumn{"rgt", "INT NOT NULL"},
		Name:         SchemeColumn{"name", "VARCHAR(64) NOT NULL"},
		Depth:        SchemeColumn{"depth", "INT NOT NULL DEFAULT 0"},
		ParentID:     SchemeColumn{"parent_id", "BIGINT NOT NULL DEFAULT 0"},
		DenyChildren: SchemeColumn{"deny_children", "BOOLEAN NOT NULL DEFAULT FALSE"},
	},
	Indexes: []SchemeIndex{
		{Columns: []string{"name"}},
		{Columns: []string{"depth"}},
		{Columns: []string{"lft"}},
		{Columns: []string{"rgt"}},
		{ColumnsFunc: func(s Scheme, i SchemeIndex) []string {
			return []string{"parent_id", s.Columns.Name.Name}
		}, Unique: true},
	},
}

Functions

func CompileQueryOptions

func CompileQueryOptions(opts ...SelectOptions) (selec, order, limit string)

func Dv

func Dv(v interface{}) interface{}

Types

type DefaultDriver

type DefaultDriver struct {
	InsertColumns []string
	NewID         func() ID
	// contains filtered or unexported fields
}

func NewDefaultDriver

func NewDefaultDriver() *DefaultDriver

func (DefaultDriver) BuildPathQuery

func (this DefaultDriver) BuildPathQuery(b builder.Builder, root *Node) builder.Builder

func (DefaultDriver) BuildPathQueryFromDepth

func (this DefaultDriver) BuildPathQueryFromDepth(depth int32) (column, from, join string)

func (DefaultDriver) Children

func (this DefaultDriver) Children(ctx context.Context, id ID, b builder.Builder) (query string, args []interface{}, err error)

func (DefaultDriver) ControlDetail

func (this DefaultDriver) ControlDetail(ctx context.Context, id ID) (query string, args []interface{})

func (DefaultDriver) DDL

func (this DefaultDriver) DDL() []string

func (DefaultDriver) DDLScheme

func (this DefaultDriver) DDLScheme(s Scheme) []string

func (DefaultDriver) Delete

func (DefaultDriver) Delete(ctx context.Context, id ID, lft, rgt int64, iargs ...interface{}) (query string, args []interface{})

func (DefaultDriver) Detail

func (this DefaultDriver) Detail(ctx context.Context, id ID) (query string, args []interface{})

func (DefaultDriver) FindID

func (DefaultDriver) FindID(ctx context.Context, lft, rgt int64) (query string, args []interface{})

func (DefaultDriver) Insert

func (this DefaultDriver) Insert(ctx context.Context, node *Node, name string, iargs ...interface{}) (query string, args []interface{})

func (DefaultDriver) MaxRight

func (DefaultDriver) MaxRight(ctx context.Context) (query string, args []interface{})

func (DefaultDriver) MoveAftersLeft

func (DefaultDriver) MoveAftersLeft(ctx context.Context, start, length int64) struct {
	Lefts, Rigths struct {
		Query string
		Args  []interface{}
	}
}

func (DefaultDriver) MoveAftersRight

func (DefaultDriver) MoveAftersRight(ctx context.Context, start, length int64) struct {
	Lefts, Rigths struct {
		Query string
		Args  []interface{}
	}
}

func (DefaultDriver) MoveTreeRight

func (DefaultDriver) MoveTreeRight(ctx context.Context, length, lft, rgt int64) (query string, args []interface{})

func (DefaultDriver) PathOf

func (this DefaultDriver) PathOf(ctx context.Context, id ID) (query string, args []interface{})

func (DefaultDriver) PathToID

func (this DefaultDriver) PathToID(ctx context.Context, pth string) (query string, args []interface{})

func (DefaultDriver) Scheme

func (this DefaultDriver) Scheme() *Scheme

func (DefaultDriver) SelfSubTree

func (DefaultDriver) SelfSubTree(ctx context.Context, root, sub ID) (query string, args []interface{})

func (DefaultDriver) SetParentID

func (this DefaultDriver) SetParentID(ctx context.Context, id, parentID ID) (query string, args []interface{})

func (DefaultDriver) TreeTempSet

func (DefaultDriver) TreeTempSet(ctx context.Context, node *Node, depthDiff *int32) (query string, args []interface{})

func (DefaultDriver) TreeTempUnset

func (DefaultDriver) TreeTempUnset(ctx context.Context, node *Node, newLeft int64, depthDiff *int32) (query string, args []interface{})

func (DefaultDriver) ValueToID

func (DefaultDriver) ValueToID(ctx context.Context, value interface{}) ID

type Driver

type Driver interface {
	FindID(ctx context.Context, lft, rgt int64) (query string, args []interface{})
	Insert(ctx context.Context, node *Node, name string, iargs ...interface{}) (query string, args []interface{})
	Detail(ctx context.Context, id ID) (query string, args []interface{})
	ControlDetail(ctx context.Context, id ID) (query string, args []interface{})
	Delete(ctx context.Context, id ID, lft, rgt int64, iargs ...interface{}) (query string, args []interface{})
	PathOf(ctx context.Context, id ID) (query string, args []interface{})
	PathToID(ctx context.Context, pth string) (query string, args []interface{})
	SelfSubTree(ctx context.Context, root, sub ID) (query string, args []interface{})
	SetParentID(ctx context.Context, id, parentID ID) (query string, args []interface{})
	TreeTempSet(ctx context.Context, node *Node, depthDiff *int32) (query string, args []interface{})
	TreeTempUnset(ctx context.Context, node *Node, newLeft int64, depthDiff *int32) (query string, args []interface{})
	MoveAftersLeft(ctx context.Context, start, length int64) struct {
		Lefts, Rigths struct {
			Query string
			Args  []interface{}
		}
	}
	MoveAftersRight(ctx context.Context, start, length int64) struct {
		Lefts, Rigths struct {
			Query string
			Args  []interface{}
		}
	}
	MaxRight(ctx context.Context) (query string, args []interface{})
	ValueToID(ctx context.Context, nodeId interface{}) ID
	Scheme() *Scheme
	DDL() []string
}

type Epoch

type Epoch time.Time

func (*Epoch) Scan

func (this *Epoch) Scan(src interface{}) (err error)

type ID

type ID interface {
	driver.Valuer
	sql.Scanner
	MustValue() driver.Value
	Raw() interface{}
}

func NewID

func NewID(value interface{}) ID

type Id

type Id struct {
	Valuer  func() (driver.Value, error)
	Scanner func(v interface{}) error
	Rawer   func() interface{}
}

func (Id) MustValue

func (this Id) MustValue() driver.Value

func (Id) Raw

func (this Id) Raw() interface{}

func (Id) Scan

func (this Id) Scan(src interface{}) error

func (Id) Value

func (this Id) Value() (driver.Value, error)

type Nested

type Nested struct {
	TableName string
	Driver    Driver
}

func New

func New(tableName string) *Nested

func (*Nested) DDL

func (this *Nested) DDL() []string

func (*Nested) Delete

func (this *Nested) Delete(ctx context.Context, tx *sql.Tx, recursive bool, id ID, args ...interface{}) (err error)

func (*Nested) DeleteOne

func (this *Nested) DeleteOne(ctx context.Context, tx *sql.Tx, id ID, args ...interface{}) (err error)

func (*Nested) DeleteRecursive

func (this *Nested) DeleteRecursive(ctx context.Context, tx *sql.Tx, id ID, args ...interface{}) (err error)

func (Nested) FindID

func (this Nested) FindID(ctx context.Context, tx *sql.Tx, lft, rgt int64, dst ID) (err error)

func (*Nested) Insert

func (this *Nested) Insert(ctx context.Context, tx *sql.Tx, id, toId ID, name string, args ...interface{}) (node *Node, err error)

func (*Nested) InsertRoot

func (this *Nested) InsertRoot(ctx context.Context, tx *sql.Tx, id ID, name string, args ...interface{}) (node *Node, err error)

func (Nested) MaxRight

func (this Nested) MaxRight(ctx context.Context, tx *sql.Tx) (max int64, err error)

func (*Nested) Move

func (this *Nested) Move(ctx context.Context, tx *sql.Tx, id, toId ID) (err error)

func (*Nested) MoveToRoot

func (this *Nested) MoveToRoot(ctx context.Context, tx *sql.Tx, id ID) (err error)

func (Nested) Node

func (this Nested) Node(ctx context.Context, tx *sql.Tx, id ID) (n *Node, err error)

func (*Nested) PathOf

func (this *Nested) PathOf(ctx context.Context, tx *sql.Tx, id ID) (pth string, err error)

func (*Nested) PathToID

func (this *Nested) PathToID(ctx context.Context, tx *sql.Tx, pth string, id ID) (err error)

func (Nested) Q

func (this Nested) Q(query string) string

func (Nested) Setup

func (this Nested) Setup(ctx context.Context, db *sql.DB) (err error)

type Node

type Node struct {
	ID, ParentID ID
	Lft, Rgt     int64
	Depth        int32
	Path         string
	DenyChindren bool
}

type Scheme

type Scheme struct {
	Columns SchemeColumns
	Indexes SchemeIndexes
}

func (Scheme) DDL

func (this Scheme) DDL() []string

type SchemeColumn

type SchemeColumn struct {
	Name       string
	Definition string
}

func (SchemeColumn) DDL

func (this SchemeColumn) DDL(s Scheme) (r string)

type SchemeColumns

type SchemeColumns struct {
	ID,
	Lft,
	Rgt,
	Name,
	Depth,
	ParentID,
	DenyChildren SchemeColumn
	Other map[string]string
}

func (SchemeColumns) DDL

func (this SchemeColumns) DDL(s Scheme) (r []string)

type SchemeIndex

type SchemeIndex struct {
	Name        string
	Definition  func(s Scheme, i SchemeIndex) string
	Columns     []string
	ColumnsFunc func(s Scheme, i SchemeIndex) []string
	Unique      bool
}

func (SchemeIndex) DDL

func (this SchemeIndex) DDL(s Scheme) (r string)

type SchemeIndexes

type SchemeIndexes []SchemeIndex

func (SchemeIndexes) DDL

func (this SchemeIndexes) DDL(s Scheme) (r []string)

type SelectOptions

type SelectOptions struct {
	Args    []interface{}
	Scanner scanner.Scanner
	Columns []string
	Order   []struct {
		Name string
		Asc  bool
	}
	Limit, Offset int
}

func (SelectOptions) Arg

func (this SelectOptions) Arg(args ...interface{}) SelectOptions

func (SelectOptions) Asc

func (this SelectOptions) Asc(v string) SelectOptions

func (SelectOptions) Desc

func (this SelectOptions) Desc(v string) SelectOptions

func (SelectOptions) Lim

func (this SelectOptions) Lim(limit int) SelectOptions

func (SelectOptions) Off

func (this SelectOptions) Off(offset int) SelectOptions

func (SelectOptions) Scaner

func (this SelectOptions) Scaner(s scanner.Scanner) SelectOptions

func (SelectOptions) Select

func (this SelectOptions) Select(column ...string) SelectOptions

Jump to

Keyboard shortcuts

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