I'm new to OrientDB and I understood that classes can have properties and in this case they actually act as tables in relational databases. However, I found out that even if I define properties for a class, it still doesn't guarantee that a document created from this class has a value for all its properties.
For example:
Here, I define a class 'Person' with a property 'name', and I still insert a new document to this class although it doesn't have a value for this property.
If so, what is the purpose of properties and how can I make sure that documents that do NOT include a value for a certain property will not be inserted into the class?
orientdb {db=GratefulDeadConcerts}> create class person
Class created successfully. Total classes in database now: 17.
orientdb {db=GratefulDeadConcerts}> create property person.name string
Property created successfully with id=1.
orientdb {db=GratefulDeadConcerts}> insert into person content
{"phone":"1234"}
Inserted record 'person#66:0{phone:1234} v1' in 0.000000 sec(s).
orientdb {db=GratefulDeadConcerts}> select from person
+----+-----+------+-----+
|# |#RID |#CLASS|phone|
+----+-----+------+-----+
|0 |#66:0|person|1234 |
+----+-----+------+-----+
In OrientDB you can work in schema-less, schema-hybrid or schema-full.
You can define properties and you can define constraints on each property:
http://orientdb.com/docs/last/SQL-Create-Property.html
At the same time you can define indexes on property:
http://orientdb.com/docs/last/Indexes.html
For example, if you want that a property has unique values over the entire class (a primary key), just define a unique index:
CREATE INDEX Person.name ON Person (name) UNIQUE
hope this help
Related
I am developing an Application using DevExpress XPO. I have a class OrderBase and and another class OrderDetails which extends OrderBase. OrderBase has a column modified_at which is capturing the last modification data as timestamp.
The table 'OrderBase' into PostgreSQL has the field modified_at but the table 'OrderDetails' into PostgreSQL does not have this field.
Is there any easy way to have this column physically into the database on table 'OrderDetails' just like table 'OrderBase'? Column should be updated to in both classes/tables.
I tried already to set the column name as field into 'OrderDetails' class but ofcourse is impossible as the field exists in the class which extends.
In prisma.io how do I find the name of a table's primary key? It is defined in file schema.prisma, but how to I identify the primary key of any arbitrary table at runtime, given the table's name?
So far I can find no reference to this in the documentation for Prisma Client. After instantiating PrismaClient I can find the list of tables and their column names (prisma._baseDmmf.datamodel.models), but no hint of which column(s) is the primary key.
I found an answer. I imported Prisma (in addition to PrismaClient) which provides access to Prisma.dmmf.datamodel.models which is an array of table models. Each table model includes an array of field definitions, each of which has the boolean property isId, which is true if that field is the row id.
For example:
Prisma.dmmf.datamodel.models[1].fields[0].isId
The names of each table and each field are string properties:
Prisma.dmmf.datamodel.models[1].name == 'Assets'
Prisma.dmmf.datamodel.models[1].fields[0].name == 'AssetId'
Hope this helps someone.
I am coming from the RDBMS world. so forgive if I ask a badly phrased question.
I have a situation where I need to ensure unique or partial unique populating data inside cayley
In RDBMS such as postgres, I can build a table like this:
primary autoincrement key called id
foreignkey to person table called person_id
foreignkey to product table called product_id
foreignkey to price table called price_id
boolean field called is_removed
If i want a unique constraint such as the entire table can have a unique index such that product_id and price_id are together as a pair must be unique, I can do that.
if i want a partial unique constraint in postgres where if the is_removed is False, then the person_id, product_id, and price_id are unique.
Then if any of the foreignkeys are null, the constraints are not triggered.
How do I have something this inside a graph database such as orientDB?
My objective is to prevent creating illegal relations in the database
In orientDB you can define a schema for your database.
You have classes instead of tables.
Vertexes and edges are specialized classes.
You can define properties on classes, and define constraints on properties.
As a concrete example, the definition for the a User vertex class :
CREATE CLASS User EXTENDS V;
CREATE PROPERTY User.userId LONG;
CREATE PROPERTY User.description STRING;
CREATE PROPERTY User.screenName STRING;
CREATE PROPERTY User.lang STRING;
CREATE PROPERTY User.location STRING;
CREATE PROPERTY User.fetched BOOLEAN;
CREATE INDEX User.userId ON User(userId) UNIQUE_HASH_INDEX METADATA {ignoreNullValues: true};
CREATE INDEX User.description ON User(description) FULLTEXT ENGINE LUCENE METADATA {ignoreNullValues: true};
These are the links to the official part of the documentation about SQL and schema manipulation:
http://orientdb.com/docs/3.0.x/sql/SQL-Create-Class.html
http://orientdb.com/docs/3.0.x/sql/SQL-Create-Vertex.html
http://orientdb.com/docs/3.0.x/sql/SQL-Create-Edge.html
http://orientdb.com/docs/3.0.x/sql/SQL-Create-Index.html
http://orientdb.com/docs/3.0.x/sql/SQL-Create-Property.html
Is there a simple way to update the name of all of a type of existing edge relationships?
alter class EDGE_NAME name NEW_EDGE_NAME
updates the name of the base edge class, but doesn't affect any existing relationships.
ie:
create class Person extends V
create class Car extends V
create class OWNS extends E
create vertex Person set name="Bob"
create vertex Car set name="Jeep"
create edge OWNS from (select from Person where name="Bob") to (select from Car where name="Jeep")
alter class OWNS name DRIVES
does nothing but delete the old edge type and create a new edge type, leaving the existing relationship unaffected (Bob still OWNS a Jeep, yet OWNS doesn't exist)
What are we supposed to do if thousands of these relationships exist?
You should rename attributes with the following commands that copy to the new name and drop the previous ones for both in and out directions:
UPDATE V SET out_DRIVES = out_OWNS where out_OWNS is not null
UPDATE V SET in_DRIVES = in_OWNS where in_OWNS is not null
UPDATE V REMOVE out_OWNS where out_OWNS is not null
UPDATE V REMOVE in_OWNS where in_OWNS is not null
If I have 2 tables 1 with a composite primary key where one of the keys is also a foreign key in another table:
Table 1:
A (PK, FK - maps to X in Table 2)
B (PK)
C
Table 2:
X (PK)
Y
Because A is both the PK in table 1 and FK in table 2, when I use EF to generate the entity model, I have both a Scalar AND a Navigation property for A in table 1. I cannot seem to remove A as a scalar (I think because it is a primary key).
The problem I am having is that if I create a table1Entity and set A's scalar property to a new value, A's navigation property will not be changed automatically (and vice versa).
Ideally I just want A to expose the navigation property - which is the way it behaves if A was not also part of the composite primary key anyway. Is there any way to achieve this?
Am I correct in assuming that Table1 derives from Table2? If so, I would do it like so:
(I'd also change the PK for both tables to the same name, since they probably have the same meaning - for the instance of this, I'll use the example ID)
First, create the model with the default relationships (I usually just import the two tables from the database)
In the designer, right click the base type, add inheritance, select the derived type.
Delete the one to zero or one association
Then, since the base type already has column ID, delete it from the derived type.
Go to table mapping for the derived type, and map the ID property to the ID of the table.
Well, not really. Create the view with schemabinding and create a clustered index on the view (SQL Server 2008 or later, earlier versions I'm not sure can do that). The clustered index will be recognised as a primary key, thus tricking EF(VS) into believing the view is a real table.
Have you expicity set the Ids of the composite key and referenced these in your configuration?
i.e
public class Table1
{
public Table2 A{get;set}
public int AId {get;set;}
public int BId {get;set;}
}
I assume you'll need something like:
HasKey(pc => new { pc.AId, pc.BId});
HasRequired(x => x.A).WithMany().HasForeignKey(x => x.AId);
Instead of mapping to table 1 directly, add a view to your database that's got all of table 1's fields, plus an extra copy of A (A2).
Then, map the scalar key to A2 and the nav key to A.
(You'll run into a problem where if you use a view, Visual Studio can't find a primary key; fix this by manually editing the XML of the edmx file and adding a <Key><PropertyRef ... /></Key> to the <EntityType> for table A)
I know - it's hacky and horrible... but hey - it works!