Skip to content

Commit 5b7cfbb

Browse files
committed
Some fixes for couchbase
1 parent 0d2aca0 commit 5b7cfbb

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

contrib/couchbase/usql-config

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
DB="couchbase://localhost:8093"
2-
VSQL="select version() as version;"
1+
# NOTE: this will only work after setting up a database on http://localhost:8091/
2+
DB="couchbase://Administrator:P4ssw0rd@localhost"
3+
VSQL="select raw ds_version() as version;"

contrib/usqlpass

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ postgres:*:*:*:postgres:P4ssw0rd
66

77
cql:*:*:*:cassandra:cassandra
88
clickhouse:*:*:*:clickhouse:P4ssw0rd
9+
couchbase:*:*:*:Administrator:P4ssw0rd
910
godror:*:*:*:system:P4ssw0rd
1011
ignite:*:*:*:ignite:ignite
1112
mymysql:*:*:*:root:P4ssw0rd

drivers/couchbase/couchbase.go

+23
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package couchbase
55

66
import (
7+
"context"
8+
"strconv"
79
"strings"
810

911
_ "github.com/couchbase/go_n1ql" // DRIVER: n1ql
@@ -13,6 +15,27 @@ import (
1315
func init() {
1416
drivers.Register("n1ql", drivers.Driver{
1517
AllowMultilineComments: true,
18+
Version: func(ctx context.Context, db drivers.DB) (string, error) {
19+
ver := "<unknown>"
20+
/*
21+
var buf []byte
22+
if err := db.QueryRowContext(ctx, `SELECT ds_version() AS version`).Scan(&buf); err == nil {
23+
var m map[string]string
24+
if err := json.Unmarshal(buf, &m); err == nil {
25+
if s, ok := m["version"]; ok {
26+
ver = s
27+
}
28+
}
29+
}
30+
*/
31+
var v string
32+
if err := db.QueryRowContext(ctx, `SELECT RAW ds_version()`).Scan(&v); err == nil {
33+
if s, err := strconv.Unquote(v); err == nil {
34+
ver = s
35+
}
36+
}
37+
return "Couchbase " + ver, nil
38+
},
1639
Err: func(err error) (string, string) {
1740
return "", strings.TrimPrefix(err.Error(), "N1QL: ")
1841
},

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ require (
5555
github.com/trinodb/trino-go-client v0.313.0
5656
github.com/uber/athenadriver v1.1.15
5757
github.com/vertica/vertica-sql-go v1.3.3
58-
github.com/xo/dburl v0.21.1
58+
github.com/xo/dburl v0.22.0
5959
github.com/xo/tblfmt v0.12.0
6060
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e
6161
github.com/ydb-platform/ydb-go-sdk/v3 v3.57.4

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1005,8 +1005,8 @@ github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17
10051005
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
10061006
github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc=
10071007
github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU=
1008-
github.com/xo/dburl v0.21.1 h1:n5mfH1fh51RQbvuaKKykGslodt8pZqyZJMNohVo2zK0=
1009-
github.com/xo/dburl v0.21.1/go.mod h1:B7/G9FGungw6ighV8xJNwWYQPMfn3gsi2sn5SE8Bzco=
1008+
github.com/xo/dburl v0.22.0 h1:sO5WLm2ywMzyiLxEcLBlw5AyKvdR5hirq9U7s3fCoeM=
1009+
github.com/xo/dburl v0.22.0/go.mod h1:B7/G9FGungw6ighV8xJNwWYQPMfn3gsi2sn5SE8Bzco=
10101010
github.com/xo/tblfmt v0.0.0-20190609041254-28c54ec42ce8/go.mod h1:3U5kKQdIhwACye7ml3acccHmjGExY9WmUGU7rnDWgv0=
10111011
github.com/xo/tblfmt v0.12.0 h1:3nQGkyGiqzy+H9bcERrqmiK2pSpQKkjn/f5D8oeXSqI=
10121012
github.com/xo/tblfmt v0.12.0/go.mod h1:AKivZTttxEXXrztqGl0dGVh4hsEOSGIfSZNbRhnKZuo=

0 commit comments

Comments
 (0)