orientjs icon indicating copy to clipboard operation
orientjs copied to clipboard

select one() does not throw error on multiple or no results

Open creisle opened this issue 7 years ago • 1 comments

orientjs version: 2.2.3 orientdb version: 2.2.17 os: centos06 node version: v6.10.0

I'm not sure if this is expected behavior or not as I was unable to find any documentation in orientjs regarding this situation specifically.

From other query builders I've often seen the <query>.one() function (i.e. something like http://docs.sqlalchemy.org/en/latest/orm/query.html#sqlalchemy.orm.query.Query.one) . Generally I would expect that if the query were to return multiple (2 or more) records, or if the query did not return any records this would result in an error being thrown.

In orientjs neither situation results in an error being thrown

for example (assume I've already set up a db connection)

db.create('VERTEX', 'V').all()
            .then(() => {
                return db.create('VERTEX', 'V').all();
            }).then(() => {
                return db.select().from('V').one();  // expected this to throw an error
            }).then((result) => {
                console.log(result);
                return db.select().from('V').all()
                    .then((reclist) => {
                        console.log('all', reclist);
                    });
            });

when the query does not find any records "result" is undefined

is this expected behavior?

creisle avatar May 10 '17 21:05 creisle

hi @creisle

yes this is expected behavior. It always has been in this way. I guess we cannot change it now that would lead to a breaking changes. Maybe in 3.0 we can do this. I will mark this as enhancement

Thanks

wolf4ood avatar May 11 '17 10:05 wolf4ood