@@ -5,6 +5,12 @@ Pure Go [OpenMLDB](https://github.com/4paradigm/OpenMLDB) driver for database/sq
55
66## Features  
77
8+ -  Lightweight
9+ -  Pure Go implementation, No C-bindings
10+ -  Connection over HTTP
11+ -  Full OpenMLDB SQL support, work with online and offline mode
12+ -  Numeric, bool, string, date, timestamp data type support
13+ 
814## Requirements  
915
1016-  OpenMLDB with all components version >= 0.6.2
@@ -19,7 +25,7 @@ go get github.com/4paradigm/openmldb-go-sdk
1925## Data Source Name (DSN)  
2026
2127``` 
22- openmldb://<API_SERVER_HOST>:<API_SERVER_PORT>/<DB_NAME> 
28+ openmldb://<API_SERVER_HOST>:<API_SERVER_PORT>/<DB_NAME>?mode=<MODE_NAME>  
2329``` 
2430
2531For example, to open a database to ` test_db `  by api server at ` 127.0.0.1:8080 ` :
@@ -28,6 +34,60 @@ db, err := sql.Open("openmldb", "openmldb://127.0.0.1:8080/test_db")
2834``` 
2935
3036` <DB_NAME> `  is mandatory in DSN, and at this time (version 0.2.0), you must ensure the database ` <DB_NAME> `  created before open go connection.
37+ DSN parameters (the ` ?mode=<MODE_NAME> `  part) are optional.
38+ 
39+ 
40+ ### Query Mode (Optional)  
41+ 
42+ The execution mode for OpenMLDB, defined as ` mode=<MODE_NAME> ` , default to ` online ` , available values are:
43+ -  ` online ` : online preview mode
44+ -  ` offsync ` : offline mode with system variable ` sync_job = true ` 
45+ -  ` offasync ` : offline mode with system variable ` sync_job = false ` 
46+ 
47+ 
48+ ## Data type support  
49+ 
50+ int16, int32, int64, float, double, bool, date, timestamp and string types in OpenMLDB SQL are supported.
51+ Since Go types are flexible by design, you may choose any type in Go by your favor, as long as that type implements
52+ [ sql#Scanner] ( https://pkg.go.dev/database/sql#Scanner )  interface.
53+ 
54+ For example, a SQL string type, can be represented in Go with ` string ` , ` sql.NullString ` , ` sql.Null[string] ` , ` string `  is able
55+ to represent SQL string when it is not NULL, error reported if you want to save a NULL value into string, while the later two types
56+ are able to save all SQL string, regardless nullable:
57+ 
58+ ``` go 
59+ import  (
60+   " database/sql" 
61+ )
62+ 
63+ //  ...
64+ 
65+ {
66+   var  s  string 
67+   err  :=  db.QueryRow (" SELECT name FROM foo WHERE id=?"  , id).Scan (&s)
68+   //  err returned from Scan if NULL value returned from query
69+ }
70+ 
71+ 
72+ {
73+   var  s  sql.NullString 
74+   err  :=  db.QueryRow (" SELECT name FROM foo WHERE id=?"  , id).Scan (&s)
75+   //  NullString is safe for query returns NULL
76+   //  ...
77+ 
78+   if  s.Valid  {
79+     //  use s.String
80+   } else  {
81+     //  NULL value
82+   }
83+ }
84+ ``` 
85+ 
86+ ### Timestamp and date support  
87+ 
88+ We use ` time.Time `  internally represents SQL timestamp and date type, so you can choose whatever type that is
89+ scannable from ` time.Time ` , like ` sql.NullTime ` , or simply ` time.Time `  itself.
90+ 
3191
3292## Getting Start  
3393
0 commit comments