Documentation ¶
Overview ¶
Example (Cert) ¶
c := newCLITest(cliTestParams{}) defer c.cleanup() c.RunWithCAArgs([]string{"cert", "create-client", "foo"}) c.RunWithCAArgs([]string{"cert", "create-client", "Ομηρος"}) c.RunWithCAArgs([]string{"cert", "create-client", "0foo"})
Output: cert create-client foo cert create-client Ομηρος cert create-client 0foo failed to generate client certificate and key: username "0foo" invalid; usernames are case insensitive, must start with a letter or underscore, may contain letters, digits or underscores, and must not exceed 63 characters
Example (In_memory) ¶
spec, err := base.NewStoreSpec("type=mem,size=1GiB") if err != nil { panic(err) } c := newCLITest(cliTestParams{ storeSpecs: []base.StoreSpec{spec}, }) defer c.cleanup() // Test some sql to ensure that the in memory store is working. c.RunWithArgs([]string{"sql", "-e", "create database t; create table t.f (x int, y int); insert into t.f values (42, 69)"}) c.RunWithArgs([]string{"node", "ls"})
Output: sql -e create database t; create table t.f (x int, y int); insert into t.f values (42, 69) INSERT 1 node ls id 1 # 1 row
Example (Logging) ¶
c := newCLITest(cliTestParams{}) defer c.cleanup() c.RunWithArgs([]string{"sql", "--logtostderr=false", "-e", "select 1"}) c.RunWithArgs([]string{"sql", "--log-backtrace-at=foo.go:1", "-e", "select 1"}) c.RunWithArgs([]string{"sql", "--log-dir=", "-e", "select 1"}) c.RunWithArgs([]string{"sql", "--logtostderr=true", "-e", "select 1"}) c.RunWithArgs([]string{"sql", "--verbosity=0", "-e", "select 1"}) c.RunWithArgs([]string{"sql", "--vmodule=foo=1", "-e", "select 1"})
Output: sql --logtostderr=false -e select 1 1 1 # 1 row sql --log-backtrace-at=foo.go:1 -e select 1 1 1 # 1 row sql --log-dir= -e select 1 1 1 # 1 row sql --logtostderr=true -e select 1 1 1 # 1 row sql --verbosity=0 -e select 1 1 1 # 1 row sql --vmodule=foo=1 -e select 1 1 1 # 1 row
Example (Max_results) ¶
c := newCLITest(cliTestParams{}) defer c.cleanup() c.Run("debug range split max_results3") c.Run("debug range split max_results4") c.Run("debug range ls --max-results=5")
Output: debug range split max_results3 debug range split max_results4 debug range ls --max-results=5 /Min-/System/"" [1] 0: node-id=1 store-id=1 /System/""-/System/NodeLiveness [2] 0: node-id=1 store-id=1 /System/NodeLiveness-/System/NodeLivenessMax [3] 0: node-id=1 store-id=1 /System/NodeLivenessMax-/System/tsd [4] 0: node-id=1 store-id=1 /System/tsd-/System/"tse" [5] 0: node-id=1 store-id=1 5 result(s)
Example (Node) ¶
c := newCLITest(cliTestParams{}) defer c.cleanup() // Refresh time series data, which is required to retrieve stats. if err := c.WriteSummaries(); err != nil { log.Fatalf(context.Background(), "Couldn't write stats summaries: %s", err) } c.Run("node ls") c.Run("node ls --format=pretty") c.Run("node status 10000")
Output: node ls id 1 # 1 row node ls --format=pretty +----+ | id | +----+ | 1 | +----+ (1 row) node status 10000 Error: node 10000 doesn't exist
Example (Ranges) ¶
c := newCLITest(cliTestParams{}) defer c.cleanup() c.Run("debug range split ranges3") c.Run("debug range ls")
Output: debug range split ranges3 debug range ls /Min-/System/"" [1] 0: node-id=1 store-id=1 /System/""-/System/NodeLiveness [2] 0: node-id=1 store-id=1 /System/NodeLiveness-/System/NodeLivenessMax [3] 0: node-id=1 store-id=1 /System/NodeLivenessMax-/System/tsd [4] 0: node-id=1 store-id=1 /System/tsd-/System/"tse" [5] 0: node-id=1 store-id=1 /System/"tse"-"ranges3" [6] 0: node-id=1 store-id=1 "ranges3"-/Table/SystemConfigSpan/Start [17] 0: node-id=1 store-id=1 /Table/SystemConfigSpan/Start-/Table/11 [7] 0: node-id=1 store-id=1 /Table/11-/Table/12 [8] 0: node-id=1 store-id=1 /Table/12-/Table/13 [9] 0: node-id=1 store-id=1 /Table/13-/Table/14 [10] 0: node-id=1 store-id=1 /Table/14-/Table/15 [11] 0: node-id=1 store-id=1 /Table/15-/Table/16 [12] 0: node-id=1 store-id=1 /Table/16-/Table/17 [13] 0: node-id=1 store-id=1 /Table/17-/Table/18 [14] 0: node-id=1 store-id=1 /Table/18-/Table/19 [15] 0: node-id=1 store-id=1 /Table/19-/Max [16] 0: node-id=1 store-id=1 17 result(s)
Example (Sql) ¶
c := newCLITest(cliTestParams{}) defer c.cleanup() c.RunWithArgs([]string{"sql", "-e", "show application_name"}) c.RunWithArgs([]string{"sql", "-e", "create database t; create table t.f (x int, y int); insert into t.f values (42, 69)"}) c.RunWithArgs([]string{"sql", "-e", "delete from t.f"}) c.RunWithArgs([]string{"sql", "-e", "select 3", "-e", "select * from t.f"}) c.RunWithArgs([]string{"sql", "-e", "begin", "-e", "select 3", "-e", "commit"}) c.RunWithArgs([]string{"sql", "-e", "select * from t.f"}) c.RunWithArgs([]string{"sql", "--execute=show databases"}) c.RunWithArgs([]string{"sql", "-e", "select 1; select 2"}) c.RunWithArgs([]string{"sql", "-e", "select 1; select 2 where false"}) // It must be possible to access pre-defined/virtual tables even if the current database // does not exist yet. c.RunWithArgs([]string{"sql", "-d", "nonexistent", "-e", "select count(*) from pg_class limit 0"}) // It must be possible to create the current database after the // connection was established. c.RunWithArgs([]string{"sql", "-d", "nonexistent", "-e", "create database nonexistent; create table foo(x int); select * from foo"}) // COPY should return an intelligible error message. c.RunWithArgs([]string{"sql", "-e", "copy t.f from stdin"}) // --echo-sql should print out the SQL statements. c.RunWithArgs([]string{"user", "ls", "--echo-sql"})
Output: sql -e show application_name application_name cockroach # 1 row sql -e create database t; create table t.f (x int, y int); insert into t.f values (42, 69) INSERT 1 sql -e delete from t.f pq: rejected: DELETE without WHERE clause (sql_safe_updates = true) sql -e select 3 -e select * from t.f 3 3 # 1 row x y 42 69 # 1 row sql -e begin -e select 3 -e commit BEGIN 3 3 # 1 row COMMIT sql -e select * from t.f x y 42 69 # 1 row sql --execute=show databases Database crdb_internal information_schema pg_catalog system t # 5 rows sql -e select 1; select 2 1 1 # 1 row 2 2 # 1 row sql -e select 1; select 2 where false 1 1 # 1 row 2 # 0 rows sql -d nonexistent -e select count(*) from pg_class limit 0 count(*) # 0 rows sql -d nonexistent -e create database nonexistent; create table foo(x int); select * from foo x # 0 rows sql -e copy t.f from stdin woops! COPY has confused this client! Suggestion: use 'psql' for COPY user ls --echo-sql > SELECT username FROM system.users username # 0 rows
Example (Sql_column_labels) ¶
c := newCLITest(cliTestParams{}) defer c.cleanup() c.RunWithArgs([]string{"sql", "-e", "create database t; create table t.u (\"\"\"foo\" int, \"\\foo\" int, \"foo\nbar\" int, \"κόσμε\" int, \"a|b\" int, \"܈85\" int)"}) c.RunWithArgs([]string{"sql", "-e", "insert into t.u values (0, 0, 0, 0, 0, 0)"}) c.RunWithArgs([]string{"sql", "-e", "show columns from t.u"}) c.RunWithArgs([]string{"sql", "-e", "select * from t.u"}) c.RunWithArgs([]string{"sql", "--format=pretty", "-e", "show columns from t.u"}) c.RunWithArgs([]string{"sql", "--format=pretty", "-e", "select * from t.u"}) c.RunWithArgs([]string{"sql", "--format=tsv", "-e", "select * from t.u"}) c.RunWithArgs([]string{"sql", "--format=csv", "-e", "select * from t.u"}) c.RunWithArgs([]string{"sql", "--format=sql", "-e", "select * from t.u"}) c.RunWithArgs([]string{"sql", "--format=html", "-e", "select * from t.u"}) c.RunWithArgs([]string{"sql", "--format=records", "-e", "select * from t.u"})
Output: sql -e create database t; create table t.u ("""foo" int, "\foo" int, "foo bar" int, "κόσμε" int, "a|b" int, "܈85" int) CREATE TABLE sql -e insert into t.u values (0, 0, 0, 0, 0, 0) INSERT 1 sql -e show columns from t.u Field Type Null Default Indices """foo" INT true NULL {} \foo INT true NULL {} "foo bar" INT true NULL {} κόσμε INT true NULL {} a|b INT true NULL {} ܈85 INT true NULL {} # 6 rows sql -e select * from t.u """foo" \foo """foo\nbar""" κόσμε a|b ܈85 0 0 0 0 0 0 # 1 row sql --format=pretty -e show columns from t.u +---------+------+------+---------+---------+ | Field | Type | Null | Default | Indices | +---------+------+------+---------+---------+ | "foo | INT | true | NULL | {} | | \foo | INT | true | NULL | {} | | foo | INT | true | NULL | {} | | bar | | | | | | κόσμε | INT | true | NULL | {} | | a|b | INT | true | NULL | {} | | ܈85 | INT | true | NULL | {} | +---------+------+------+---------+---------+ (6 rows) sql --format=pretty -e select * from t.u +------+------+------------+-------+-----+-----+ | "foo | \foo | "foo\nbar" | κόσμε | a|b | ܈85 | +------+------+------------+-------+-----+-----+ | 0 | 0 | 0 | 0 | 0 | 0 | +------+------+------------+-------+-----+-----+ (1 row) sql --format=tsv -e select * from t.u """foo" \foo """foo\nbar""" κόσμε a|b ܈85 0 0 0 0 0 0 # 1 row sql --format=csv -e select * from t.u """foo",\foo,"""foo\nbar""",κόσμε,a|b,܈85 0,0,0,0,0,0 # 1 row sql --format=sql -e select * from t.u CREATE TABLE results ( """foo" STRING, "\foo" STRING, """foo\nbar""" STRING, "κόσμε" STRING, "a|b" STRING, ܈85 STRING ); INSERT INTO results VALUES ('0', '0', '0', '0', '0', '0'); sql --format=html -e select * from t.u <table> <thead><tr><th>row</th><th>"foo</th><th>\foo</th><th>"foo\nbar"</th><th>κόσμε</th><th>a|b</th><th>܈85</th></tr></head> <tbody> <tr><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr> </tbody> <tfoot><tr><td colspan=7>1 row</td></tr></tfoot></table> sql --format=records -e select * from t.u -[ RECORD 1 ] "foo | 0 \foo | 0 "foo\nbar" | 0 κόσμε | 0 a|b | 0 ܈85 | 0
Example (Sql_empty_table) ¶
c := newCLITest(cliTestParams{}) defer c.cleanup() c.RunWithArgs([]string{"sql", "-e", "create database t;" + "create table t.norows(x int);" + "create table t.nocolsnorows();" + "create table t.nocols(); insert into t.nocols(rowid) values (1),(2),(3);"}) for _, table := range []string{"norows", "nocols", "nocolsnorows"} { for _, format := range []string{"pretty", "tsv", "csv", "sql", "html", "raw", "records"} { c.RunWithArgs([]string{"sql", "--format=" + format, "-e", "select * from t." + table}) } }
Output: sql -e create database t;create table t.norows(x int);create table t.nocolsnorows();create table t.nocols(); insert into t.nocols(rowid) values (1),(2),(3); INSERT 3 sql --format=pretty -e select * from t.norows +---+ | x | +---+ +---+ (0 rows) sql --format=tsv -e select * from t.norows x # 0 rows sql --format=csv -e select * from t.norows x # 0 rows sql --format=sql -e select * from t.norows CREATE TABLE results ( x STRING ); sql --format=html -e select * from t.norows <table> <thead><tr><th>row</th><th>x</th></tr></head> </tbody> <tfoot><tr><td colspan=2>0 rows</td></tr></tfoot></table> sql --format=raw -e select * from t.norows # 1 column # 0 rows sql --format=records -e select * from t.norows sql --format=pretty -e select * from t.nocols -- (3 rows) sql --format=tsv -e select * from t.nocols # no columns # empty # empty # empty # 3 rows sql --format=csv -e select * from t.nocols # no columns # empty # empty # empty # 3 rows sql --format=sql -e select * from t.nocols CREATE TABLE results ( ); INSERT INTO results(rowid) VALUES (DEFAULT); INSERT INTO results(rowid) VALUES (DEFAULT); INSERT INTO results(rowid) VALUES (DEFAULT); sql --format=html -e select * from t.nocols <table> <thead><tr><th>row</th></tr></head> <tbody> <tr><td>1</td></tr> <tr><td>2</td></tr> <tr><td>3</td></tr> </tbody> <tfoot><tr><td colspan=1>3 rows</td></tr></tfoot></table> sql --format=raw -e select * from t.nocols # 0 columns # row 1 # row 2 # row 3 # 3 rows sql --format=records -e select * from t.nocols (3 rows) sql --format=pretty -e select * from t.nocolsnorows -- (0 rows) sql --format=tsv -e select * from t.nocolsnorows # no columns # 0 rows sql --format=csv -e select * from t.nocolsnorows # no columns # 0 rows sql --format=sql -e select * from t.nocolsnorows CREATE TABLE results ( ); sql --format=html -e select * from t.nocolsnorows <table> <thead><tr><th>row</th></tr></head> </tbody> <tfoot><tr><td colspan=1>0 rows</td></tr></tfoot></table> sql --format=raw -e select * from t.nocolsnorows # 0 columns # 0 rows sql --format=records -e select * from t.nocolsnorows (0 rows)
Example (Sql_format) ¶
c := newCLITest(cliTestParams{}) defer c.cleanup() c.RunWithArgs([]string{"sql", "-e", "create database t; create table t.times (bare timestamp, withtz timestamptz)"}) c.RunWithArgs([]string{"sql", "-e", "insert into t.times values ('2016-01-25 10:10:10', '2016-01-25 10:10:10-05:00')"}) c.RunWithArgs([]string{"sql", "-e", "select * from t.times"})
Output: sql -e create database t; create table t.times (bare timestamp, withtz timestamptz) CREATE TABLE sql -e insert into t.times values ('2016-01-25 10:10:10', '2016-01-25 10:10:10-05:00') INSERT 1 sql -e select * from t.times bare withtz 2016-01-25 10:10:10+00:00 2016-01-25 15:10:10+00:00 # 1 row
Example (Sql_table) ¶
c := newCLITest(cliTestParams{}) defer c.cleanup() c.RunWithArgs([]string{"sql", "-e", "create database t; create table t.t (s string, d string);"}) c.RunWithArgs([]string{"sql", "-e", "insert into t.t values (e'foo', 'printable ASCII')"}) c.RunWithArgs([]string{"sql", "-e", "insert into t.t values (e'\"foo', 'printable ASCII with quotes')"}) c.RunWithArgs([]string{"sql", "-e", "insert into t.t values (e'\\\\foo', 'printable ASCII with backslash')"}) c.RunWithArgs([]string{"sql", "-e", "insert into t.t values (e'foo\\x0abar', 'non-printable ASCII')"}) c.RunWithArgs([]string{"sql", "-e", "insert into t.t values ('κόσμε', 'printable UTF8')"}) c.RunWithArgs([]string{"sql", "-e", "insert into t.t values (e'\\xc3\\xb1', 'printable UTF8 using escapes')"}) c.RunWithArgs([]string{"sql", "-e", "insert into t.t values (e'\\x01', 'non-printable UTF8 string')"}) c.RunWithArgs([]string{"sql", "-e", "insert into t.t values (e'\\xdc\\x88\\x38\\x35', 'UTF8 string with RTL char')"}) c.RunWithArgs([]string{"sql", "-e", "insert into t.t values (e'\\xc3\\x28', 'non-UTF8 string')"}) c.RunWithArgs([]string{"sql", "-e", "insert into t.t values (e'a\\tb\\tc\\n12\\t123123213\\t12313', 'tabs')"}) c.RunWithArgs([]string{"sql", "-e", "select * from t.t"}) c.RunWithArgs([]string{"sql", "--format=pretty", "-e", "select * from t.t"}) c.RunWithArgs([]string{"sql", "--format=tsv", "-e", "select * from t.t"}) c.RunWithArgs([]string{"sql", "--format=csv", "-e", "select * from t.t"}) c.RunWithArgs([]string{"sql", "--format=sql", "-e", "select * from t.t"}) c.RunWithArgs([]string{"sql", "--format=html", "-e", "select * from t.t"}) c.RunWithArgs([]string{"sql", "--format=raw", "-e", "select * from t.t"}) c.RunWithArgs([]string{"sql", "--format=records", "-e", "select * from t.t"}) c.RunWithArgs([]string{"sql", "--format=pretty", "-e", "select ' hai' as x"}) c.RunWithArgs([]string{"sql", "--format=pretty", "-e", "explain(indent) select s from t.t union all select s from t.t"})
Output: sql -e create database t; create table t.t (s string, d string); CREATE TABLE sql -e insert into t.t values (e'foo', 'printable ASCII') INSERT 1 sql -e insert into t.t values (e'"foo', 'printable ASCII with quotes') INSERT 1 sql -e insert into t.t values (e'\\foo', 'printable ASCII with backslash') INSERT 1 sql -e insert into t.t values (e'foo\x0abar', 'non-printable ASCII') INSERT 1 sql -e insert into t.t values ('κόσμε', 'printable UTF8') INSERT 1 sql -e insert into t.t values (e'\xc3\xb1', 'printable UTF8 using escapes') INSERT 1 sql -e insert into t.t values (e'\x01', 'non-printable UTF8 string') INSERT 1 sql -e insert into t.t values (e'\xdc\x88\x38\x35', 'UTF8 string with RTL char') INSERT 1 sql -e insert into t.t values (e'\xc3\x28', 'non-UTF8 string') pq: invalid UTF-8 byte sequence DETAIL: source SQL: insert into t.t values (e'\xc3\x28', 'non-UTF8 string') ^ HINT: try \h VALUES sql -e insert into t.t values (e'a\tb\tc\n12\t123123213\t12313', 'tabs') INSERT 1 sql -e select * from t.t s d foo printable ASCII """foo" printable ASCII with quotes \foo printable ASCII with backslash "foo bar" non-printable ASCII κόσμε printable UTF8 ñ printable UTF8 using escapes """\x01""" non-printable UTF8 string ܈85 UTF8 string with RTL char "a b c 12 123123213 12313" tabs # 9 rows sql --format=pretty -e select * from t.t +--------------------------------+--------------------------------+ | s | d | +--------------------------------+--------------------------------+ | foo | printable ASCII | | "foo | printable ASCII with quotes | | \foo | printable ASCII with backslash | | foo | non-printable ASCII | | bar | | | κόσμε | printable UTF8 | | ñ | printable UTF8 using escapes | | "\x01" | non-printable UTF8 string | | ܈85 | UTF8 string with RTL char | | a b c | tabs | | 12 123123213 12313 | | +--------------------------------+--------------------------------+ (9 rows) sql --format=tsv -e select * from t.t s d foo printable ASCII """foo" printable ASCII with quotes \foo printable ASCII with backslash "foo bar" non-printable ASCII κόσμε printable UTF8 ñ printable UTF8 using escapes """\x01""" non-printable UTF8 string ܈85 UTF8 string with RTL char "a b c 12 123123213 12313" tabs # 9 rows sql --format=csv -e select * from t.t s,d foo,printable ASCII """foo",printable ASCII with quotes \foo,printable ASCII with backslash "foo bar",non-printable ASCII κόσμε,printable UTF8 ñ,printable UTF8 using escapes """\x01""",non-printable UTF8 string ܈85,UTF8 string with RTL char "a b c 12 123123213 12313",tabs # 9 rows sql --format=sql -e select * from t.t CREATE TABLE results ( s STRING, d STRING ); INSERT INTO results VALUES ('foo', 'printable ASCII'); INSERT INTO results VALUES ('"foo', 'printable ASCII with quotes'); INSERT INTO results VALUES (e'\\foo', 'printable ASCII with backslash'); INSERT INTO results VALUES (e'foo\nbar', 'non-printable ASCII'); INSERT INTO results VALUES (e'\u03BA\U00001F79\u03C3\u03BC\u03B5', 'printable UTF8'); INSERT INTO results VALUES (e'\u00F1', 'printable UTF8 using escapes'); INSERT INTO results VALUES (e'"\\x01"', 'non-printable UTF8 string'); INSERT INTO results VALUES (e'\u070885', 'UTF8 string with RTL char'); INSERT INTO results VALUES (e'a\tb\tc\n12\t123123213\t12313', 'tabs'); sql --format=html -e select * from t.t <table> <thead><tr><th>row</th><th>s</th><th>d</th></tr></head> <tbody> <tr><td>1</td><td>foo</td><td>printable ASCII</td></tr> <tr><td>2</td><td>"foo</td><td>printable ASCII with quotes</td></tr> <tr><td>3</td><td>\foo</td><td>printable ASCII with backslash</td></tr> <tr><td>4</td><td>foo<br/>bar</td><td>non-printable ASCII</td></tr> <tr><td>5</td><td>κόσμε</td><td>printable UTF8</td></tr> <tr><td>6</td><td>ñ</td><td>printable UTF8 using escapes</td></tr> <tr><td>7</td><td>"\x01"</td><td>non-printable UTF8 string</td></tr> <tr><td>8</td><td>܈85</td><td>UTF8 string with RTL char</td></tr> <tr><td>9</td><td>a b c<br/>12 123123213 12313</td><td>tabs</td></tr> </tbody> <tfoot><tr><td colspan=3>9 rows</td></tr></tfoot></table> sql --format=raw -e select * from t.t # 2 columns # row 1 ## 3 foo ## 15 printable ASCII # row 2 ## 4 "foo ## 27 printable ASCII with quotes # row 3 ## 4 \foo ## 30 printable ASCII with backslash # row 4 ## 7 foo bar ## 19 non-printable ASCII # row 5 ## 11 κόσμε ## 14 printable UTF8 # row 6 ## 2 ñ ## 28 printable UTF8 using escapes # row 7 ## 6 "\x01" ## 25 non-printable UTF8 string # row 8 ## 4 ܈85 ## 25 UTF8 string with RTL char # row 9 ## 24 a b c 12 123123213 12313 ## 4 tabs # 9 rows sql --format=records -e select * from t.t -[ RECORD 1 ] s | foo d | printable ASCII -[ RECORD 2 ] s | "foo d | printable ASCII with quotes -[ RECORD 3 ] s | \foo d | printable ASCII with backslash -[ RECORD 4 ] s | foo | bar d | non-printable ASCII -[ RECORD 5 ] s | κόσμε d | printable UTF8 -[ RECORD 6 ] s | ñ d | printable UTF8 using escapes -[ RECORD 7 ] s | "\x01" d | non-printable UTF8 string -[ RECORD 8 ] s | ܈85 d | UTF8 string with RTL char -[ RECORD 9 ] s | a b c | 12 123123213 12313 d | tabs sql --format=pretty -e select ' hai' as x +-------+ | x | +-------+ | hai | +-------+ (1 row) sql --format=pretty -e explain(indent) select s from t.t union all select s from t.t +-------+--------+-------+--------------------+ | Level | Type | Field | Description | +-------+--------+-------+--------------------+ | 0 | append | | -> append | | 1 | render | | -> render | | 2 | scan | | -> scan | | 2 | | table | t@primary | | 2 | | spans | ALL | | 1 | render | | -> render | | 2 | scan | | -> scan | | 2 | | table | t@primary | | 2 | | spans | ALL | +-------+--------+-------+--------------------+ (9 rows)
Example (User) ¶
c := newCLITest(cliTestParams{}) defer c.cleanup() c.Run("user ls") c.Run("user ls --format=pretty") c.Run("user ls --format=tsv") c.Run("user set FOO") c.Run("user set Foo") c.Run("user set fOo") c.Run("user set foO") c.Run("user set foo") c.Run("user set _foo") c.Run("user set f_oo") c.Run("user set foo_") c.Run("user set ,foo") c.Run("user set f,oo") c.Run("user set foo,") c.Run("user set 0foo") c.Run("user set foo0") c.Run("user set f0oo") c.Run("user set foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoof") c.Run("user set foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo") c.Run("user set Ομηρος") // Try some reserved keywords. c.Run("user set and") c.Run("user set table") // Don't use get, since the output of hashedPassword is random. // c.Run("user get foo") c.Run("user ls --format=pretty") c.Run("user rm foo") c.Run("user ls --format=pretty")
Output: user ls username # 0 rows user ls --format=pretty +----------+ | username | +----------+ +----------+ (0 rows) user ls --format=tsv username # 0 rows user set FOO INSERT 1 user set Foo INSERT 1 user set fOo INSERT 1 user set foO INSERT 1 user set foo INSERT 1 user set _foo INSERT 1 user set f_oo INSERT 1 user set foo_ INSERT 1 user set ,foo username ",foo" invalid; usernames are case insensitive, must start with a letter or underscore, may contain letters, digits or underscores, and must not exceed 63 characters user set f,oo username "f,oo" invalid; usernames are case insensitive, must start with a letter or underscore, may contain letters, digits or underscores, and must not exceed 63 characters user set foo, username "foo," invalid; usernames are case insensitive, must start with a letter or underscore, may contain letters, digits or underscores, and must not exceed 63 characters user set 0foo username "0foo" invalid; usernames are case insensitive, must start with a letter or underscore, may contain letters, digits or underscores, and must not exceed 63 characters user set foo0 INSERT 1 user set f0oo INSERT 1 user set foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoof username "foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoof" invalid; usernames are case insensitive, must start with a letter or underscore, may contain letters, digits or underscores, and must not exceed 63 characters user set foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo INSERT 1 user set Ομηρος INSERT 1 user set and INSERT 1 user set table INSERT 1 user ls --format=pretty +-----------------------------------------------------------------+ | username | +-----------------------------------------------------------------+ | _foo | | and | | f0oo | | f_oo | | foo | | foo0 | | foo_ | | foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo | | table | | ομηρος | +-----------------------------------------------------------------+ (10 rows) user rm foo DELETE 1 user ls --format=pretty +-----------------------------------------------------------------+ | username | +-----------------------------------------------------------------+ | _foo | | and | | f0oo | | f_oo | | foo0 | | foo_ | | foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo | | table | | ομηρος | +-----------------------------------------------------------------+ (9 rows)
Example (Zone) ¶
c := newCLITest(cliTestParams{}) defer c.cleanup() c.Run("zone ls") c.Run("zone set system --file=./testdata/zone_attrs.yaml") c.Run("zone ls") c.Run("zone get .meta") c.Run("zone get system.nonexistent") c.Run("zone get system.lease") c.Run("zone set system.lease --file=./testdata/zone_attrs.yaml") c.Run("zone set system.namespace --file=./testdata/zone_attrs.yaml") c.Run("zone set system.nonexistent --file=./testdata/zone_attrs.yaml") c.Run("zone set system --file=./testdata/zone_range_max_bytes.yaml") c.Run("zone get system") c.Run("zone rm system") c.Run("zone ls") c.Run("zone rm .default") c.Run("zone set .meta --file=./testdata/zone_range_max_bytes.yaml") c.Run("zone set .system --file=./testdata/zone_range_max_bytes.yaml") c.Run("zone set .timeseries --file=./testdata/zone_range_max_bytes.yaml") c.Run("zone get .system") c.Run("zone ls") c.Run("zone set .default --file=./testdata/zone_range_max_bytes.yaml") c.Run("zone get system") c.Run("zone set .default --disable-replication") c.Run("zone get system") c.Run("zone rm .meta") c.Run("zone rm .system") c.Run("zone ls") c.Run("zone rm .timeseries") c.Run("zone ls") c.Run("zone rm .meta") c.Run("zone rm .system") c.Run("zone rm .timeseries")
Output: zone ls .default zone set system --file=./testdata/zone_attrs.yaml range_min_bytes: 1048576 range_max_bytes: 67108864 gc: ttlseconds: 90000 num_replicas: 1 constraints: [us-east-1a, ssd] zone ls .default system zone get .meta .default range_min_bytes: 1048576 range_max_bytes: 67108864 gc: ttlseconds: 90000 num_replicas: 1 constraints: [] zone get system.nonexistent system.nonexistent not found zone get system.lease system range_min_bytes: 1048576 range_max_bytes: 67108864 gc: ttlseconds: 90000 num_replicas: 1 constraints: [us-east-1a, ssd] zone set system.lease --file=./testdata/zone_attrs.yaml setting zone configs for individual system tables is not supported; try setting your config on the entire "system" database instead zone set system.namespace --file=./testdata/zone_attrs.yaml setting zone configs for individual system tables is not supported; try setting your config on the entire "system" database instead zone set system.nonexistent --file=./testdata/zone_attrs.yaml system.nonexistent not found zone set system --file=./testdata/zone_range_max_bytes.yaml range_min_bytes: 1048576 range_max_bytes: 134217728 gc: ttlseconds: 90000 num_replicas: 3 constraints: [us-east-1a, ssd] zone get system system range_min_bytes: 1048576 range_max_bytes: 134217728 gc: ttlseconds: 90000 num_replicas: 3 constraints: [us-east-1a, ssd] zone rm system DELETE 1 zone ls .default zone rm .default unable to remove special zone .default zone set .meta --file=./testdata/zone_range_max_bytes.yaml range_min_bytes: 1048576 range_max_bytes: 134217728 gc: ttlseconds: 90000 num_replicas: 3 constraints: [] zone set .system --file=./testdata/zone_range_max_bytes.yaml range_min_bytes: 1048576 range_max_bytes: 134217728 gc: ttlseconds: 90000 num_replicas: 3 constraints: [] zone set .timeseries --file=./testdata/zone_range_max_bytes.yaml range_min_bytes: 1048576 range_max_bytes: 134217728 gc: ttlseconds: 90000 num_replicas: 3 constraints: [] zone get .system .system range_min_bytes: 1048576 range_max_bytes: 134217728 gc: ttlseconds: 90000 num_replicas: 3 constraints: [] zone ls .default .meta .system .timeseries zone set .default --file=./testdata/zone_range_max_bytes.yaml range_min_bytes: 1048576 range_max_bytes: 134217728 gc: ttlseconds: 90000 num_replicas: 3 constraints: [] zone get system .default range_min_bytes: 1048576 range_max_bytes: 134217728 gc: ttlseconds: 90000 num_replicas: 3 constraints: [] zone set .default --disable-replication range_min_bytes: 1048576 range_max_bytes: 134217728 gc: ttlseconds: 90000 num_replicas: 1 constraints: [] zone get system .default range_min_bytes: 1048576 range_max_bytes: 134217728 gc: ttlseconds: 90000 num_replicas: 1 constraints: [] zone rm .meta DELETE 1 zone rm .system DELETE 1 zone ls .default .timeseries zone rm .timeseries DELETE 1 zone ls .default zone rm .meta DELETE 0 zone rm .system DELETE 0 zone rm .timeseries DELETE 0
Index ¶
- Variables
- func AddCmd(c *cobra.Command)
- func InitCLIDefaults()
- func Main()
- func MakeDBClient() (*client.DB, *stop.Stopper, error)
- func MaybeDecorateGRPCError(wrapped func(*cobra.Command, []string) error) func(*cobra.Command, []string) error
- func MaybeShoutError(wrapped func(*cobra.Command, []string) error) func(*cobra.Command, []string) error
- func Run(args []string) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrorCode = 1
ErrorCode is the value to be used by main() as exit code in case of error. For most errors 1 is appropriate, but a signal termination can change this.
Functions ¶
func Main ¶
func Main()
Main is the entry point for the cli, with a single line calling it intended to be the body of an action package main `main` func elsewhere. It is abstracted for reuse by duplicated `main` funcs in different distributions.
func MakeDBClient ¶
MakeDBClient creates a kv client for use in cli tools.
func MaybeDecorateGRPCError ¶
func MaybeDecorateGRPCError( wrapped func(*cobra.Command, []string) error, ) func(*cobra.Command, []string) error
MaybeDecorateGRPCError catches grpc errors and provides a more helpful error message to the user.
Types ¶
This section is empty.
Source Files ¶
Click to show internal directories.
Click to hide internal directories.