Cosmos DB Graph-API 中的查询参数



新的 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")
                    }
        });

我问的时候考虑到了安全。或者还有其他方法可以防御小精灵的注射?

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 兼容的功能。

最新更新