question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding new properties with the CREATE CLASS command.

See original GitHub issue

Hi,

In the SQL world, it is possible to create schema within the CREATE TABLE command. It would be cool if ODB could do the same. Something along the lines of:

CREATE CLASS User (
Id LONG STRING,
FirstName STRING,
LastName STRING,
Address EMBEDDED (
           Street STRING,
           City STRING,
           PostalCode STRING,
           Country STRING),
BirthDate DATETIME
);

Not sure if that is how EMBEDDED should work, but I think the point is clear.

Scott

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
mmacfaddencommented, Jun 13, 2016

TL;DR This requires a conceptual shift in OrientDB and there may or may not be an easy way to get there. Thinking of it in terms of existing EMBEDDED functionality will probably not work.

I think this is interesting. When I first started using OrientDB I was expecting something like this. I however quickly realized the Orient has a class/inheritance model very similar to an object oriented programming language. The schema control is centered around classes. Classes are named and unique in the system. Just like in Java. If want to declare a class I do this:

public class Person {
  String firstName;
  String lastName;
}

If I want a Person to have an address, I could do this:

public class Person {
  String firstName;
  String lastName;

  String addressLine1;
  String addressLine2;
  String addressCity;
  String addressCountry;
}

I have kept person flat and defined the address on it. I can say Person.addresLine1 etc. Then I might think to my self two things. I might think 1) I have 4 related attributes that represent and address, 2) I want to define a company that has an address also, so 3) I should make a separate class.

public class Address {
  String line1;
  String line2;
  String city;
  String country;
}

public class Person {
  String firstName;
  String lastName;
  Address address;
}

public class Company {
  String name;
  Address address;
}

Now I can do the following: Person.address.line1 and I am happy. This is exactly how orient works. In many object orient languages this is the only way to compose objects. In Java the class definition is essentially the “schema” of the language. In Java I can’t just define a Person and embed nested properties at will, unless I just use Maps, at which point there is not structured schema. OrientDB follows this model. I can either just say EMBEDDEDMAP and have no structure or I can say EMBEDDED and specify another existing type.

Now in JavaScript we can do more interesting things. I can just do:

var person = {
  firstName: "john",
  lastName: "doe",
  address: {
    line1: "somehwere",
    city: "a place"
  }
}

Which is flexible, but there is no real schema to this.

My question is if really what we just want think about is having deep property definitions. Thinking like “There is a CLASS Foo. Foo has a property address.line1 which is a string.” I believe that EMBEDDED with a LINKED TYPE / CLASS is the wrong way to think about it. I think we could try some things

We can think about how we could store deeper paths in the parent class when defining properties. Imaging if we could do something like this:

CREATE CLASS Person;
CREATE PROPERTY Person.address EMBEDDED; (or CUSTOM or EMBEDDEDMAP, etc.)
CREATE PROPERTY Person.address.line1 STRING;

In this scenario there is no external embedded class anywhere. We are just extending the depth at which properties can be defined. Right now they can only be defined as <className>.<propertyName>. Here we do <className>.<propertyName>.<subPropertyName>. All of these mappings would be contained within the Person definition.

Then we could create syntax for doing this on create

CREATE CLASS Person (
firstName STRING,
lastName STRING,
Address EMBEDDED (
           Street STRING,
           City STRING,
           PostalCode STRING,
           Country STRING)
);

CREATE CLASS Company (
name STRING,
address EMBEDDED (
           Street STRING,
           City STRING,
           PostalCode STRING,
           Country STRING)
);

In neither case have we created a new class called Address. Both classes Person and Company have defined deeper sub properties.

There are a few things to work out, such as:

  1. If we drop a parent property all the sub properties would go away?
  2. If you try to define a sub property before the parent property, to we just assume the parent?
  3. Is there any through to deeper properties nested in an EMBEDDEDLIST?
0reactions
smolinaricommented, Jun 13, 2016

And then we could do this? <= it is a question. 😄

CREATE CLASS Person (
firstName STRING MANDATORY,
lastName STRING MANDATORY,
Address EMBEDDED (
           Street STRING MANDATORY,
           City STRING MANDATORY,
           PostalCode STRING MANDATORY,
           Country STRING MANDATORY)
);

If we drop a parent property all the sub properties would go away?

I’d say, yes.

If you try to define a sub property before the parent property, to we just assume the parent?

I don’t understand this question. How could or can you define a sub-property before the parent is created?

Is there any through to deeper properties nested in an EMBEDDEDLIST?

Like embedded lists that are embedded lists?

Scott

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - How to add property to a class dynamically?
First, without decorator notation. This may be more useful for the dynamic assignment of getters, setters, or deleters. Dynamic (a.k.a. Monkey ...
Read more >
Add-Member (Microsoft.PowerShell.Utility) - Microsoft Learn
The Add-Member cmdlet lets you add members (properties and methods) to an instance of a PowerShell object. For instance, you can add a...
Read more >
System Properties - Essential Java Classes
To modify the existing set of system properties, use System.setProperties . This method takes a Properties object that has been initialized to contain...
Read more >
Object.create() - JavaScript - MDN Web Docs
The Object.create() method creates a new object, using an existing object as the prototype of the newly created object.
Read more >
Python's property(): Add Managed Attributes to Your Classes
With property() , you can attach getter and setter methods to given class attributes. This way, you can handle the internal implementation for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found