Is it possible to create a unique constraint on a sub-key in ArangoDB? - indexing

Context
We are limited by ArangoDB's recommendation against using attribute names starting with an underscore _ https://www.arangodb.com/docs/stable/data-modeling-naming-conventions-attribute-names.html because we want to be certain that any such attribute would not be used by ArangoDB at a later stage.
We could add an attribute
properties:{myproperty1:'abc',_myUnderscoreProperty:'def'},
but in case we would do this for documents representing users, which would have
properties:{_name:'abc',_email:'abc#graphileon.com'},
we would need to be able to create a unique constraint on properties._name. But this does not seem to be possible.
Question
Is this possible or there a workaround?

Yes, it is possible. You can create a unique index on field properties._name

Related

Creating constraint on multiple properties in neo4j

I'm new in Neo4j an I need some help.
I'm trying to make constraint in multiple properties of nodes at once per two meanings:
I need to specify as constraint many properties without typing again and again all over the properties with the command
I need to define many properties as ONE- UNITY constraint like in SQL when 3 attributes is a primary key and not separably.
How can I achieve it?
You are actually asking 2 questions.
The APOC procedure apoc.schema.assert is helpful for conveniently ensuring that the DB has the required set of indexes and constraints. (Be aware, though, that this procedure will drop any existing indexes and constraints not specified in the call.)
For example, as shown in the documentation, this call:
CALL apoc.schema.assert(
{Track:['title','length']},
{Artist:['name'],Track:['id'],Genre:['name']});
will return a result like this (also, if an index or constraint had been dropped, a row with the action value of "DROPPED" would have been returned as well):
╒════════════╤═══════╤══════╤═══════╕
│label │key │unique│action │
╞════════════╪═══════╪══════╪═══════╡
│Track │title │false │CREATED│
├────────────┼───────┼──────┼───────┤
│Track │length │false │CREATED│
├────────────┼───────┼──────┼───────┤
│Artist │name │true │CREATED│
├────────────┼───────┼──────┼───────┤
│Genre │name │true │CREATED│
├────────────┼───────┼──────┼───────┤
│Track │id │true │CREATED│
└────────────┴───────┴──────┴───────┘
Since there is not (yet) any way to create an index or constraint on multiple properties of a node label, one popular workaround is to use an extra property whose value is an array of the values you want to use. You will have to make sure the values are all of the same type, converting some if necessary. Unfortunately, this requires storing some data redundantly, and makes your code a bit more complex.

Foreign key: check table has no key field with the domain

I have two tables: ZDEPARTMENT01 and ZEMPLOY01.
ZDEPARTMENT01 has a foreign key DEPHEAD, whose data element is ZPERSONNEL_NO of domain ZPERSONNEL_NO ( NUMC, 10 ). ZEMPLOY01 has a primary key EMP_NUM, whose data element is ZEMP_NUM of domain ZEMP_NUM ( NUMC, 10 ).
ZDEPARTMENT01-DEPHEAD is the foreign key and ZEMPLOY01-EMP_NUM is the check key, and ZDEPARTMENT01-DEPHEAD domain ZPERSONNEL_NO has value table: ZEMPLOY01.
While setting the check table for ZDEPARTMENT01-DEPHEAD I got the error Check table ZEMPLOY01 has no key field with the domain ZPERSONNEL_NO of the field DEPHEAD
Even though both domains have the same datatype and length (but different domains) the system is unable to recognize the foreign key table and check table relationship.
The document says: The system attempts to assign the key fields of the check table to fields of the table with the same domain. Does it mean in addition to the datatype and the length, the domain names should be same between the foreign key table and the check table?
How to solve this?
Yes that's what it means. You have two Data Elements: ZEMP_NUM and ZPERSONNEL_NO. If you double-click on these, in your table, you will navigate to the data element definition. There you will see the Domain assigned to each. These should be the same, so make them the same.
Think about it this way:
Domains provide structural consistency for data that can appear in multiple places. You wouldn't have an employee id that's 10 digits in some places and 8 in others or it will cause 10-digit records to get truncated. Likewise, if you run out of digits and need to extend your employee id to 11 digits, you want to make sure it's changed everywhere, in every table where it's used. Domains let you do this. Domains also let you configure the default look up relationship (value table) or fixed values that can be selected (eg the Employee table).
Data Elements provide contextual relevance. You'll notice that in addition to supplying the domain of a data element, you can define the field labels and heading, and you can assign a custom search help. These allow you to display the field to the user in a way that is relevant to the current activity. In this case, you can label the Employee "Department Head", because it would be confusing to have a field meant to hold the ID of the department head and have it display as only "Employee". You could also add a search help that restricts the Employee list to only those flagged as "Managers".
As it already says in the message, you'll have to adjust your data elements to use the same domains:
The check table must have a key field to which the domain of the check
field is assigned.
(documentation)
I'm not entirely sure about this, but I believe the rationale behind this is that this will prevent you from changing one of the table field definitions without changing the other one at the same time.
I think your problem are the key fields definitions. The table 'ZEMPLOY01' has the key fields 'CARRIER' and 'EMPNUM' and if you want that the foreign key 'DEPHEAD' of table 'ZDEPARTMENT01' works then you have two options:
Change the key fields defined in table 'ZEMPLOY01'. Just set 'EMPNUM' as your only key field and then try to make the relation.
Add the field 'CARRIER' to table 'ZDEPARTMENT01' and then try to make the relation.
Please confirm.
Hope it helps.

Custom PL/SQL functions for dual-column primary key to put in form creator

I have a table with primary key that consist of two columns and both are foreign keys. I'm creating form on this table and wizard require either sequence or trigger or custom PL/SQL function. I want to get values for both columns from items that will be located on form and filled when redirecting from another page to this page (that I'm creating).
Does function is good solution in this case? How this function should look? Could you write me an example, please? Sample hidden item to be used in form would be P21_ID_ROW_FK.
I will be grateful for any help you can provide.
If you can, I suggest you create a surrogate primary key on your table, and populate it using a sequence or a trigger. Create a unique constraint on your two foreign key columns.
I don't want to start a surrogate vs natural key debate here. Some frameworks, including Apex, just seem to be designed with surrogate keys in mind, the current question being a case in point.

Creation of compund unique contraint in neo4j 2.0

i'm using neo4j to create a versioned graph database, and i'm having some troubles to implement unique constraints in the database.
I want to know if is possible to do something like
CREATE CONSTRAINT ON (u:CaliopeUser) ASSERT u.timestampt+u.name IS UNIQUE
Or any other idea about how to implenment the uniqueness constraint in neo4j for a versioned database.
In 2.0 compound schema indexes are not possible. The recommended workaround is to create another property holding the compound value (maybe a transactionEventHandler might help with automating this) and use a index on that property.
I expect support for indexes on compound properties in some future release.

SORM: Mapping fields to custom column names?

From the SORM documentation, it's not really clear and the API does not help.
So, how do I specify a custom column name in an entity? I would also like to change the column name of the primary key for each entity. Is that possible?
Thanks.
No. Changing column names isn't possible because SORM is all about convention over configuration. That's what makes it simple.
The primary key isn't configurable either, but for different reasons.