-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* docs: adds OR sample * fixed tests * per linter * exclude IDE stuff * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * remove unneeded stuff * git is hard * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
d14f87e
commit 8eb857d
Showing
6 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ system-test/*key.json | |
.DS_Store | ||
package-lock.json | ||
__pycache__ | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2023 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
// sample-metadata: | ||
// title: Create a union between two filters | ||
// description: Create a union between two filters (logical OR operator) | ||
|
||
async function main() { | ||
// [START datastore_query_filter_or] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const projectId = "your Google Cloud project id"; | ||
|
||
// Imports the Cloud Datastore | ||
const {Datastore, PropertyFilter, or} = require('@google-cloud/datastore'); | ||
|
||
async function queryFilterOr() { | ||
// Instantiate the Datastore | ||
const datastore = new Datastore(); | ||
const query = datastore | ||
.createQuery('Task') | ||
.filter( | ||
or([ | ||
new PropertyFilter('description', '=', 'Buy milk'), | ||
new PropertyFilter('description', '=', 'Feed cats'), | ||
]) | ||
); | ||
|
||
const [entities] = await datastore.runQuery(query); | ||
for (const entity of entities) { | ||
console.log(`Entity found: ${entity['description']}`); | ||
} | ||
} | ||
|
||
await queryFilterOr(); | ||
// [END datastore_query_filter_or] | ||
} | ||
|
||
exports.queryFilterOr = main; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2023 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/* eslint-disable */ | ||
|
||
'use strict'; | ||
|
||
const path = require('path'); | ||
const {assert} = require('chai'); | ||
const {describe, it, after, before} = require('mocha'); | ||
const sinon = require('sinon'); | ||
const {Datastore} = require('@google-cloud/datastore'); | ||
const datastore = new Datastore(); | ||
|
||
const {queryFilterOr} = require('../queryFilterOr'); | ||
let taskKey1, taskKey2; | ||
|
||
describe('Creating a union query', () => { | ||
const stubConsole = function () { | ||
sinon.stub(console, 'error'); | ||
sinon.stub(console, 'log'); | ||
}; | ||
|
||
const restoreConsole = function () { | ||
console.log.restore(); | ||
console.error.restore(); | ||
}; | ||
|
||
beforeEach(stubConsole); | ||
afterEach(restoreConsole); | ||
|
||
before(async () => { | ||
taskKey1 = datastore.key('Task'); | ||
const entity1 = { | ||
key: taskKey1, | ||
data: { | ||
description: 'Buy milk', | ||
}, | ||
}; | ||
|
||
taskKey2 = datastore.key('Task'); | ||
const entity2 = { | ||
key: taskKey2, | ||
data: { | ||
description: 'Feed cats', | ||
}, | ||
}; | ||
|
||
await datastore.upsert(entity1); | ||
await datastore.upsert(entity2); | ||
}); | ||
|
||
after(async () => { | ||
await datastore.delete(taskKey1); | ||
await datastore.delete(taskKey2); | ||
}); | ||
|
||
it('should get a combination of items from the Datastore', async () => { | ||
await queryFilterOr(); | ||
assert.include(console.log.firstCall.args[0], 'Entity'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters