-
Notifications
You must be signed in to change notification settings - Fork 107
fix: allow IN queries on __key__ #1085
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ad3d2ea
4f0db50
23c3200
d279595
ee08623
72acbf1
258c478
f3ff52f
d91b8bd
6337f63
a9bcc0a
7910b43
f186ee2
3e7f057
c6ac45e
1dcc17f
de1f070
25575ba
8b07e55
40a5e19
cf9105c
a551ebe
8bbc2dc
d68506e
fb9bdf7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ import arrify = require('arrify'); | |
import {Key} from 'readline'; | ||
import {Datastore} from '.'; | ||
import {Entity} from './entity'; | ||
import {EntityFilter, isFilter} from './filter'; | ||
import {EntityFilter, isFilter, AllowedFilterValueType} from './filter'; | ||
import {Transaction} from './transaction'; | ||
import {CallOptions} from 'google-gax'; | ||
import {RunQueryStreamOptions} from '../src/request'; | ||
|
@@ -207,12 +207,20 @@ class Query { | |
* const keyQuery = query.filter('__key__', key); | ||
* ``` | ||
*/ | ||
filter(propertyOrFilter: string | EntityFilter, value?: {} | null): Query; | ||
filter(propertyOrFilter: string, operator: Operator, value: {} | null): Query; | ||
filter( | ||
propertyOrFilter: string | EntityFilter, | ||
operatorOrValue?: Operator, | ||
value?: {} | null | ||
filter(filter: EntityFilter): Query; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My take is that the old signature was buggy and wouldn't catch unsupported calls. So I see this as a bug fix. Also I think the impl could be improved by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will do this in a separate issue: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 to go with a |
||
filter<T extends string>( | ||
property: T, | ||
value: AllowedFilterValueType<T> | ||
): Query; | ||
filter<T extends string>( | ||
property: T, | ||
operator: Operator, | ||
value: AllowedFilterValueType<T> | ||
): Query; | ||
filter<T extends string>( | ||
propertyOrFilter: T | EntityFilter, | ||
operatorOrValue?: Operator | AllowedFilterValueType<T>, | ||
value?: AllowedFilterValueType<T> | ||
): Query { | ||
if (isFilter(propertyOrFilter)) { | ||
this.entityFilters.push(propertyOrFilter); | ||
|
@@ -223,7 +231,7 @@ class Query { | |
); | ||
let operator = operatorOrValue as Operator; | ||
if (arguments.length === 2) { | ||
value = operatorOrValue as {}; | ||
value = operatorOrValue as AllowedFilterValueType<T>; | ||
operator = '='; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does this have to change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggested the fix so I'll answer.
filter.toProto !== undefined
only checks if the object has atoProto
properties (not set toundefined
)It is the case that
EntityFilter
s have atoProto
methods but it is not necessarily the case that an object with atoProto
property is anEntityFilter
.filter instanceof EntityFilter
is the correct check forfilter is EntityFilter
I hope that makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @vicb, both using
instanceof
and avoiding type assertions (filter as EntityFilter
) are recommended in the Google TypeScript Style Guide. LGTM 👍