Skip to content

Commit

Permalink
feat(020): readme, upgrade test env
Browse files Browse the repository at this point in the history
  • Loading branch information
aceforeverd committed Apr 23, 2024
1 parent 47f7565 commit 5f15d07
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
OPENMLDB_VERSION=0.8.4
OPENMLDB_VERSION=0.8.5
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
OpenMLDB Go SDK
------

Pure Go [OpenMLDB](https://github.com/4paradigm/OpenMLDB) driver for database/sql, connect via HTTP.

## Features

## Requirements

- OpenMLDB with all components version >= 0.6.2
- OpenMLDB API Server setted up

## Installation

```sh
go get github.com/4paradigm/openmldb-go-sdk
```

## Data Source Name (DSN)

```
openmldb://<API_SERVER_HOST>:<API_SERVER_PORT>/<DB_NAME>
```

For example, to open a database to `test_db` by api server at `127.0.0.1:8080`:
```go
db, err := sql.Open("openmldb", "openmldb://127.0.0.1:8080/test_db")
```

## Getting Start

```go
package main

import (
"context"
"database/sql"

_ "github.com/4paradigm/openmldb-go-sdk"
)

func main() {
db, err := sql.Open("openmldb", "openmldb://127.0.0.1:8080/test_db")
if err != nil {
panic(err)
}

defer db.Close()

ctx := context.Background()

// execute DDL
if _, err := db.ExecContext(ctx, `CREATE TABLE demo (c1 int, c2 string);`); err != nil {
panic(err)
}

// execute DML
if _, err := db.ExecContext(ctx, `INSERT INTO demo VALUES (1, "bb"), (2, "bb");`); err != nil {
panic(err)
}

// execute DQL
rows, err := db.QueryContext(ctx, `SELECT c1, c2 FROM demo;`)
if err != nil{
panic(err)
}

var col1 int
var col2 string

// iterating query result
for rows.Next() {
if err := rows.Scan(&col1, &col2); err != nil {
panic(err)
}
println(col1, col2)
}
}
```

0 comments on commit 5f15d07

Please sign in to comment.