From c046517bff1b6531ff1c71c4d0ac9fec7900df75 Mon Sep 17 00:00:00 2001 From: aceforeverd Date: Tue, 23 Apr 2024 19:15:59 +0800 Subject: [PATCH] feat(020): readme, upgrade test env (#5) --- .env | 2 +- README.md | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 README.md diff --git a/.env b/.env index 74160e9..7742fe0 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -OPENMLDB_VERSION=0.8.4 +OPENMLDB_VERSION=0.8.5 diff --git a/README.md b/README.md new file mode 100644 index 0000000..de761a6 --- /dev/null +++ b/README.md @@ -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://:/ +``` + +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) + } +} +```