xdbutils_orderby

package
v0.0.0-...-587cc14 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: MIT Imports: 1 Imported by: 1

README

xdbutils_orderby

Dependencies

  • None

Documents

Types
  • type PropertyValue struct
  • type PropertyDict map
  • type OrderByOption func
Variables
  • None
Constants
  • None
Functions
  • func NewPropertyValue(reverse bool, destinations ...string) *PropertyValue
  • func WithSourceSeparator(separator string) OrderByOption
  • func WithTargetSeparator(separator string) OrderByOption
  • func WithSourceProcessor(processor func(source string) (field string, asc bool)) OrderByOption
  • func WithTargetProcessor(processor func(destination string, asc bool) (target string)) OrderByOption
  • func GenerateOrderByExpr(querySource string, dict PropertyDict, options ...OrderByOption) string
Methods
  • None

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateOrderByExpr

func GenerateOrderByExpr(querySource string, dict PropertyDict, options ...OrderByOption) string

GenerateOrderByExpr returns a generated order-by expression by given order-by query source string (such as "name desc, age asc") and PropertyDict, with some OrderByOption-s. The generated expression will be in mysql-sql (such as "xxx ASC") or neo4j-cypher style (such as "xxx.yyy DESC").

SQL Example:

dict := PropertyDict{
	"uid":  NewPropertyValue(false, "uid"),
	"name": NewPropertyValue(false, "firstname", "lastname"),
	"age":  NewPropertyValue(true, "birthday"),
}
_ = GenerateOrderByExpr(`uid, age desc`, dict) // => uid ASC, birthday ASC
_ = GenerateOrderByExpr(`age, username desc`, dict) // => birthday DESC, firstname DESC, lastname DESC

Cypher Example:

dict := PropertyDict{
	"uid":  NewPropertyValue(false, "p.uid"),
	"name": NewPropertyValue(false, "p.firstname", "p.lastname"),
	"age":  NewPropertyValue(true, "u.birthday"),
}
_ = GenerateOrderByExpr(`uid, age desc`, dict) // => p.uid ASC, u.birthday ASC
_ = GenerateOrderByExpr(`age, username desc`, dict) // => u.birthday DESC, p.firstname DESC, p.lastname DESC

Types

type OrderByOption

type OrderByOption func(*orderByOptions)

OrderByOption represents an option type for GenerateOrderByExpr's option, can be created by WithXXX functions.

func WithSourceProcessor

func WithSourceProcessor(processor func(source string) (field string, asc bool)) OrderByOption

WithSourceProcessor creates an OrderByOption to specify the source processor for extracting field name and ascending flag from given source, defaults to use the "field asc" or "field desc" format (case-insensitive) to extract information.

func WithSourceSeparator

func WithSourceSeparator(separator string) OrderByOption

WithSourceSeparator creates an OrderByOption to specify the source order-by expression fields separator, defaults to ",".

func WithTargetProcessor

func WithTargetProcessor(processor func(destination string, asc bool) (target string)) OrderByOption

WithTargetProcessor creates an OrderByOption to specify the target processor for combining field name and ascending flag to target expression, defaults to generate the target with "destination ASC" or "destination DESC" format.

func WithTargetSeparator

func WithTargetSeparator(separator string) OrderByOption

WithTargetSeparator creates an OrderByOption to specify the target order-by expression fields separator, defaults to ", ".

type PropertyDict

type PropertyDict map[string]*PropertyValue

PropertyDict is used to store PropertyValue-s for data transfer object (dto) to entity's property mapping rule, is used in GenerateOrderByExpr.

type PropertyValue

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

PropertyValue represents database single entity's property mapping rule, is used in GenerateOrderByExpr.

func NewPropertyValue

func NewPropertyValue(reverse bool, destinations ...string) *PropertyValue

NewPropertyValue creates a PropertyValue by given reverse and destinations, is used to describe database single entity's property mapping rule.

Here: 1. `destinations` represents mapping property destination list, use `property_name` directly for sql, use `returned_name.property_name` for cypher. 2. `reverse` represents the flag whether you need to revert the order or not.

func (*PropertyValue) Destinations

func (p *PropertyValue) Destinations() []string

Destinations returns the destinations of PropertyValue.

func (*PropertyValue) Reverse

func (p *PropertyValue) Reverse() bool

Reverse returns the reverse flag of PropertyValue.

Jump to

Keyboard shortcuts

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