-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
47f7565
commit 5f15d07
Showing
2 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
OPENMLDB_VERSION=0.8.4 | ||
OPENMLDB_VERSION=0.8.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
``` |