'Getting data from queryparser

I am attempting to use queryparser to extract table relationships from an SQL query. I can get most of what I need, I'm just having issues unpacking the lists.

library(queryparser)

file <- "select 
  p.name,
  p.age,
  p.hometown,
  c.state,
  c.country,
  n.capitol,
  n.leader
 from person p
   inner join city c
     on  p.hometown = c.name
   inner join nation n
     on c.county = n.name
 where C.country != 'Antarctica' "

query <- parse_query(file, tidyverse = TRUE)
query$from

yields the following lists:

> query$from
$p
person

$c
city

$n
nation

attr(,"join_types")
[1] "inner join" "inner join"
attr(,"join_conditions")
attr(,"join_conditions")[[1]]
p.hometown == c.name

attr(,"join_conditions")[[2]]
c.county == n.name

I would like to have a datafame that has each table name and it's alias, and a second table with the join criteria. What is the easiest way to do this dynamically so that I don't have to adjust code between scanning different scripts?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source