OrientDB-NET.binary icon indicating copy to clipboard operation
OrientDB-NET.binary copied to clipboard

Retrieving the properties defined for a class is not very intuitive

Open jmcdaniel83 opened this issue 7 years ago • 1 comments

Introduction

I was working with injecting properties into a class' schema, but then when a property name wasn't in the proper format it would only add a subset of the total properties I wanted into a class. This caused me to have to get a list of property names that are already defined so that I only add the newer ones to the class.

However, I found that the current API is not very intuitive in its execution. I'm hoping that there is a different API that I've missed. But here's the code that I'm currently having to do in order to just verify that a given property already exists for a class:

// collect our current properties (very odd how to get this data)
List<string> props = new List<string>();
foreach (ODocument item in connection.Schema.Properties(heatMapClass)) {
   // this is not an intuitive way to retrieve a property name
   object propertyName;
   // need to have an understanding of the underlying type here with the
   // constant "name" string
   item.TryGetValue("name", out propertyName);
   props.Add(propertyName.ToString());
}

// Now I can simply use the List API to check if a property is already defined
if (!props.Contains(propertyName)) {
   // add new property name
}

Proposal

Would prefer a similar API when one wishes to verify when a class already exists or not connection.Schema.IsClassExist(). So in this case have a few new methods:

  • connection.Schema.DoesPropertyExist("PropertyName").Class("ClassName") - Will verify that a single property name already exists for the provided class name.
  • connection.Schema.PropertyList("ClassName") - Will provide a List of Property objects for the provided class name that has all the items associated with a property (Name, Type, etc.).

This way I could simply validate a property exists on a class, and if I needed all properties for a given class. I can access the items in a very simple way through properties.

// validate that a property already exists for our class
if (!connection.Schema.DoesPropertyExist("PropertyName").Class("ClassName")) {
   // add new property name
}

// go through our properties for our class
List<Property> props = connection.Schema.PropertyList("ClassName");
foreach (Property prop in props) {
   // get the name
   string propertyName = prop.Name;
   // get the type
   OType propertyType = prop.Type;
   // etc.
}

jmcdaniel83 avatar Apr 05 '17 19:04 jmcdaniel83

I will take a look at your proposal as it fits into the new binary driver being developed. Thank your for your recommendation :)

realityenigma avatar Apr 14 '17 04:04 realityenigma