4

Is there a working example of using Google Datastore GQL in Node.js?

The examples in the documentation contain a .execute function that doesn't appear to exist.

https://cloud.google.com/datastore/docs/concepts/gql

I therefore tried using the regular callback approach but the GQL statement isn't picked up. I've tried using gql_query and gqlQuery as the resource parameter name but to no avail.

store.datasets.runQuery(
        {
            "resource":
            {
                "gqlQuery":
                {
                    "queryString":"SELECT * from Messages LIMIT 50",
                    "allowLiterals":true
                }
            }

        }, 
        function(err, result, endCursor, apiResponse)
        {
...
    }
Justin Tamblyn
  • 719
  • 8
  • 21
sradforth
  • 2,176
  • 2
  • 23
  • 37
  • May I ask if you have figured this one out? – Justin Tamblyn Dec 12 '16 at 05:06
  • 1
    Yes, GQL is usually the wrong approach. It's incredibly limited and has syntatic nuances that aren't obvious IMHO. I ended up using the datastore API library as it was much easier and more understandable behaviour. – sradforth Dec 12 '16 at 16:05
  • Thanks! I was excited about the possibility of generated queries (like an ORM). – Justin Tamblyn Dec 13 '16 at 08:27
  • @sradforth I don't understand how can you say that GQL is limited over Datastore API. As simple thing as 'or' operator is not supported in Datastore API....another one is that default indexing does not allow for querying with multiple filters where there is an inequality operator... – korzeniow Jun 04 '18 at 11:10

2 Answers2

4

I may have found the answer:

enter image description here

The docs indicate that "... Google Cloud Client Library for Java supports GQL, but other Google Cloud client libraries do not."

Justin Tamblyn
  • 719
  • 8
  • 21
1

Looks like they have added Ruby, but still no Node.js :(

Fortunately, I needed the equivalent of GQL CONTAINS and .filter('foo', '=', 'bar') (on a value that is an array) seems to be working ok.

GQL added Ruby

Donn Lee
  • 2,962
  • 1
  • 24
  • 16