From: Ardis Lu Date: Fri, 27 Aug 2021 03:49:46 +0000 (-0700) Subject: Use PropertiesService for FILE_ID master data X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=f246edec7328974dd1dedd8bd489c67963ec0df1;p=sheets-db Use PropertiesService for FILE_ID master data --- diff --git a/Code.gs b/Code.gs index 64a2fb9..092658b 100644 --- a/Code.gs +++ b/Code.gs @@ -1,6 +1,8 @@ const UI = SpreadsheetApp.getUi(); const WORKBOOK = SpreadsheetApp.getActive(); +const FILE_ID = PropertiesService.getScriptProperties().getProperty('FILE_ID'); + function onOpen() { const ui = SpreadsheetApp.getUi(); ui.createMenu('SQLite') @@ -39,7 +41,6 @@ function generateDatabaseQuery() { */ const sheets = WORKBOOK.getSheets(); - const fileId = '1xUrGGbaQLVRnytUKtnINAxzild0PBeJZ'; // Google Drive file ID to store the final SQL query /** Construct SQL for creating the database */ let query = `-- This query was generated by sheets-db @@ -100,7 +101,7 @@ function generateDatabaseQuery() { // URL to download the file: // https://drive.google.com/u/0/uc?id=1xUrGGbaQLVRnytUKtnINAxzild0PBeJZ&export=download - DriveApp.getFileById(fileId).setContent(query); + DriveApp.getFileById(FILE_ID).setContent(query); - UI.alert('Success!', `Query generated! Download here: https://drive.google.com/u/0/uc?id=${fileId}&export=download`, ui.ButtonSet.OK); + UI.alert('Success!', `Query generated! Download here: https://drive.google.com/u/0/uc?id=${FILE_ID}&export=download`, ui.ButtonSet.OK); } diff --git a/README.md b/README.md index d4bdf82..7a40cff 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ These steps only need to be completed once. 3. Create a new Google Sheet or create a copy of the [demo Google Sheet](https://docs.google.com/spreadsheets/d/1pY-0oDh4pI8NffZQwN-AkpfJdot7bmlM9nky7w150UY/edit?usp=sharing). 4. Go to Tools > Script Editor to create a new Google Apps Script (GAS) project. The GAS project is automatically attached to the Google Sheet. 5. Copy `Code.gs` into the GAS project and save. If you copied the demo Google Sheet, this code should already be there. -6. **(IMPORTANT)** In `Code.gs`, update the hardcoded constant `fileId` to the file ID noted in Step 2. +6. **(IMPORTANT)** In `Code.gs`, there is a reference to a [Google Apps Script property](https://developers.google.com/apps-script/guides/properties) (environment variable) named `FILE_ID`. Use the GAS user interface to set `FILE_ID` to the file ID noted in Step 2. # Usage