calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [10/50] calcite-avatica-go git commit: Move schema to DSN path so that it follows the same schematics as the MySQL and PostgreSQL driver.
Date Fri, 11 Aug 2017 01:50:07 GMT
Move schema to DSN path so that it follows the same schematics as the MySQL and PostgreSQL
driver.


Project: http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/commit/4e1ded88
Tree: http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/tree/4e1ded88
Diff: http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/diff/4e1ded88

Branch: refs/heads/master
Commit: 4e1ded88f09f25163be7c9a6a9c738791a777c96
Parents: 9a364ff
Author: Francis Chuang <francis.chuang@boostport.com>
Authored: Fri Sep 30 10:40:58 2016 +1000
Committer: Julian Hyde <jhyde@apache.org>
Committed: Thu Aug 10 18:47:09 2017 -0700

----------------------------------------------------------------------
 README.md      | 16 ++++++++--------
 driver_test.go |  8 ++++----
 dsn.go         |  5 +++--
 dsn_test.go    |  6 +++---
 4 files changed, 18 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/blob/4e1ded88/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index f804dc0..42d04dc 100644
--- a/README.md
+++ b/README.md
@@ -35,10 +35,16 @@ rows := db.Query("SELECT COUNT(*) FROM test")
 The DSN has the following format (optional parts are marked by square brackets):
 
 ```
-http://address:ports[?parameter1=value&...parameterN=value]
+http://address:port[/schema][?parameter1=value&...parameterN=value]
 ```
 
-In other words, the scheme (http), address and port is mandatory, but the parameters are
optional.
+In other words, the scheme (http), address and port is mandatory, but the schema and parameters
are optional.
+
+#### schema
+The `schema` path sets the default schema to use for this connection. For example, if you
set it to `myschema`,
+then executing the query `SELECT * FROM my_table` will have the equivalence of `SELECT *
FROM myschema.my_table`.
+If schema is set, you can still work on tables in other schemas by supplying a schema prefix:
+`SELECT * FROM myotherschema.my_other_table`.
 
 The following parameters are supported:
 
@@ -47,12 +53,6 @@ The following parameters are supported:
 The `location` will be set as the location of unserialized `time.Time` values. It must be
a valid timezone.
 If you want to use the local timezone, use `Local`. By default, this is set to `UTC`.
 
-#### schema
-The `schema` parameter sets the default schema to use for this connection. For example, if
you set it to `myschema`,
-then executing the query `SELECT * FROM my_table` will have the equivalence of `SELECT *
FROM myschema.my_table`.
-If schema is set, you can still work on tables in other schemas by supplying a schema prefix:
-`SELECT * FROM myotherschema.my_other_table`.
-
 #### maxRowsTotal
 
 The `maxRowsTotal` parameter sets the maximum number of rows to return for a given query.
By default, this is set to

http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/blob/4e1ded88/driver_test.go
----------------------------------------------------------------------
diff --git a/driver_test.go b/driver_test.go
index 928b610..4cc1661 100644
--- a/driver_test.go
+++ b/driver_test.go
@@ -927,9 +927,9 @@ func TestSchemaSupport(t *testing.T) {
 	db.Exec("CREATE SCHEMA IF NOT EXISTS avaticatest")
 	defer db.Exec("DROP SCHEMA IF EXISTS avaticatest")
 
-	query := "?schema=avaticatest"
+	path := "/avaticatest"
 
-	runTests(t, dsn+query, func(dbt *DBTest) {
+	runTests(t, dsn+path, func(dbt *DBTest) {
 
 		// Create and seed table
 		dbt.mustExec(`CREATE TABLE ` + dbt.tableName + ` (
@@ -975,9 +975,9 @@ func TestMultipleSchemaSupport(t *testing.T) {
 	db.Exec("CREATE SCHEMA IF NOT EXISTS avaticatest2")
 	defer db.Exec("DROP SCHEMA IF EXISTS avaticatest2")
 
-	query := "?schema=avaticatest1"
+	path := "/avaticatest1"
 
-	runTests(t, dsn+query, func(dbt *DBTest) {
+	runTests(t, dsn+path, func(dbt *DBTest) {
 
 		// Create and seed table
 		dbt.mustExec(`CREATE TABLE avaticatest2.` + dbt.tableName + ` (

http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/blob/4e1ded88/dsn.go
----------------------------------------------------------------------
diff --git a/dsn.go b/dsn.go
index 2292bf3..d1cbad0 100644
--- a/dsn.go
+++ b/dsn.go
@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"net/url"
 	"strconv"
+	"strings"
 	"time"
 )
 
@@ -68,8 +69,8 @@ func ParseDSN(dsn string) (*Config, error) {
 		conf.location = loc
 	}
 
-	if v := queries.Get("schema"); v != "" {
-		conf.schema = v
+	if parsed.Path != "" {
+		conf.schema = strings.TrimPrefix(parsed.Path, "/")
 	}
 
 	if v := queries.Get("transactionIsolation"); v != "" {

http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/blob/4e1ded88/dsn_test.go
----------------------------------------------------------------------
diff --git a/dsn_test.go b/dsn_test.go
index 7c43786..6fce9da 100644
--- a/dsn_test.go
+++ b/dsn_test.go
@@ -8,14 +8,14 @@ import (
 
 func TestParseDSN(t *testing.T) {
 
-	config, err := ParseDSN("http://localhost:8765?maxRowsTotal=1&frameMaxSize=1&location=Australia/Melbourne&schema=myschema&transactionIsolation=8")
+	config, err := ParseDSN("http://localhost:8765/myschema?maxRowsTotal=1&frameMaxSize=1&location=Australia/Melbourne&transactionIsolation=8")
 
 	if err != nil {
 		t.Fatalf("Unexpected error: %s", err)
 	}
 
-	if config.endpoint != "http://localhost:8765" {
-		t.Errorf("Expected endpoint to be %s, got %s", "http://localhost:8765", config.endpoint)
+	if config.endpoint != "http://localhost:8765/myschema" {
+		t.Errorf("Expected endpoint to be %s, got %s", "http://localhost:8765/myschema", config.endpoint)
 	}
 
 	if config.frameMaxSize != 1 {


Mime
View raw message