apache / incubator-hugegraph-toolchain

HugeGraph toolchain - include a series useful graph modules
https://hugegraph.apache.org/
Apache License 2.0
82 stars 87 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 #609

Closed 1280019840 closed 4 weeks ago

1280019840 commented 4 weeks 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 1717655653779 image

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

vertex := model.Vertex[any]{
        Label: "person",
        Properties: map[string]any{
            "name": "Alice",
            "age":  30,
        },
    }

    createResp, err := client.Vertex.Create(
        client.Vertex.Create.WithVertex(vertex),
    )
    if err != nil {
        fmt.Println(err)
    }
    fmt.Println("createResp: ", createResp.StatusCode)

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

No response

dosubot[bot] commented 4 weeks ago

To resolve the issue with the model package and correctly create a vertex using the Vertex struct in Go, you need to ensure that you import the model package correctly. The model package is an internal package in the HugeGraph toolchain. Here is how you can import it and use it to create a vertex:

  1. Import the model package:
import "hugegraph.apache.org/client-go/internal/model"
  1. Create a vertex using the model.Vertex struct:

Here is an example of how to create a vertex using the model.Vertex struct and the client.Vertex.Create method:

package main

import (
    "context"
    "fmt"
    "log"

    "hugegraph.apache.org/client-go/api"
    "hugegraph.apache.org/client-go/api/v1/vertex"
    "hugegraph.apache.org/client-go/internal/model"
)

func main() {
    // Initialize the transport (assuming you have a transport implementation)
    var transport api.Transport

    // Create a new Vertex client
    vertexClient := vertex.New(transport)

    // Define a new vertex
    newVertex := model.Vertex[any]{
        Label: "person",
        Properties: map[string]any{
            "name": "Alice",
            "age":  30,
        },
    }

    // Create the vertex
    createResp, err := vertexClient.Create(
        vertexClient.Create.WithContext(context.Background()),
        vertexClient.Create.WithVertex(newVertex),
    )
    if err != nil {
        log.Println("Error creating vertex:", err)
        return
    }

    // Print the created vertex response
    fmt.Println("createResp: ", createResp.StatusCode)
}

This example demonstrates how to import the model package, define a new vertex, and create it using the client.Vertex.Create method. Ensure that you have the correct import path for the model package and that your transport implementation is correctly set up.

For more details, you can refer to the HugeGraph-Client Quick Start Guide [1][2].

To continue talking to Dosu, mention @dosu.

1280019840 commented 4 weeks ago

import "hugegraph.apache.org/client-go/internal/model" Packet does not exist image