Skip to content

Commit

Permalink
fix some typos (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanbohan committed Mar 18, 2024
1 parent 99663b9 commit 17a025d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,11 @@ err := tbl.AddRow(2, "127.0.0.2", time.Now())
resp, err := cli.Write(context.Background(), tbl)
```

##### Delete in GreptimeDB
##### Delete from GreptimeDB

```go
dtbl, err := table.New("<table_name>")
dtbl.AddTagColumn("id", types.INT64)
dtbl.AddFieldColumn("host", types.STRING)
dtbl.AddTimestampColumn("ts", types.TIMESTAMP_MILLISECOND)

// timestamp is the time you want to delete row
Expand All @@ -110,8 +109,9 @@ err := cli.StreamWrite(context.Background(), tbl)
...
affected, err := cli.CloseStream(ctx)
```
##### Stream Delete in GreptimeDB


##### Stream Delete from GreptimeDB

```go
err := cli.StreamDelete(context.Background(), tbl)
...
Expand Down
26 changes: 16 additions & 10 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ func NewClient(cfg *Config) (*Client, error) {
return &Client{cfg: cfg, client: client}, nil
}

// submit is create the request and send it to GreptimeDB.
// It is can set up the Operation as [INSERT,DELETE]
// submit is to build request and send it to GreptimeDB.
// The operations can be set:
// - INSERT
// - DELETE
func (c *Client) submit(ctx context.Context, operation types.Operation, tables ...*table.Table) (*gpb.GreptimeResponse, error) {
header_ := header.New(c.cfg.Database).WithAuth(c.cfg.Username, c.cfg.Password)
request_, err := request.New(header_, operation, tables...).Build()
Expand Down Expand Up @@ -143,7 +145,7 @@ func (c *Client) WriteObject(ctx context.Context, obj any) (*gpb.GreptimeRespons
}

// DeleteObject is like [Delete] to delete the data from GreptimeDB, but schema is defined in the struct tag.
// resp, err := client.WriteObject(context.Background(), deleteMonitors)
// resp, err := client.DeleteObject(context.Background(), deleteMonitors)
func (c *Client) DeleteObject(ctx context.Context, obj any) (*gpb.GreptimeResponse, error) {
tbl, err := schema.Parse(obj)
if err != nil {
Expand All @@ -153,7 +155,11 @@ func (c *Client) DeleteObject(ctx context.Context, obj any) (*gpb.GreptimeRespon
return c.submit(ctx, types.DELETE, tbl)
}

func (c *Client) streamSubimt(ctx context.Context, operation types.Operation, tables ...*table.Table) error {
// streamSubmit is to build stream request and send it to GreptimeDB.
// The operations can be set:
// - INSERT
// - DELETE
func (c *Client) streamSubmit(ctx context.Context, operation types.Operation, tables ...*table.Table) error {
if c.stream == nil {
stream, err := c.client.HandleRequests(ctx)
if err != nil {
Expand Down Expand Up @@ -186,7 +192,7 @@ func (c *Client) streamSubimt(ctx context.Context, operation types.Operation, ta
// // send data into GreptimeDB
// resp, err := client.StreamWrite(context.Background(), tbl)
func (c *Client) StreamWrite(ctx context.Context, tables ...*table.Table) error {
return c.streamSubimt(ctx, types.INSERT, tables...)
return c.streamSubmit(ctx, types.INSERT, tables...)
}

// StreamDelete is to delete the data from GreptimeDB via explicit schema.
Expand All @@ -201,9 +207,9 @@ func (c *Client) StreamWrite(ctx context.Context, tables ...*table.Table) error
// tbl.AddRow("tag1", timestamp)
//
// // delete the data from GreptimeDB
// resp, err := client.StreamWrite(context.Background(), tbl)
// resp, err := client.StreamDelete(context.Background(), tbl)
func (c *Client) StreamDelete(ctx context.Context, tables ...*table.Table) error {
return c.streamSubimt(ctx, types.DELETE, tables...)
return c.streamSubmit(ctx, types.DELETE, tables...)
}

// StreamWriteObject is like [StreamWrite] to send the data into GreptimeDB, but schema is defined in the struct tag.
Expand Down Expand Up @@ -249,17 +255,17 @@ func (c *Client) StreamWriteObject(ctx context.Context, body any) error {
if err != nil {
return err
}
return c.streamSubimt(ctx, types.INSERT, tbl)
return c.streamSubmit(ctx, types.INSERT, tbl)
}

// StreamDeleteObject is like [StreamDelete] to Delete the data from GreptimeDB, but schema is defined in the struct tag.
// resp, err := client.StreamWriteObject(context.Background(), deleteMonitors)
// resp, err := client.StreamDeleteObject(context.Background(), deleteMonitors)
func (c *Client) StreamDeleteObject(ctx context.Context, body any) error {
tbl, err := schema.Parse(body)
if err != nil {
return err
}
return c.streamSubimt(ctx, types.DELETE, tbl)
return c.streamSubmit(ctx, types.DELETE, tbl)
}

// CloseStream closes the stream. Once we’ve finished writing our client’s requests to the stream
Expand Down
7 changes: 5 additions & 2 deletions table/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,11 @@ func ConvertType(type_ ColumnType) (gpb.ColumnDataType, error) {

}

// Operation is the type of write operation
// current supported [Insert, Delete]
// Operation is to identify the operation type of the request.
// current supported:
// - Insert
// - Delete
//
// TODO: [Update]
type Operation uint

Expand Down

0 comments on commit 17a025d

Please sign in to comment.