File: README.md

package info (click to toggle)
golang-github-viant-toolbox 0.33.2-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,280 kB
  • sloc: makefile: 16
file content (71 lines) | stat: -rw-r--r-- 2,004 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Expandable Collection User Defined Function

### Usage


#### Data substitution

```go

    aMap := data.NewMap();
    aMap.Put("ts", "2015-02-11")
    udf.Register(aMap)
    expanded := aMap.ExpandAsText(`$FormatTime($ts, "yyyy")`)
 
```
#### Data node selection


```go

	holder := data.NewMap()
    collection := data.NewCollection()
    collection.Push(map[string]interface{}{
        "amount": 2,
        "id":2,
        "name":"p1",
        "vendor":"v1",
    })
    collection.Push(map[string]interface{}{
        "amount": 12,
        "id":3,
        "name":"p2",
        "vendor":"v2",
    })
    holder.SetValue("node1.obj", collection)

	records, err := Select([]interface{}{"node1/obj/*", "id", "name:product"}, holder)


```

#### The list of defined UDFs

-  Length, Len returns length of slice, map or string
-  AsMap - convert source into a map, it accepts data structure, or JSON, YAML literal
-  AsCollection - convert source into a slice, it accepts data structure, or JSON, YAML literal
-  AsData - convert source into a map or slice, it accepts data structure, or JSON, YAML literal
-  AsInt - convert source into a an int
-  AsFloat - convert source into a a float
-  AsBool  - convert source into a boolean
-  AsNumber - converts to either int or float
-  FormatTime, takes two arguments, date or now, followed by java style date format
-  Values - returns map values
-  Keys  - return map keys
-  IndexOf - returns index of matched slice element
-  Join - join slice element with supplied separator
-  Split - split text by separator
-  Sum - sums values for matched Path, i.e. $Sum('node1/obj/*/amount')
-  Count - counts values for matched Path, i.e. $Sum('node1/obj/*/amount')
-  Select - selects attribute for matched path, i.e $Select("node1/obj/*", "id", "name:product")
-  QueryEscape - url escape
-  QueryUnescape - url unescape
-  Base64Encode
-  Base64DecodeText
-  TrimSpace
-  Elapsed elapsed time  
-  Rand
-  Replace
-  ToLower
-  ToUpper
-  AsNewLineDelimitedJSON