larienna
larienna

Reputation: 151

orient DB: Adding properties to properties

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:

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

Upvotes: 2

Views: 1814

Answers (1)

rmuller
rmuller

Reputation: 12849

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

Upvotes: 3

Related Questions