我正在尝试对可以使用graphql的灵活性但希望使其标准化的数据库进行建模。
想象一下这种关系结构:
is.character(mydata$Date)
[1] FALSE
is.numeric(mydata$Date)
[1] FALSE
但是我想创建四个不同的集合以使其标准化。
为了最好地描述,其模式如下所示:
planet
continent
country
city
太好了,我可以查询每个单独的元素,并获取所有元素。
但是,如果我想获得一个大陆的所有城市怎么办?
我需要完善以下内容:
type Planet {
planetName: String
}
type Continent {
continentName: String
}
type Country {
countryName: String
}
type City {
cityName: String
}
type Query {
planets: [Planet]
continents: [Continent]
countries: [Country]
cities: [City]
}
现在,如果我们进行查询,我们将得到type Continent {
continentName: String
cities: [City]
}
type City {
cityName: String
}
type Query {
planets: [Planet]
continents: [Continent]
countries: [Country]
cities: [City]
}
(ID),并且可以得到属于它的所有城市。但是我们需要在城市和大陆之间建立某种联系。我的想法就像在数据库结构中一样:
continentName
这样,我可以编写一个解析器来从查询的父对象中获取continent: {
continentName,//the id
countries,//array of ids of countries
cities //array of ids of cities
}
,并从指定ID的城市集合中进行查询。
但是,如果我想做这样的事情怎么办:
cities
反过来,得到属于该大陆的所有城市。我可以去查询特定的大陆,获取所有属于该大陆的城市,并获取指定的城市,但这需要很长时间。
如果我要像这样构造数据怎么办?
type Query {
cities(continentName: String): [City]
}
使用上述结构,无论从哪个级别向下,向哪个方向向下,我都可以连接并以嵌套格式查询数据。这似乎是一个完美的解决方案,但是当我阅读了对noSQL数据库进行建模时,我并没有发现它。
解决方案是否可能存在瓶颈或问题?