Home Products Documentation

Author note: This example is not yet implemented and showcases where we're envisioning the syntax of the SQL to go

-- LSD has two fundamental pieces of syntax,
-- identifiers and blocks. Blocks define the values
-- that correspond with a given identifier. A block
-- can be used to refer to a value as shown below
some_number <| 123 |
some_string <| "foo" |
some_atom <| wowza |
some_css_selector <| body h1 |

-- Using identifiers can be helpful for aliasing CSS
math_topic <| a#search-math |
adv_search <| a[href="/search/advanced"] |
search_button <| button.button.is-medium |
article_container <| p.list-title span |
pdf_link <| a:nth-child(1) |
next_page_button <| a.pagination-next |

-- A block can also be used to define a query
-- result that gets assigned to an identifier
first_page_results <|
FROM https://arxiv.org
|> CLICK ON math_topic
|> CLICK ON adv_search
|> CLICK ON search_button
|> SELECT pdf_link
|> GROUP BY article_container |

-- An identifier can derive from another one like
-- starting from first_page_results
second_page_results <|
FROM first_page_results
|> CLICK ON next_page_button
|> SELECT pdf_link
|> GROUP BY article_container |

-- A block starting with a <|> is a short hand for a
-- function. Similar to how python class methods
-- implicitly have self as a first argument to a
-- function, functions in LSD implicitly take on the
-- context of the SQL block leading up to its
-- invocation as a first argument
dive_into_arxiv <|> starting_page <|
FROM starting_page
|> CLICK ON next_page_button
|> SELECT pdf_link
|> GROUP BY article_container
|> WHEN EXISTS next_page_button
     THEN dive_into_arxiv
     ELSE SELECT pdf_link |

-- To provide additional arguments just separate
-- identifiers with spaces
function_with_arg <|> starting_page text_to_type <|
FROM starting_page
|> ENTER INTO input#search-bar text_to_type
|> CLICK ON button#search |

-- Without establishing a block, this is presumed
-- to be the result of interest
FROM second_page_results
|> dive_into_arxiv second_page_results