在Cosmos DB Graph-API中查询参数

时间:2017-05-11 13:51:35

标签: gremlin azure-cosmosdb

新的Cosmos DB图API中是否支持查询参数? 例如,在查询中:

IDocumentQuery<dynamic> query = client.CreateGremlinQuery<dynamic>(graph, "g.V().has('name', 'john')");

我可以像在DocumentDB中那样用查询参数替换硬编码值'john':

IQueryable<Book> queryable = client.CreateDocumentQuery<Book>(
                collectionSelfLink,
                new SqlQuerySpec
        {
                    QueryText = "SELECT * FROM books b WHERE (b.Author.Name = @name)", 
                    Parameters = new SqlParameterCollection() 
            { 
                          new SqlParameter("@name", "Herman Melville")
                    }
        });

我在考虑安全问题。或者可能还有其他方法可以防止Gremlin的注射?

1 个答案:

答案 0 :(得分:-3)

Tinkerpop通常有bindings的概念,允许您从gremlins脚本中单独定义数据。可以在此处找到使用Java代码的示例:https://github.com/tinkerpop/gremlin/wiki/Using-Gremlin-through-Java  (搜索绑定)。

您还可以通过Http端点使用绑定,例如通过执行以下操作:

curl http://localhost:8182 -d '{"gremlin": "g.V().has(key1, value1);", "bindings": {"key1": "name", "value1": "david"}}'

您需要查明查询中的client是否支持绑定参数,但在我看来,您正在寻找的是与Tinkerpop兼容的功能。

相关问题