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

how to check is exists before creating edge #8830

Closed
grimace opened this issue Mar 31, 2019 · 3 comments
Closed

how to check is exists before creating edge #8830

grimace opened this issue Mar 31, 2019 · 3 comments
Assignees
Labels

Comments

@grimace
Copy link

grimace commented Mar 31, 2019

OrientDB Version: 3.0.17

Java Version: JDK 8.x

OS: ubuntu 18.x

Expected behavior

would like to only create one edge, but need to check if exists first

Actual behavior

just don't know how to do this

Steps to reproduce

something like:
CREATE EDGE E FROM #22:33 TO #22:55 IF NOT EXISTS

@grimace grimace changed the title how to check is exits before creating edge how to check is exists before creating edge Mar 31, 2019
@luigidellaquila
Copy link
Member

Hi @grimace

You can do it in a single statement with CREATE EDGE UPSERT:

CREATE EDGE E UPSERT FROM #22:33 TO #22:55 

The UPSERT requires a UNIQUE index on EdgeClass[out, in] and only checks if the edge exists between the two vertices (it doesn't check other properties)

docs here:

https://orientdb.com/docs/3.0.x/sql/SQL-Create-Edge.html

Thanks

Luigi

@grimace
Copy link
Author

grimace commented Apr 1, 2019

Thank you!

@grimace grimace closed this as completed Apr 1, 2019
@grimace grimace reopened this May 1, 2019
@grimace
Copy link
Author

grimace commented May 1, 2019

Why do I get this exception while trying to create an edge?

Relationship content is invalid on field in_OwnsContent. Found: {delegate={entries=[#303:0]}}

I don't think I'm trying to set any properties on the Edge.

here's how I'm executing the create/upsert:

              res.locals.db.create("EDGE", "OwnsContent", "UPSERT")
                .from(repo_id).to(rid)
                .one()
                .then(edge => {
                    console.log('created edge from repo to article : '+edge);
                    cb(edge);
                });

cb is a callback in nodejs...

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

No branches or pull requests

3 participants