我有一个包含IP地址范围的模型,类似于:
class Country(db.Model):
begin_ipnum = db.IntegerProperty()
end_ipnum = db.IntegerProperty()
Run Code Online (Sandbox Code Playgroud)
在SQL数据库上,我将能够找到包含特定范围内的IP的行,如下所示:
SELECT * FROM Country WHERE ipnum BETWEEN begin_ipnum AND end_ipnum
Run Code Online (Sandbox Code Playgroud)
或这个:
SELECT * FROM Country WHERE begin_ipnum < ipnum AND end_ipnum > ipnum
Run Code Online (Sandbox Code Playgroud)
遗憾的是,GQL只允许在一个属性上使用不等式过滤器,并且不支持BETWEEN语法.我如何解决这个问题,并在App Engine上构建一个与这些相当的查询?
此外,ListProperty创建记录时可以"生存"还是必须计算?
首先尝试解决方案更新问题:
所以根据David的答案以及以下文章:
http://appengine-cookbook.appspot.com/recipe/custom-model-properties-are-cute/
我正在尝试将自定义字段添加到我的模型中,如下所示:
class IpRangeProperty(db.Property):
def __init__(self, begin=None, end=None, **kwargs):
if not isinstance(begin, db.IntegerProperty) or not isinstance(end, db.IntegerProperty):
raise TypeError('Begin and End must be Integers.')
self.begin = begin
self.end = end
super(IpRangeProperty, self).__init__(self.begin, self.end, **kwargs)
def get_value_for_datastore(self, model_instance):
begin …Run Code Online (Sandbox Code Playgroud) 我创建了一个应用程序,让用户输入产品并进行比较.我现在需要考虑扩展和多个用户,我想只向用户显示他们创建的项目(而不是整个数据库,这可能是某个选项,但现在每个用户必须创建自己的列表).
是否有一种罐装/首选方式使整个应用程序中的所有查询仅返回条目,并将"作者"字段设置为特定用户,登录用户?或者是否必须使用"AND author ..."类型过滤器更新每个查询?这是命名空间的用途吗?
我在Google App Engine上使用Python.
在GQL参考中,鼓励将IN关键字与值列表一起使用,并从GQL查询中手动构造Key
SELECT * FROM MyModel WHERE __key__ = KEY('MyModel', 'my_model_key')
Run Code Online (Sandbox Code Playgroud)
将会成功.但是,使用您期望的代码:
SELECT * FROM MyModel WHERE __key__ IN (KEY('MyModel', 'my_model_key1'),
KEY('MyModel', 'my_model_key2'))
Run Code Online (Sandbox Code Playgroud)
在数据存储查看器中,存在"无效的GQL查询字符串"的投诉.
格式化此类查询的正确方法是什么?
更新:这不适用于当前的SDK.正如我在评论中指出的,当使用列表时,只有引用(例如:1或:email)或int,float,string,boolean或null literal是可接受的列表条目.
第二个更新:我修复了错误,现在可以执行此类查询.可以在Google Code Hosting diff中找到修复程序 .
PS我知道在Python中有更有效的方法(没有构建GQL查询)和使用remote_api,但每次调用remote_api都会计入配额.在配额不是(必然)免费的环境中,快速和脏的查询非常有用.
我认为这是不可能的,如果添加了新索引,则必须重新加载所有数据.
这应该发生吗?
如果我有两个表,客户和订单,并且我想查找客户的最新订单,我将如何使用GQL在Google App Engine上执行此操作?
通常,我会通过订单表中存在的外键customer_id加入这两个表.
select orders.* from customers, orders
where customers.customer_id = orders.customer_id
and orders.order_id = (select top 1 sub_orders.order_id from orders sub_orders
where sub_orders.customer_id = orders.customer_id
order by sub_orders.order_date desc)
Run Code Online (Sandbox Code Playgroud)
但是,由于Google App Engine似乎无法进行加入,因此我不确定如何解决此限制.任何建议,将不胜感激.
我想搜索名称以特定字符串开头的所有实体,这在数据存储中可能吗?
我试过这个:
q = datastore.NewQuery("Places").Filter("Name > ", "a")
Run Code Online (Sandbox Code Playgroud)
但这不起作用。
如果这是不可能的,您可以向我建议什么替代解决方案?大查询?App Engine 上的 BigTable 或其他服务?
我正在研究 React + Postgraphile (GraphQL) + axios(对 postgraphile 服务器的 http 请求)的教学组合的项目。
它有很多 GraphQL 查询。最初是从同一文件中的查询与其他 JavaScript 和渲染代码开始的,但一旦添加了特定查询,它就变得混乱了。
在搜索时,我发现我们可以将查询分离到单独的文件中 - .graphql 或 .gql 为此,我必须与 Webpack 模块集成 -
我想知道是否有更简单(开箱即用)的方法来实现类似的事情,而不使用 Webpack,因为它需要大量的配置。
任何指针或示例都会非常有帮助。
谢谢。
在我的 hasura.io 数据库中,我有一个booking表,我在其中存储具有以下属性的预订:
现在,从 UI 中,当用户进行预订时,我想检查之前是否有任何涉及这些日期范围的预订。
例如。用户想要在以下日期进行预订:
{
"from": "2020-03-31T14:00:00+00:00",
"to": "2020-03-31T17:00:00+00:00"
}
Run Code Online (Sandbox Code Playgroud)
但在同一天有一个预订:
{
"from": "2020-03-31T15:00:00+00:00",
"to": "2020-04-01T17:00:00+00:00"
}
Run Code Online (Sandbox Code Playgroud)
请注意,此预订不是在用户尝试预订的日期范围内进行的。因此,以下查询将不返回任何内容。
query CheckBooking($from: timestamptz!, $to: timestamptz!) {
booking(where: {_and: [{from: {_lte: $from}}, {to: {_gte: $to}}]}) {
id
from
to
}
}
Run Code Online (Sandbox Code Playgroud)
以上是我尝试过但没有成功的方法。任何人都可以帮助找出检查范围内或用户新预订内是否有任何预订的正确查询是什么?
从 useEffect 挂钩接收数据后,我尝试调用 Graph QL 查询。我需要响应中的数据在查询中使用。然而,钩子不能有条件地调用。然而,如果我去掉这个条件,loadedAnime 将是未定义的。我该如何摆脱这种限制?
import React, { useEffect, useState } from "react";
import { useParams } from "react-router-dom";
import AnimeBanner from "../components/AnimeBanner";
import { useHttpClient } from "../Hooks/http-hook";
import { GetAnimeData } from "../GraphQLFunctions";
import { useQuery } from "@apollo/react-hooks";
import gql from "graphql-tag";
const GET_ANIME_INFO = gql`
query GetAnimeInfo($name: String!) {
Media(search: $name) {
title {
romaji
english
native
userPreferred
}
episodes
id
bannerImage
}
}
`;
const Anime = (props) => {
//Logic for getting …Run Code Online (Sandbox Code Playgroud) 当我直接查询数据库时,此查询有效,但当我使用 python gql 时,我不断收到此错误。我无法找到如何停止在任何地方出现该错误。
query = f"""query{{
addresses(line1: "{street}", city: "{city}", zip: "{zip}", subdivision: {state}){{
entities{{
id
}}
}}
}}"""
GraphQL = sonar.execute(query=query, variable_values=None)
Output: TypeError: Not an AST Node: 'query{\n addresses(line1:............
Run Code Online (Sandbox Code Playgroud) gql ×10
graphql ×3
reactjs ×2
apollo ×1
go ×1
hasura ×1
javascript ×1
join ×1
node.js ×1
postgraphile ×1
python ×1
python-3.x ×1
react-apollo ×1
string ×1
typeerror ×1