|
| 1 | +// Copyright 2020 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +async function main(file = 'YOUR_FILE_NAME') { |
| 16 | + // [START datastore_admin_entities_import] |
| 17 | + const {Datastore} = require('@google-cloud/datastore'); |
| 18 | + const datastore = new Datastore(); |
| 19 | + |
| 20 | + async function importEntities() { |
| 21 | + /** |
| 22 | + * TODO(developer): Uncomment these variables before running the sample. |
| 23 | + */ |
| 24 | + // const file = 'YOUR_FILE_NAME'; |
| 25 | + |
| 26 | + const [importOperation] = await datastore.import({file}); |
| 27 | + |
| 28 | + // Uncomment to await the results of the operation. |
| 29 | + // await importOperation.promise(); |
| 30 | + |
| 31 | + // Or cancel the operation. |
| 32 | + await importOperation.cancel(); |
| 33 | + |
| 34 | + // You may also choose to include only specific kinds and namespaces. |
| 35 | + const [specificImportOperation] = await datastore.import({ |
| 36 | + file, |
| 37 | + kinds: ['Employee', 'Task'], |
| 38 | + namespaces: ['Company'], |
| 39 | + }); |
| 40 | + |
| 41 | + // Uncomment to await the results of the operation. |
| 42 | + // await specificImportOperation.promise(); |
| 43 | + |
| 44 | + // Or cancel the operation. |
| 45 | + await specificImportOperation.cancel(); |
| 46 | + } |
| 47 | + |
| 48 | + await importEntities(); |
| 49 | + // [END datastore_admin_entities_import] |
| 50 | +} |
| 51 | + |
| 52 | +const args = process.argv.slice(2); |
| 53 | +main(...args).catch(console.error); |
0 commit comments