เครื่องมือสร้างสำหรับ DataSourceSpec หากต้องการสร้างข้อกำหนดสำหรับประเภทหนึ่งๆ ให้ใช้วิธี as...() หากต้องการสร้างเครื่องมือสร้างใหม่ ให้ใช้ SpreadsheetApp.newDataSourceSpec() หากต้องการใช้ข้อกำหนด โปรดดู DataSourceTable
ใช้คลาสนี้กับข้อมูลที่เชื่อมต่อกับฐานข้อมูลเท่านั้น
ตัวอย่างนี้แสดงวิธีสร้างข้อกําหนดแหล่งข้อมูล BigQuery
const spec = SpreadsheetApp.newDataSourceSpec() .asBigQuery() .setProjectId('big_query_project') .setRawQuery('select @FIELD from table limit @LIMIT') .setParameterFromCell('FIELD', 'Sheet1!A1') .setParameterFromCell('LIMIT', 'namedRangeCell') .build();
ตัวอย่างนี้แสดงวิธีสร้างข้อกำหนดแหล่งข้อมูล Looker โดยจะแสดงผลออบเจ็กต์ LookerDataSourceSpec หลังจากใช้ build()
const spec = SpreadsheetApp.newDataSourceSpec() .asLooker() .setInstanceUrl('https://looker_instance_url.com') .setModelName('model_name') .setExploreName('explore_name') .build();
เมธอด
| วิธีการ | ประเภทการแสดงผล | รายละเอียดแบบย่อ |
|---|---|---|
as | Big | รับเครื่องมือสร้างสำหรับแหล่งข้อมูล BigQuery |
as | Looker | รับเครื่องมือสร้างสำหรับแหล่งข้อมูล Looker |
build() | Data | สร้างข้อกำหนดของแหล่งข้อมูลจากการตั้งค่าในเครื่องมือสร้างนี้ |
copy() | Data | สร้างDataตามการตั้งค่าของแหล่งข้อมูลนี้ |
get | Data | รับพารามิเตอร์ของแหล่งข้อมูล |
get | Data | รับประเภทของแหล่งข้อมูล |
remove | Data | นำพารามิเตอร์ทั้งหมดออก |
remove | Data | นำพารามิเตอร์ที่ระบุออก |
set | Data | เพิ่มพารามิเตอร์ หรือหากมีพารามิเตอร์ที่มีชื่ออยู่แล้ว ให้อัปเดตเซลล์แหล่งที่มาสำหรับเครื่องมือสร้างข้อกำหนดแหล่งข้อมูลประเภท Data |
เอกสารโดยละเอียด
asBigQuery()
รับเครื่องมือสร้างสำหรับแหล่งข้อมูล BigQuery
รีเทิร์น
BigQueryDataSourceSpecBuilder — เครื่องมือสร้างข้อกำหนดแหล่งข้อมูล BigQuery
asLooker()
รับเครื่องมือสร้างสำหรับแหล่งข้อมูล Looker
const spec = SpreadsheetApp.newDataSourceSpec() .asLooker() .setInstanceUrl('https://looker_instance_url.com') .setModelName('model_name') .setExploreName('explore_name') .build();
รีเทิร์น
LookerDataSourceSpecBuilder - ตัวสร้างข้อกำหนดของแหล่งข้อมูล Looker
build()
สร้างข้อกำหนดของแหล่งข้อมูลจากการตั้งค่าในเครื่องมือสร้างนี้ ต้องใช้ as...()
เพื่อระบุประเภทแหล่งข้อมูลก่อนสร้าง
ตัวอย่างโค้ดต่อไปนี้สร้างข้อกำหนด DataSource ของ BigQuery
const bigQueryDataSourceSpec = SpreadsheetApp.newDataSourceSpec().asBigQuery(); // TODO(developer): Replace with the required dataset, project and table IDs. bigQueryDataSourceSpec.setDatasetId('my data set id'); bigQueryDataSourceSpec.setProjectId('my project id'); bigQueryDataSourceSpec.setTableId('my table id'); bigQueryDataSourceSpec.build();
ตัวอย่างโค้ดต่อไปนี้สร้าง Looker DataSource Spec
const lookerDataSourceSpecBuilder = SpreadsheetApp.newDataSourceSpec().asLooker(); const lookerSpec = lookerDataSourceSpecBuilder.setExploreName('my explore name') .setInstanceUrl('my instance url') .setModelName('my model name') .build();
รีเทิร์น
DataSourceSpec - ข้อกำหนดของแหล่งข้อมูล
copy()
สร้างDataSourceSpecBuilderตามการตั้งค่าของแหล่งข้อมูลนี้
// TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); const spec = ss.getDataSources()[0].getSpec(); const newSpec = spec.copy();
รีเทิร์น
DataSourceSpecBuilder - เครื่องมือสร้าง
getParameters()
รับพารามิเตอร์ของแหล่งข้อมูล
// TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); const spec = ss.getDataSources()[0].getSpec(); const parameters = spec.getParameters();
วิธีนี้ใช้ได้กับแหล่งข้อมูล BigQuery เท่านั้น
รีเทิร์น
DataSourceParameter[] — รายการพารามิเตอร์
getType()
รับประเภทของแหล่งข้อมูล
// TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); const spec = ss.getDataSources()[0].getSpec(); const type = spec.getType();
รีเทิร์น
DataSourceType — ประเภทแหล่งข้อมูล
removeAllParameters()
นำพารามิเตอร์ทั้งหมดออก
const specBuilder = SpreadsheetApp.newDataSourceSpec(); specBuilder.removeAllParameters();
รีเทิร์น
DataSourceSpecBuilder — ตัวสร้างสำหรับการเชื่อมโยง
removeParameter(parameterName)
นำพารามิเตอร์ที่ระบุออก
const specBuilder = SpreadsheetApp.newDataSourceSpec(); specBuilder.removeParameter('x');
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
parameter | String | ชื่อพารามิเตอร์ที่จะนำออก |
รีเทิร์น
DataSourceSpecBuilder — ตัวสร้างสำหรับการเชื่อมโยง
setParameterFromCell(parameterName, sourceCell)
เพิ่มพารามิเตอร์ หรือหากมีพารามิเตอร์ที่มีชื่ออยู่แล้ว ให้อัปเดตเซลล์แหล่งที่มาสำหรับเครื่องมือสร้างข้อกำหนดแหล่งข้อมูลประเภท DataSourceType.BIGQUERY
วิธีนี้ใช้ได้กับแหล่งข้อมูล BigQuery เท่านั้น
const specBuilder = SpreadsheetApp.newDataSourceSpec().asBigQuery(); specBuilder.setParameterFromCell('x', 'A1'); const bigQuerySpec = specBuilder.build();
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
parameter | String | ชื่อพารามิเตอร์ |
source | String | เซลล์ต้นทางตามที่ระบุในรูปแบบ A1 |
รีเทิร์น
DataSourceSpecBuilder — ตัวสร้างสำหรับการเชื่อมโยง