orient DB:向属性添加属性 [英] orient DB: Adding properties to properties

查看:149
本文介绍了orient DB:向属性添加属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是orientdb的新人,我正在探索的可能性。我有一个项目,我只是想确保我开始在正确的方向。



为了让你快速了解我想做什么,想想它像MS Access或Kexi,这意味着一个管理数据库的软件。



将创建一些表来管理软件,其他数据表将由用户创建。 Orient DB对类的每个属性/字段使用以下属性。



名称

类型
Linked_Type

Linked_Class

强制

Read_Only

Not_Null

最小

最大

Collat​​e



但对于用户数据库类fields,我要向其字段添加更多属性。



所以我的第一个想法是将那些添加的属性存储到数据库中的用户数据库的字段结构。用户数据将被放入定向数据库表,而添加的字段/属性信息将存储在系统数据库中。



但是, 2个不同的地方,我想知道是否没有其他的方法来进行。例如,也许我可以扩展用于存储字段属性的类,并添加我的新属性。但我不知道这是否是可能的。有一件事是肯定的,Web界面将不再工作,或至少不显示那些添加的字段。



...我的问题是否清楚?这是只是混淆,因为在东方数据库字段被称为属性也有属性(上面列出)






更新



我想象你所暗示的是NoSQL数据库对于主要功能没有结构。所以无结构数据库的定义结构是有点无意义的。



在这种情况下,如果我认为结构应该保持灵活,为每个字段。例如,字段可以具有名称,但是对于我来说几乎不足够的信息。我还需要:




  • 全名

  • 短名(缩写)

  • 说明



例如,在用户界面中,可以显示该信息以帮助用户。



如果实现为元数据,我可以有一个巨大的表索引的类名和字段名。每次引用数据库字段时,如果元数据可用,我会查看该表。如果是,我使用它,如果没有我只是忽略它。这将允许灵活的结构,因为即使没有定义元数据,可以添加新的字段。



否则我选择OrientDB的原因不一定是因为它缺乏结构,因为我喜欢结构化的信息。它首先是因为如果继承,使一个类继承一个超类的能力。第二,因为任何对象都可以链接到任何对象。这是我在关系数据库中不能做的2件事。



我的项目的一部分是处理棋盘游戏组件,它需要任何组件包含任何组件。例如,游戏板可以持有Pawns,令牌和卡。卡牌还可以持有棋子,令牌等。这些对象在游戏过程中四处移动。所以一个图形数据库似乎完美的目的。



但是刚性字段结构对我来说不是一个问题,如果你有继承。例如,具有不同字段结构的多种类型的卡只需要在超级类中具有公共信息。例如,物品卡可以具有超级类物品,并且具有称为武器,护甲,盾牌的派生类,每个都有自己的字段。






第二次更新



我试图改变属性,似乎工作,或者我应该说没有错误消息。但是当我尝试查询信息时,我什么都没有。在控制台上,它提供给我:

  ---- + ------ 
#| @CLASS
---- + ------
0 | null
---- + ------

找到1个项目。查询在0.036秒(s)内执行。

我试图在google上搜索自定义属性,但是没有关于它的文档。



也许我可以尝试从java代码中读取,因为这是我更可能使用的。



我有点设法以这种方式查看信息

 从(选择expand(classes)from metadata:schema) where name ='Item'

---- + ------ + ----- + ---- + -------- + ---- ----- + -------- + ------- + ---- + ---- + ------ + ---------- -------------------------------------------- + ----- -
#| @CLASS | name | type | globalId | mandatory | readonly | notNull | min | max | regexp | customFields | collat​​e
---- + ------ + --- + ---- + -------- + --------- + -------- + ------- + ---- + ---- + ------ + -------------------------------------- ---------------- + -------
0 | null |名称| 7 | 21 | false | false | false | null | null | null | {description =This is the name of the item,access = 1} | default
1 | null | Price | 1 | 22 | false | false | false | null | null | null | $ b ---- + ------ + ----- + ---- + -------- + --------- + ------ - + ------- + ---- + ---- + ------ + ---------------------- -------------------------------- + -------



这意味着运行我在文档中找到的命令不起作用:

  ALTER CLASS Item CUSTOM name.display = 1 


解决方案

有趣的问题!



OrientDB的好处是它的灵活性。您决定是否要构造数据模型(定义模式约束)。您可以通过定义课程来实施架构约束, 属性,并定义约束/构面(称为OrientDB的属性) 。除了您列出的系统定义的属性,您还可以定义自定义属性。



例如:

  CREATE CLASS MyTable 
CREATE PROPERTY MyTable.name STRING
ALTER PROPERTY MyTable.name CUSTOM displayOrder = 1

注意CUSTOM属性。 OrientDB本身忽略这个属性(因为没有为它定义语义),所以你必须在你的应用程序中自己管理它。



要查询这些自定义属性:

  select classes [name ='MyTable']。properties [name ='name']。customFields.displayOrder FROM metadata:schema 

I am new to orientdb and I am exploring the possibilities. I have a project in mind and I just want to make sure I start in the right direction.

To give you a quick idea of what I want to do, think of it like MS Access or Kexi, which means a software that manage database. That explanation will be enough for my question.

Some "tables" will be created to manage the software, and other data "tables" will be created by the user. Orient DB use the following "properties" for each "property"/"Field" of a class.

Name
Type Linked_Type
Linked_Class
Mandatory
Read_Only
Not_Null
Min
Max
Collate

But for the user database class "fields", I want to add more properties to their field.

So my first idea, was to store into the database, the field structure of the user database with those added properties. The user data will be put into regular orient db "tables", while the added field/property information will be stored in the system database.

But instead of keeping information in 2 different places, I was wondering if there were not other ways to proceed. For example, maybe I could extend the class used to store field properties and add my new properties. But I am not sure if it is actually possible. One thing for sure is that the web interface would not work anymore, or at least not display those added field.

... Is my question clear? It's just confusing because in orient DB fields are called properties which also have properties (listed above)


Update

I imagine that what you implied is that NoSQL database has for primary feature no structure at all. So defining structure for a no structure database is a bit pointless.

In that case, If I consider that the "structure" should remain flexible, it could be implemented as metadata for each field. For example, a "field" can have a "name", but that is barely enough information for me. I would also need:

  • Full Name
  • Short Name (Abbreviation)
  • Description

So that for example, in the user interface, that information could be displayed to help the user. Or that this information could be used to generate a wiki web page for documentation purpose.

If implemented as metadata, I could have a huge table indexed by class name and field name. Each time I refer to a database field, I look into that table if metadata is available. If yes, I use it, if no I just ignore it. That would allow flexible structure as new "fields" could be added even if no metadata is defined.

Else my reason for choosing OrientDB is not necessarily for it's lack of structure, because I do like structured information. It's first because if inheritance, the ability to make a class inherit a super class. Second because any object can be linked to any object. These are 2 things I cannot do in relational database.

A part of my project is to handle board game components which require any component to contain any component. For example, a game board can hold Pawns, tokens and cards. Where cards can also hold pawns, tokens, etc. Those objects are moved around during game play. So a graph database seems perfect for that purpose.

But the rigid field structure is not really an issue for me if you have inheritance. For example, having multiple kind of cards with different field structure just require to have the common information in a super class. For example, Item cards could have the super class "Item" and have derived class called "Weapon", "Armor", "Shield" which each have their own field.


2nd update

I tried altering property and it seems to work, or should I say there is no error message. But When I try to query the information, I get nothing. On console it gives me:

----+------
#   |@CLASS
----+------
0   |null  
----+------

1 item(s) found. Query executed in 0.036 sec(s).

I tried to search google about custom properties but there is little documentation about it.

Maybe I could try reading it from java code since this is what I am more likely to use.

I somewhat managed to see the information this way

select expand(properties) from ( select expand(classes) from metadata:schema) where name='Item'

----+------+-----+----+--------+---------+--------+-------+----+----+------+------------------------------------------------------+-------
#   |@CLASS|name |type|globalId|mandatory|readonly|notNull|min |max |regexp|customFields                                          |collate
----+------+-----+----+--------+---------+--------+-------+----+----+------+------------------------------------------------------+-------
0   |null  |Name |7   |21      |false    |false   |false  |null|null|null  |{description="This is the name of the item", access=1}|default
1   |null  |Price|1   |22      |false    |false   |false  |null|null|null  |null                                                  |default
----+------+-----+----+--------+---------+--------+-------+----+----+------+------------------------------------------------------+-------

which implies that running this command that I found in the documentation did not work:

ALTER CLASS Item CUSTOM name.display=1

解决方案

Interesting question!

The nice thing about OrientDB is its flexibility. YOU decide if you want to structure your data model (define schema constraints) or not. Enforcing schema constraints is done by defining Classes, Properties for those classes and defining constraints / facets on these properties (called Attributes by OrientDB). Besides the system defined attributes you listed, you can also define custom Attributes. Maybe this is where you are looking for.

Example:

CREATE CLASS MyTable
CREATE PROPERTY MyTable.name STRING
ALTER PROPERTY MyTable.name CUSTOM displayOrder=1

Notice the CUSTOM Attribute. OrientDB itself ignores this Attribute (because there are no semantics defined for it), so you must manage it yourself in your application. However, you defined all meta data at one place.

To query these custom attributes:

select classes[name='MyTable'].properties[name='name'].customFields.displayOrder FROM metadata:schema

这篇关于orient DB:向属性添加属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆