Adding new properties with the CREATE CLASS command.
See original GitHub issueHi,
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:
- Created 8 years ago
- Comments:8 (8 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:
If I want a Person to have an address, I could do this:
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.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:
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:
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
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:
And then we could do this? <= it is a question. 😄
I’d say, yes.
I don’t understand this question. How could or can you define a sub-property before the parent is created?
Like embedded lists that are embedded lists?
Scott