Skip to content

Commit 45272df

Browse files
committed
Usage, connection via DSN, connection via connector
Signed-off-by: Matthew Kim <[email protected]>
1 parent 0b7f22f commit 45272df

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

doc.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,82 @@
11
/*
22
Package dbsql implements the go driver to Databricks SQL
3+
4+
# Usage
5+
6+
Clients should use the database/sql package in conjunction with the driver:
7+
8+
import (
9+
"database/sql"
10+
11+
_ "github.com/databricks/databricks-sql-go"
12+
)
13+
14+
func main() {
15+
db, err := sql.Open("databricks", "token:<token>@<hostname>:<port>/<endpoint_path>")
16+
17+
if err != nil {
18+
log.Fatal(err)
19+
}
20+
defer db.Close()
21+
}
22+
23+
# Connection via DSN (Data Source Name)
24+
25+
Use sql.Open() to create a database handle via a data source name string:
26+
27+
db, err := sql.Open("databricks", "<dsn_string>")
28+
29+
The DSN format is:
30+
31+
token:[my_token]@[hostname]:[port]/[endpoint http path]?param=value
32+
33+
Supported optional connection parameters can be specified in param=value and include:
34+
35+
- catalog: Sets the initial catalog name in the session
36+
- schema: Sets the initial schema name in the session
37+
- maxRows: Sets up the max rows fetched per request. Default is 10000
38+
- timeout: Adds timeout (in seconds) for the server query execution. Default is no timeout
39+
- userAgentEntry: Used to identify partners. Set as a string with format <isv-name+product-name>
40+
41+
Supported optional session parameters can be specified in param=value and include:
42+
43+
- ansi_mode: (Boolean string). Session statements will adhere to rules defined by ANSI SQL specification. Default is "false"
44+
- timezone: (e.g. "America/Los_Angeles"). Sets the timezone of the session
45+
46+
# Connection via new connector object
47+
48+
Use sql.OpenDB() to create a database handle via a new connector object created with dbsql.NewConnector():
49+
50+
import (
51+
"database/sql"
52+
dbsql "github.com/databricks/databricks-sql-go"
53+
)
54+
55+
func main() {
56+
connector, err := dbsql.NewConnector(
57+
dbsql.WithServerHostname(<hostname>),
58+
dbsql.WithPort(<port>),
59+
dbsql.WithHTTPPath(<http_path>),
60+
dbsql.WithAccessToken(<my_token>)
61+
)
62+
if err != nil {
63+
log.Fatal(err)
64+
}
65+
defer db.close()
66+
}
67+
68+
db := sql.OpenDB(connector)
69+
70+
Supported functional options include:
71+
72+
- WithServerHostname(<hostname> string): Sets up the server hostname. Mandatory
73+
- WithPort(<port> int): Sets up the server port. Mandatory
74+
- WithAccessToken(<my_token> string): Sets up the Personal Access Token. Mandatory
75+
- WithHTTPPath(<http_path> string): Sets up the endpoint to the warehouse. Mandatory
76+
- WithInitialNamespace(<catalog> string, <schema> string): Sets up the catalog and schema name in the session. Optional
77+
- WithMaxRows(<max_rows> int): Sets up the max rows fetched per request. Default is 10000. Optional
78+
- WithSessionParams(<params_map> map[string]string): Sets up session parameters including "timezone" and "ansi_mode". Optional
79+
- WithTimeout(<timeout> Duration). Adds timeout (in time.Duration) for the server query execution. Default is no timeout. Optional
80+
- WithUserAgentEntry(<isv-name+product-name> string). Used to identify partners. Optional
381
*/
482
package dbsql

0 commit comments

Comments
 (0)