OrientDB用户手册之 SQL Query on a NoSQL database

上一节我们浏览了一些OrientDB的基本概念,并且提及一个讨论最多的:支持SQL语言。Is not a contradiction for a DBMS that is defined NoSQL embrace this standard?Maybe not。
【讲了一堆废话,懒得翻了,浪费时间,我也没怎么看懂】
We defined in the introductory movement NoSQL not as something contrary to SQL itself, but as the warning "use the DBMS right for your use case. So why support its SQL ? Incidentally the relational model is very different from the graph and very far from the concepts of schema-less document database.

The answer is simple: anyone reading this know SQL because it has been the predominant technology in the last 30 years. Rather than inventing Yet Another Language I thought from ancient SQL would be a good idea to allow anyone to use OrientDB from day one.

Obviously the standard SQL language has no concept of schema-less, trees or graphs because it was designed for a model that does not cover this kind of structures, if not purely through adaptation applications. To support these new paradigms are created for new entrants and an extended syntax.

那么我们开始使用绑定的演示数据库。打开控制台(见前面的章节)并连接到你电脑上的数据库demo。现在运行:select * from city(就像你在关系数据库中查找City表中的所有记录)。
> select * from city

现在,让我们创建一个带条件的查询,包含多个连接的记录。在关系世界就是一个多表间的join,but the links are directly OrientDB waterways。下面就是它的实现方法:
> select * from city where country.name = 'Italy'

在这个例子中,这个查询将返回国家名是“Italy”的城市:简单,快速,简洁。想象一个更复杂的查询,它的条件牵涉更多的记录。等价的关系查询非常长并且难以阅读,但用OrientDB,所有事情都很简单和可读。如果你省略了projections(就是在关键字“SELECT”和“FROM”之间的,这个例子里是“*”),OrientDB总是返回所有记录。例如:
> select from city

E 'can also navigate through records in the projections, useful if you do affect, not as a result the current class, but connected elements。例如我们想从Address类型的记录中抽取所有意大利的前三个城市的名字,可以这样:
> select city.name from address where city.country.name = 'Italy' limit 3

注意limit子句3,它约束结果为3个元素。现在我们已经了解了连接(LINK),让我们看看如何使用复杂类型比如Collection,设计为一个列表或集合。这两个之间的区别是,列表保持按位置排序的元素的顺序而且允许重复,然而在集合中不能有重复,而且排序是任意的【一堆废话,其实就是说List是有序有重复,Set是无序无重复】。在下面的例子中我想尝试包含多个地址的账户。“addresses”属性是一个包含Address类型记录的集合,它描述了1-N(一对多)关系。关系数据库中需要一个外键来描述关系,OrientDB用引用集合(或连接)。
> select from account where addresses.size() > 0

size()操作是其中一个可用的操作。在下一节,我们将看到其他更详细的集合和映射操作。现在我们将用更复杂例子来结束这一节:查找所有地址是“Washington”的账户(addresses是Address的collection)。
> select flatten(addresses) from Account where addresses contains ( city.country.name = 'Washington' )

这个例子中我们用contains操作,它为collection中所有元素执行括号中的条件,如果最终有一个(以上)元素满足条件,就返回TRUE。flatten()操作抽取所有结果的collection,然后全部放到一个collection中,使他们更加简单。

你可能感兴趣的:(orientdb)