Truy cập vào chế độ cài đặt chung của một thông số nguồn dữ liệu hiện có. Để truy cập vào thông số nguồn dữ liệu cho một số loại nhất định, hãy sử dụng phương thức as...(). Để tạo một quy cách nguồn dữ liệu mới, hãy sử dụng SpreadsheetApp.newDataSourceSpec().
Chỉ sử dụng lớp này với dữ liệu được kết nối với cơ sở dữ liệu.
Ví dụ này cho thấy cách lấy thông tin từ một thông số nguồn dữ liệu BigQuery.
const dataSourceTable = SpreadsheetApp.getActive() .getSheetByName('Data Sheet 1') .getDataSourceTables()[0]; const spec = dataSourceTable.getDataSource().getSpec(); if (spec.getType() === SpreadsheetApp.DataSourceType.BIGQUERY) { const bqSpec = spec.asBigQuery(); Logger.log('Project ID: %s\n', bqSpec.getProjectId()); Logger.log('Raw query string: %s\n', bqSpec.getRawQuery()); }
Ví dụ này cho thấy cách lấy thông tin từ một thông số nguồn dữ liệu Looker. Việc sử dụng asLooker() sẽ trả về một đối tượng LookerDataSourceSpec.
// 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().asLooker(); if (spec.getType() === SpreadsheetApp.DataSourceType.LOOKER) { const lookerSpec = spec.asLooker(); Logger.log('Looker instance URL: %s\n', lookerSpec.getInstanceUrl()); }
Phương thức
| Phương thức | Kiểu dữ liệu trả về | Mô tả ngắn |
|---|---|---|
as | Big | Lấy thông số kỹ thuật cho nguồn dữ liệu BigQuery. |
as | Looker | Lấy thông số kỹ thuật cho nguồn dữ liệu Looker. |
copy() | Data | Tạo một Data dựa trên chế độ cài đặt của nguồn dữ liệu này. |
get | Data | Lấy các thông số của nguồn dữ liệu. |
get | Data | Lấy loại nguồn dữ liệu. |
Tài liệu chi tiết
asBigQuery()
Lấy thông số kỹ thuật cho nguồn dữ liệu BigQuery.
Cầu thủ trả bóng
BigQueryDataSourceSpec – Thông số nguồn dữ liệu BigQuery.
asLooker()
Lấy thông số kỹ thuật cho nguồn dữ liệu Looker.
// 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().asLooker();
Cầu thủ trả bóng
LookerDataSourceSpec – Quy cách nguồn dữ liệu Looker.
copy()
Tạo một DataSourceSpecBuilder dựa trên chế độ cài đặt của nguồn dữ liệu này.
// 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();
Cầu thủ trả bóng
DataSourceSpecBuilder – Trình tạo.
getParameters()
Lấy các thông số của nguồn dữ liệu.
// 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();
Phương thức này chỉ áp dụng cho nguồn dữ liệu BigQuery.
Cầu thủ trả bóng
DataSourceParameter[] – Danh sách tham số.
getType()
Lấy loại nguồn dữ liệu.
// 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();
Cầu thủ trả bóng
DataSourceType – Loại nguồn dữ liệu.