Class DataSourceSpec
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
데이터소스사양
기존 데이터 소스 사양의 일반 설정에 액세스합니다. 특정 유형의 데이터 소스 사양에 액세스하려면 as...()
메서드를 사용하세요. 새 데이터 소스 사양을 만들려면 SpreadsheetApp.newDataSourceSpec()
를 사용하세요.
이 클래스는 데이터베이스에 연결된 데이터에만 사용합니다.
이 예에서는 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());
}
이 예에서는 Looker 데이터 소스 사양에서 정보를 가져오는 방법을 보여줍니다. asLooker()
를 사용하면 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());
}
자세한 문서
asLooker()
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();
리턴
LookerDataSourceSpec
: Looker 데이터 소스 사양입니다.
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
: 데이터 소스 유형입니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[null,null,["최종 업데이트: 2025-07-26(UTC)"],[[["\u003cp\u003e\u003ccode\u003eDataSourceSpec\u003c/code\u003e provides access to the general settings of an existing database-connected data source.\u003c/p\u003e\n"],["\u003cp\u003eTo access type-specific settings, utilize the \u003ccode\u003eas...()\u003c/code\u003e methods (e.g., \u003ccode\u003easBigQuery()\u003c/code\u003e, \u003ccode\u003easLooker()\u003c/code\u003e).\u003c/p\u003e\n"],["\u003cp\u003eYou can create a new data source specification using \u003ccode\u003eSpreadsheetApp.newDataSourceSpec()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ecopy()\u003c/code\u003e method facilitates creating a \u003ccode\u003eDataSourceSpecBuilder\u003c/code\u003e to modify existing settings.\u003c/p\u003e\n"],["\u003cp\u003eMethods like \u003ccode\u003egetParameters()\u003c/code\u003e and \u003ccode\u003egetType()\u003c/code\u003e allow retrieval of data source parameters and type respectively.\u003c/p\u003e\n"]]],["`DataSourceSpec` accesses settings of existing data sources connected to databases. Use `as...()` to access specific types, like `asBigQuery()` or `asLooker()`. Key actions include: retrieving data source type with `getType()`, fetching parameters via `getParameters()`, and creating a modifiable copy using `copy()`. For example, retrieve BigQuery project ID and raw query string, or get a Looker instance URL. This class can not be used with new data source, use `SpreadsheetApp.newDataSourceSpec()` instead.\n"],null,["# Class DataSourceSpec\n\nDataSourceSpec\n\nAccess the general settings of an existing data source spec. To access data source spec for\ncertain type, use `as...()` method. To create a new data source spec, use [SpreadsheetApp.newDataSourceSpec()](/apps-script/reference/spreadsheet/spreadsheet-app#newDataSourceSpec()).\n\n\n**Only use this class with data that's connected to a database.**\n\n\nThis example shows how to get information from a BigQuery data source spec.\n\n```javascript\nconst dataSourceTable = SpreadsheetApp.getActive()\n .getSheetByName('Data Sheet 1')\n .getDataSourceTables()[0];\nconst spec = dataSourceTable.getDataSource().getSpec();\nif (spec.getType() === SpreadsheetApp.DataSourceType.BIGQUERY) {\n const bqSpec = spec.asBigQuery();\n Logger.log('Project ID: %s\\n', bqSpec.getProjectId());\n Logger.log('Raw query string: %s\\n', bqSpec.getRawQuery());\n}\n```\n\nThis example shows how to get information from a Looker data source spec. Using `as``Looker()` returns a [LookerDataSourceSpec](/apps-script/reference/spreadsheet/looker-data-source-spec) object.\n\n```javascript\n// TODO(developer): Replace the URL with your own.\nconst ss = SpreadsheetApp.openByUrl(\n 'https://docs.google.com/spreadsheets/d/abc123456/edit',\n);\nconst spec = ss.getDataSources()[0].getSpec().asLooker();\n\nif (spec.getType() === SpreadsheetApp.DataSourceType.LOOKER) {\n const lookerSpec = spec.asLooker();\n Logger.log('Looker instance URL: %s\\n', lookerSpec.getInstanceUrl());\n}\n``` \n\n### Methods\n\n| Method | Return type | Brief description |\n|-------------------------------------|-----------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|\n| [asBigQuery()](#asBigQuery()) | [BigQueryDataSourceSpec](/apps-script/reference/spreadsheet/big-query-data-source-spec) | Gets the spec for BigQuery data source. |\n| [asLooker()](#asLooker()) | [LookerDataSourceSpec](/apps-script/reference/spreadsheet/looker-data-source-spec) | Gets the spec for Looker data source. |\n| [copy()](#copy()) | [DataSourceSpecBuilder](/apps-script/reference/spreadsheet/data-source-spec-builder) | Creates a [DataSourceSpecBuilder](/apps-script/reference/spreadsheet/data-source-spec-builder) based on this data source's settings. |\n| [getParameters()](#getParameters()) | [DataSourceParameter[]](/apps-script/reference/spreadsheet/data-source-parameter) | Gets the parameters of the data source. |\n| [getType()](#getType()) | [DataSourceType](/apps-script/reference/spreadsheet/data-source-type) | Gets the type of the data source. |\n\nDetailed documentation\n----------------------\n\n### `as``Big``Query()`\n\nGets the spec for BigQuery data source.\n\n#### Return\n\n\n[BigQueryDataSourceSpec](/apps-script/reference/spreadsheet/big-query-data-source-spec) --- The BigQuery data source spec.\n\n*** ** * ** ***\n\n### `as``Looker()`\n\nGets the spec for Looker data source.\n\n```javascript\n// TODO(developer): Replace the URL with your own.\nconst ss = SpreadsheetApp.openByUrl(\n 'https://docs.google.com/spreadsheets/d/abc123456/edit',\n);\nconst spec = ss.getDataSources()[0].getSpec().asLooker();\n```\n\n#### Return\n\n\n[LookerDataSourceSpec](/apps-script/reference/spreadsheet/looker-data-source-spec) --- The Looker data source spec.\n\n*** ** * ** ***\n\n### `copy()`\n\nCreates a [DataSourceSpecBuilder](/apps-script/reference/spreadsheet/data-source-spec-builder) based on this data source's settings.\n\n```javascript\n// TODO(developer): Replace the URL with your own.\nconst ss = SpreadsheetApp.openByUrl(\n 'https://docs.google.com/spreadsheets/d/abc123456/edit',\n);\nconst spec = ss.getDataSources()[0].getSpec();\n\nconst newSpec = spec.copy();\n```\n\n#### Return\n\n\n[DataSourceSpecBuilder](/apps-script/reference/spreadsheet/data-source-spec-builder) --- The builder.\n\n*** ** * ** ***\n\n### `get``Parameters()`\n\nGets the parameters of the data source.\n\n```javascript\n// TODO(developer): Replace the URL with your own.\nconst ss = SpreadsheetApp.openByUrl(\n 'https://docs.google.com/spreadsheets/d/abc123456/edit',\n);\nconst spec = ss.getDataSources()[0].getSpec();\nconst parameters = spec.getParameters();\n```\n\nThis method is only available for BigQuery data sources.\n\n#### Return\n\n\n[DataSourceParameter[]](/apps-script/reference/spreadsheet/data-source-parameter) --- The parameter list.\n\n*** ** * ** ***\n\n### `get``Type()`\n\nGets the type of the data source.\n\n```javascript\n// TODO(developer): Replace the URL with your own.\nconst ss = SpreadsheetApp.openByUrl(\n 'https://docs.google.com/spreadsheets/d/abc123456/edit',\n);\nconst spec = ss.getDataSources()[0].getSpec();\nconst type = spec.getType();\n```\n\n#### Return\n\n\n[DataSourceType](/apps-script/reference/spreadsheet/data-source-type) --- The data source type."]]