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

Relations between objects #4

Closed
wants to merge 4 commits into from
Closed

Conversation

saromanov
Copy link
Contributor

I added experimental feature is linking(or relations) between objects like in graph databases.
It can be seen lika a puppet if this feature is necessary.
Usage:

    obj1 := &TestObject{
        ID:  "my-object",
        Foo: "abc",
    }
    obj2 := &TestObject{
        ID:  "my-cool-thing",
        Foo: "xyz",
    }

    obj3 := &TestObject{
        ID:  "my-other-cool-thing",
        Foo: "xyz",
    }

    err := txn.Insert("main", obj1)
    if err != nil {
        t.Fatalf("err: %v", err)
    }
    err = txn.Insert("main", obj2)
    if err != nil {
        t.Fatalf("err: %v", err)
    }
    err = txn.Insert("main", obj3)
    if err != nil {
        t.Fatalf("err: %v", err)
    }

      //Connect between to ID by attribute "Work"
    err = txn.Connect(&Link{
        Table:      "main",
        Index:      "id",
        Arg1:       obj1.ID,
        Arg2:       obj2.ID,
        Attributes: []string{"Work"},
    })

    err = txn.Connect(&Link{
        Table:      "main",
        Index:      "id",
        Arg1:       obj1.ID,
        Arg2:       obj3.ID,
        Attributes: []string{"Work"},
    })

    if err != nil {
        t.Fatalf("err: %v", err)
    }

    // Get links by attribute "Work" and ID from first objects. 
    // It must return two objects(obj2.ID and obj3.ID)
    res, errlinks := txn.GetLinks("main", "id", "Work", obj1.ID)
    if errlinks != nil {
        t.Fatalf("err: %v", errlinks)
    }

@armon
Copy link
Member

armon commented Nov 8, 2015

This is outside the scope of this library unfortunately. I would recommend forking the library if you need this functionality.

@armon armon closed this Nov 8, 2015
absolutelightning added a commit that referenced this pull request May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants