Documentation ¶
Index ¶
- Variables
- func Compare(a HierarchyIdData, b HierarchyIdData) int
- func Encode(levels HierarchyIdData) ([]byte, error)
- func IsDescendantOf(child HierarchyIdData, parent HierarchyIdData) bool
- func ToString(data HierarchyIdData) string
- type HierarchyId
- func (j *HierarchyId) GetAncestor() HierarchyId
- func (j *HierarchyId) GetAncestors() []HierarchyId
- func (j *HierarchyId) GetLevel() int
- func (j *HierarchyId) GetReparentedValue(oldAncestor HierarchyId, newAncestor HierarchyId) HierarchyId
- func (HierarchyId) GormDBDataType(db *gorm.DB, field *schema.Field) string
- func (HierarchyId) GormDataType() string
- func (j *HierarchyId) IsDescendantOf(parent HierarchyId) bool
- func (j HierarchyId) MarshalJSON() ([]byte, error)
- func (j *HierarchyId) Scan(src any) error
- func (j *HierarchyId) ToString() string
- func (j *HierarchyId) UnmarshalJSON(data []byte) error
- func (j HierarchyId) Value() (driver.Value, error)
- type HierarchyIdData
- type HierarchyIdPattern
Constants ¶
This section is empty.
Variables ¶
var Patterns = []HierarchyIdPattern{
{-281479271682120, -4294971465, "000100xxxxxxxxxxxxxx0xxxxxxxxxxxxxxxxxxxxx0xxxxxx0xxx0x1xxxT"},
{4294972496, 281479271683151, "111111xxxxxxxxxxxxxx0xxxxxxxxxxxxxxxxxxxxx0xxxxxx0xxx0x1xxxT"},
{-4294971464, -4169, "000101xxxxxxxxxxxxxxxxxxx0xxxxxx0xxx0x1xxxT"},
{5200, 4294972495, "111110xxxxxxxxxxxxxxxxxxx0xxxxxx0xxx0x1xxxT"},
{-4168, -73, "000110xxxxx0xxx0x1xxxT"},
{1104, 5199, "11110xxxxx0xxx0x1xxxT"},
{80, 1103, "1110xxx0xxx0x1xxxT"},
{-72, -9, "0010xx0x1xxxT"},
{16, 79, "110xx0x1xxxT"},
{-8, -1, "00111xxxT"},
{8, 15, "101xxxT"},
{4, 7, "100xxT"},
{0, 3, "01xxT"},
}
List of possible patterns for hierarchyid values.
Sorted from the largest to the smallest.
Functions ¶
func Compare ¶
func Compare(a HierarchyIdData, b HierarchyIdData) int
Compare two hierarchyid data types
The comparison is done by comparing each level of the hierarchyid. If the levels are the same, the next level is compared. If the levels are different, the comparison stops and the result is returned.
func Encode ¶
func Encode(levels HierarchyIdData) ([]byte, error)
Encode a hierarchyid from hierarchyid.
func IsDescendantOf ¶
func IsDescendantOf(child HierarchyIdData, parent HierarchyIdData) bool
Check if a hierarchyid is a descendant of another hierarchyid
func ToString ¶
func ToString(data HierarchyIdData) string
Create a string representation of the hierarchyid data type
The string representation is a series of integers separated by slashes. For example, \1\2\3\
Types ¶
type HierarchyId ¶
type HierarchyId struct { // Path of the hierarchy (e.g "/1/2/3/4/") Data HierarchyIdData }
HierarchyId is a structure to represent database hierarchy ids.
func GetRoot ¶
func GetRoot() HierarchyId
Get the root of the tree '\'.
The root is the hierarchyid with an empty path.
func (*HierarchyId) GetAncestor ¶
func (j *HierarchyId) GetAncestor() HierarchyId
Get the direct parent of a hierarchyid.
func (*HierarchyId) GetAncestors ¶
func (j *HierarchyId) GetAncestors() []HierarchyId
Get all ancestors of a hierarchyid.
E.g. '/1/2/3/4/' will return ['/1/', '/1/2/', '/1/2/3/']
func (*HierarchyId) GetLevel ¶
func (j *HierarchyId) GetLevel() int
Get the tree level where this hierarchyid is located.
'/1/2/3/4/' is at level 4, '/1/2/3/' is at level 3, etc.
func (*HierarchyId) GetReparentedValue ¶
func (j *HierarchyId) GetReparentedValue(oldAncestor HierarchyId, newAncestor HierarchyId) HierarchyId
Calculate a new hierarchyid when moving from a parent to another parent in the tree.
The position will be calculated based on the old and new parents.
E.g. if the element is on position '/1/2/57/8/' old parents is '/1/2/' and new parent is '/1/3/' the new position will be '/1/3/57/8/'
func (HierarchyId) GormDBDataType ¶
GormDBDataTypeInterface defines the data type to apply in the database.
func (HierarchyId) GormDataType ¶
func (HierarchyId) GormDataType() string
GormDataTypeInterface to specify the nema of data type.
func (*HierarchyId) IsDescendantOf ¶
func (j *HierarchyId) IsDescendantOf(parent HierarchyId) bool
Check if a hierarchyid is a descendant of another hierarchyid
func (HierarchyId) MarshalJSON ¶
func (j HierarchyId) MarshalJSON() ([]byte, error)
When marshaling to JSON, we want the field formatted as a string.
func (*HierarchyId) Scan ¶
func (j *HierarchyId) Scan(src any) error
Scan implements the sql.Scanner interface.
Used to read the value provided by the SQL server.
func (*HierarchyId) ToString ¶
func (j *HierarchyId) ToString() string
Create a string representation of the hierarchyid data type
func (*HierarchyId) UnmarshalJSON ¶
func (j *HierarchyId) UnmarshalJSON(data []byte) error
When unmarshaling from JSON, we want to parse the string into the field.
type HierarchyIdData ¶
type HierarchyIdData = []int64
HierarchyIdData is a type to represent a hierarchyid data type from SQL Server
The hierarchyid data type is a series of integers separated by slashes. For example, \1\2\3\.
func Decode ¶
func Decode(data []byte) (HierarchyIdData, error)
Decode takes a byte slice of data stored in SQL Server hierarchyid format and returns a HierarchyId.
SQL server uses a custom binary format for hierarchyid.
func FromString ¶
func FromString(data string) (HierarchyIdData, error)
Create a hierarchyid data type from a string representation
func GetAncestor ¶
func GetAncestor(data HierarchyIdData) HierarchyIdData
Get the direct ancestor of a hierarchyid.
func GetAncestors ¶
func GetAncestors(data HierarchyIdData) []HierarchyIdData
Get all ancestors (parents) of a hierarchyid.
type HierarchyIdPattern ¶
type HierarchyIdPattern struct { // Minimum value Min int64 // Maximum value Max int64 // Pattern structure (0 and 1 are fixed}, x corresponds to the value and T is the terminator. Pattern string }
Represents a possible pattern for hierarchyid values.
The structure used to store the values, changes based on the value size. These patterns codify the possible structures based on value size.