|
| 1 | +--- |
| 2 | +id: version-0.7.0-cql_db_access |
| 3 | +title: Accessing Database |
| 4 | +original_id: cql_db_access |
| 5 | +--- |
| 6 | + |
| 7 | +Once your database is successfully created, you can use the `console` sub-command to access it in an interactive console: |
| 8 | + |
| 9 | +```bash |
| 10 | +cql console 'covenantsql://4bc27a06ae52a7b8b1747f3808dda786ddd188627bafe8e34a332626e7232ba5' |
| 11 | +``` |
| 12 | + |
| 13 | +Output: |
| 14 | + |
| 15 | + INFO[0000] Geting bp address from dns: bp05.testnet.gridb.io |
| 16 | + INFO[0010] init config success path=~/.cql/config.yaml |
| 17 | + INFO[0010] connecting to "covenantsql://4bc27a06ae52a7b8b1747f3808dda786ddd188627bafe8e34a332626e7232ba5" |
| 18 | + Connected with driver covenantsql (develop-da3af8f6-20190515152207) |
| 19 | + Type "help" for help. |
| 20 | + |
| 21 | + co:4bc27a06ae52a7b8b1747f3808dda786ddd188627bafe8e34a332626e7232ba5=> |
| 22 | + |
| 23 | +Or access as `account2` (Should been granted access permission and transfered deposit token to the database successfully in last section): |
| 24 | + |
| 25 | +```bash |
| 26 | +cql console -config "account2/config.yaml" 'covenantsql://4bc27a06ae52a7b8b1747f3808dda786ddd188627bafe8e34a332626e7232ba5' |
| 27 | +``` |
| 28 | + |
| 29 | +Output: |
| 30 | + |
| 31 | + INFO[0000] Geting bp address from dns: bp05.testnet.gridb.io |
| 32 | + INFO[0010] init config success path=~/.config/cql/account2/config.yaml |
| 33 | + INFO[0010] connecting to "covenantsql://4bc27a06ae52a7b8b1747f3808dda786ddd188627bafe8e34a332626e7232ba5" |
| 34 | + Connected with driver covenantsql (develop-da3af8f6-20190515152207) |
| 35 | + Type "help" for help. |
| 36 | + |
| 37 | + co:4bc27a06ae52a7b8b1747f3808dda786ddd188627bafe8e34a332626e7232ba5=> |
| 38 | + |
| 39 | +Here is an example of using the interactive console: |
| 40 | + |
| 41 | + co:4bc27a06ae52a7b8b1747f3808dda786ddd188627bafe8e34a332626e7232ba5=> create table t1 (c1 int); |
| 42 | + CREATE TABLE |
| 43 | + co:4bc27a06ae52a7b8b1747f3808dda786ddd188627bafe8e34a332626e7232ba5=> insert into t1 values (1), (2), (3); |
| 44 | + INSERT |
| 45 | + co:4bc27a06ae52a7b8b1747f3808dda786ddd188627bafe8e34a332626e7232ba5=> select * from t1; |
| 46 | + c1 |
| 47 | + ---- |
| 48 | + 1 |
| 49 | + 2 |
| 50 | + 3 |
| 51 | + (3 rows) |
| 52 | + |
| 53 | + co:4bc27a06ae52a7b8b1747f3808dda786ddd188627bafe8e34a332626e7232ba5=> |
| 54 | + |
| 55 | +## Sub-command `console` Complete Parameters |
| 56 | + |
| 57 | +The sub-command `console` also supports running `adapter` or `explorer` servers in the background. Check [Local Servers](#local-servers) for details. |
| 58 | + |
| 59 | + usage: cql console [common params] [Console params] dsn |
| 60 | + |
| 61 | + Console runs an interactive SQL console for CovenantSQL. |
| 62 | + e.g. |
| 63 | + cql console covenantsql://4119ef997dedc585bfbcfae00ab6b87b8486fab323a8e107ea1fd4fc4f7eba5c |
| 64 | + |
| 65 | + There is also a -command param for SQL script, and you can add "< file.sql" at end of command for executing a SQL file. |
| 66 | + If those params are set, it will run SQL script and exit without staying console mode. |
| 67 | + e.g. |
| 68 | + cql console -command "create table test1(test2 int);" covenantsql://4119ef997dedc585bfbcfae00ab6b87b8486fab323a8e107ea1fd4fc4f7eba5c |
| 69 | + |
| 70 | + Console params: |
| 71 | + -adapter string |
| 72 | + Address to serve a database chain adapter, e.g. :7784 |
| 73 | + -command string |
| 74 | + Run only single command (SQL or usql internal command) and exit |
| 75 | + -explorer string |
| 76 | + Address serve a database chain explorer, e.g. :8546 |
| 77 | + -out string |
| 78 | + Record stdout to file |
| 79 | + -single-transaction |
| 80 | + Execute as a single transaction (if non-interactive) |
| 81 | + -variable value |
| 82 | + Set variable |
0 commit comments