Created
January 20, 2023 12:14
-
-
Save gargomoma/808bfd72ef03ddc14db48bc60cf3cc72 to your computer and use it in GitHub Desktop.
setBQDataSource is a GappS function to build/update your Big Query connections.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///////////////////////////////////////////////////////////////////////////////// | |
//setBQDataSource is a GappS function to build/update your Big Query connections. | |
//Ideal if you need to update or create multiple connections, making mantainers life easier. | |
//Imagination, life is your creation! | |
///////////////////////////////////////////////////////////////////////////////// | |
function setBQDataSource(ProjID,Query,SheetName,refreshAllLinkedObjects=true) { | |
SpreadsheetApp.enableBigQueryExecution(); //.enableAllDataSourcesExecution(); | |
/////////////// | |
var ss = SpreadsheetApp.getActive(); | |
/////////////// | |
var dataSourceSpec = SpreadsheetApp.newDataSourceSpec() | |
.asBigQuery() | |
.setProjectId( ProjID ) | |
.setRawQuery( Query ) | |
.build(); | |
/////////////// | |
var sheet_data = ss.getSheetByName( SheetName ); | |
if (!sheet_data){ | |
Logger.log(`Sheet ${SheetName} didn't exist: Creating Sheet.`) | |
ss.insertDataSourceSheet(dataSourceSpec).asSheet().setName( SheetName ); | |
} else { | |
Logger.log(`Sheet ${SheetName} did exist: Updating DataSource.`) | |
sheet_data.asDataSourceSheet().getDataSource().updateSpec(dataSourceSpec,refreshAllLinkedObjects); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment