Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback from Insert Method #71

Open
aprelle opened this issue Jan 9, 2020 · 10 comments
Open

Feedback from Insert Method #71

aprelle opened this issue Jan 9, 2020 · 10 comments
Assignees

Comments

@aprelle
Copy link

aprelle commented Jan 9, 2020

In comparison to the other methods, e.g. update, insert does not deliver any result:

result = runtime.require('db').collections().Person.insert({
'_id': 'luke',
'firstName': 'Luke',
'lastName': 'Skywalker'
});

Here, result is always Array(0) [], whether an element was added or not. The only hint is a message:

runtime: unknown property 'XXX' for the definition of 'Person'
runtime: invalid document ....

Which I cannot catch (any hint how I can do it will be appreciated), since it is not an error.

Would it be possible to update the method, so it returns, e.g.

  • 1, when an element was successfully inserted,
  • 0, otherwise?
@ecarriou ecarriou self-assigned this Jan 9, 2020
@ecarriou
Copy link
Member

ecarriou commented Jan 9, 2020

Thank you for your suggestion!

ìnsert API returns an array with the _id of created document/component, empty array otherwise. I will update the documentation about that.

In your case example, if the model is valid, the result should return ['luke'].

It was a design choice not to raise an error during call to runtime APIs. The goal was to avoid script break and to have all the informations about errors in the log.

What I can do is to add some logs inside update, create and remove APIs, so you will get more informations when you call these APIs. I will probably put these logs at debug level, so to see them you will have juste to do:

runtime.require('logger').level('debug')

By the way, you can add this line in your current script to have more information about the model generation.

@aprelle
Copy link
Author

aprelle commented Jan 10, 2020

Thanks for a quick reply.

I think it is a good idea not to raise an error during call to runtime APIs. However, it should be a feedback with some information. Therefore it would be great to see some documentation about debug log levels. Right now runtime.require('logger').level('debug') returns undefinded.

As for insert method, it returns Array(0) [], whether an element was added or not. When I check my model, for example, I see an element was inserted, however the return value is an empty array. Exactly like the case, when an element was not added for this or that reason.

@ecarriou
Copy link
Member

ecarriou commented Jan 11, 2020

I will have a look on update, create and remove APIs to check if there is no issue, because the behavior you have is not correct one. I will also complete the online documentation about the signatures of these APIs.

runtime.require('logger').level('debug') returns nothing but it enables level of log to a specific level (debug / info / warn / error). If you had it at the beginning of your script (i.e. before metamodel.create()), you will get logs like these:

runtime: starting model creation...
runtime: generating model 'Jedi'...
runtime: analyzing model 'Jedi'...
runtime: 'Jedi' database collection created
runtime: 'Jedi' class created
runtime: model creation ended

ecarriou added a commit that referenced this issue Jan 11, 2020
ecarriou added a commit that referenced this issue Jan 11, 2020
@ecarriou
Copy link
Member

I have updated the library in order to fix an issue I have found with the insert API: the returned array does not contain id of document that already exist in collection. It may fix the behavior you had.

I have also update the online documentation.

@aprelle
Copy link
Author

aprelle commented Feb 11, 2020

Thanks for extending the documentation! I would add the case, with creation of references. It is clear how it is done, while creating components. However, it seems like it is not functioning the same way after a model was loaded:

// add reference
luke.father(anakin);

BTW insert was functioning properly. I was confused by documentation. I thought I have to create an instance firstly and then call the insert method. Therefore insert returned nothing back.

@ecarriou
Copy link
Member

You're welcome! And I will try to make the documentation clearer.

About the creation of references, you mean like in this example ? What differences have you between adding a reference in the object like:

new Jedi({
  '_id': 'luke',
  'firstName': 'Luke',
  'lastName': 'Skywalker',
  'father': 'anakin'
});

and by code like this:

const anakin = this.require('anakin');
luke.father(anakin);

@aprelle
Copy link
Author

aprelle commented Feb 24, 2020

Yes, this example is not functioning in my case for different types of models. I get the same error type each time. Here, how the error will look like for this example:

runtime: invalid value for property 'father' on component 'a7aaad61-f679-41a5-a61a-e0c94d63eb08' (class '<anakin>'): expected type 'number' instead of type '<luke>'

@ecarriou
Copy link
Member

ecarriou commented Mar 7, 2020

Can you give me a sample of the code that gives you that error ? So that I can fix the issue.

@aprelle
Copy link
Author

aprelle commented Mar 26, 2020

I think mixed up collections with links. So I tried to add an element to a collection with the method ment for adding links.

luke.father(anakin) -> add a link or reference
padme.children([luke, leia]); -> this method is not functioning. when there are already elements in the collection. No error comes. So I use : padme.children().push[luke) , which is functioning.

@ecarriou
Copy link
Member

ecarriou commented Apr 4, 2020

Hi,

I try this scripts (taken from the documentation), and it seems to work:

const system = runtime.system('example10');

const metamodel = runtime.require('metamodel');

metamodel.schema('Jedi', {
  'firstName': 'property',
  'lastName': 'property',
  'children': 'collection' 
});

metamodel.create();

const Jedi = runtime.require('Jedi');

new Jedi({
  '_id': 'leia',
  'firstName': 'Leia Amidala',
  'lastName': 'Skywalker'
});

new Jedi({
  '_id': 'luke',
  'firstName': 'Luke',
  'lastName': 'Skywalker'
});

new Jedi({
  '_id': 'padme',
  'firstName': 'Padme',
  'lastName': 'Amidala',
  'children': ['luke', 'leia']
});

system.on('start', () => {
  const padme = this.require('padme');
  const luke = this.require('luke');

  padme.children([luke]);

  console.log(padme.children(0).firstName());
});

system.start();

Maybe something is different in your script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants