apache / incubator-hugegraph-toolchain

HugeGraph toolchain - include a series useful graph modules
https://hugegraph.apache.org/
Apache License 2.0
88 stars 92 forks source link

Model is an internal package model, how should I create it Create a model when using Vertex Using Vertex [any] as a parameter, call Vertex What about Create. WithVertex #610

Closed 1280019840 closed 2 months ago

1280019840 commented 3 months ago

Problem Type (问题类型)

configs (配置项 / 文档相关)

Before submit

Environment (环境信息)

Your Question (问题描述)

Model is an internal package model, how should I create it Create a model when using Vertex Using Vertex [any] as a parameter, call Vertex What about Create. WithVertex image image

Vertex/Edge example (问题点 / 边数据举例)

No response

Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)

No response

dosubot[bot] commented 3 months ago

To properly create and use the model.Vertex in your Go project, you need to ensure that you import the model package correctly. The "undeclared name: model" compilation error indicates that the model package is not recognized in your current file.

Here is an example of how you can import and use the model.Vertex struct:

  1. Import the model package at the beginning of your Go file.
  2. Create an instance of model.Vertex.

Assuming your project structure is as follows:

your_project/
├── main.go
└── hugegraph-client-go/
    └── internal/
        └── model/
            └── model.go

Your main.go file should look something like this:

package main

import (
    "fmt"
    "your_project/hugegraph-client-go/internal/model"
)

func main() {
    // Example of creating a Vertex with properties of type map[string]interface{}
    vertex := model.Vertex[map[string]interface{}]{
        ID:    "1",
        Label: "person",
        Properties: map[string]interface{}{
            "name": "John Doe",
            "age":  30,
        },
    }

    fmt.Printf("Vertex: %+v\n", vertex)
}

In this example:

Make sure the import path matches the actual location of your model package. Adjust the import path if your project structure is different.

Additionally, if you are using the hugegraph-client-go library, you might need to import the vertex package and use its functions to create and manipulate vertices. Here is an example:

package main

import (
    "context"
    "fmt"
    "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/api"
    "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/api/v1/vertex"
    "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/internal/model"
)

type Person struct {
    Name string `json:"name,omitempty"`
    Age  uint64 `json:"age,omitempty"`
    City string `json:"city,omitempty"`
}

func main() {
    transport := api.NewTransport(api.Config{
        Graph: "your_graph",
    })

    vertexClient := vertex.New(transport)

    // Create a new vertex
    person := Person{
        Name: "John Doe",
        Age:  30,
        City: "New York",
    }

    createResp, err := vertexClient.Create(
        vertexClient.Create.WithContext(context.Background()),
        vertexClient.Create.WithVertex(model.Vertex[any]{
            Label:      "person",
            Properties: person,
        }),
    )
    if err != nil {
        fmt.Println("Error creating vertex:", err)
        return
    }

    fmt.Printf("Created Vertex: %+v\n", createResp.Data)
}

In this example:

Ensure that you have the correct import paths and that the hugegraph-client-go library is properly installed in your project [1][2][3].

To continue talking to Dosu, mention @dosu.

izliang commented 3 months ago

I am aware of this issue, please give me some time. I plan to reorganize the logic and design a more user-friendly SDK.

github-actions[bot] commented 3 months ago

Due to the lack of activity, the current issue is marked as stale and will be closed after 20 days, any update will remove the stale label