Skip to content
Mike Cohen edited this page Dec 17, 2020 · 1 revision

Some VQL tips and common patterns.

Selecting a value based on a map

Sometimes we want to get a different value based on, e.g. os platform. The easiest way is to build a lookup map with a dict() and use the get() function to look it up

LET my_info = SELECT * FROM info()
LET MyPath <= get(item=dict(
     linux="/opt/velo",
     windows="C:\\Program Files",
     darwin="/tmp"
   ),
   member=my_info[0].OS, 
   default="I dont know?")

SELECT MyPath FROM scope()

As an alternative you can convert this into a function:

LET GetPath(OS) = get(item=dict(
     linux="/opt/velo",
     windows="C:\\Program Files",
     darwin="/tmp"
   ),
   member=OS, 
   default="I dont know?")

LET my_info = SELECT * FROM info()
SELECT GetPath(OS=my_info[0].OS) AS MyPath FROM scope()