Export metadata on connector datasets

We need to export metadata for all datasets that use certain connectors. Specifically, we have created a large number of datasets using postgresql and bigquery connectors. We need to export (1) the query used for each dataset, (2) the dataset id for each dataset, and (3) the name of each dataset.

I know it is possible to get info on all datasets in an instance with the API, but we need to be able to get the above information for a specific subset of datasets.

Is this possible with the API or otherwise?

Thank you.