Skip to content

Commit

Permalink
fix code block type
Browse files Browse the repository at this point in the history
  • Loading branch information
noborus committed Apr 24, 2024
1 parent 03fe815 commit 267a83f
Show file tree
Hide file tree
Showing 20 changed files with 79 additions and 104 deletions.
11 changes: 3 additions & 8 deletions content/trdsql/10_stdin.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ In addition, there are many commands that output data that can be treated as tab
For example, the ps command,

```console
ps
```

```
$ ps
PID TTY TIME CMD
1157 pts/3 00:00:00 ps
22590 pts/3 00:00:03 zsh
Expand All @@ -67,7 +64,7 @@ Therefore, you can output it in Ascii Table format as follows.
ps|trdsql -ih -id " " -oat "SELECT \`PID\`, \`TTY\`, \`TIME\`, \`CMD\` FROM -"
```

```
```at
+-------+-------+----------+--------+
| PID | TTY | TIME | CMD |
+-------+-------+----------+--------+
Expand All @@ -86,9 +83,7 @@ command | trdsql -ih -id " " -a -
```

```console
ps|trdsql -id " " -ih -a -
```
```
$ ps|trdsql -id " " -ih -a -
The table name is -.
The file type is CSV.

Expand Down
12 changes: 4 additions & 8 deletions content/trdsql/10_stdin.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ nkf -w sjis.csv|trdsql -icsv "SELECT * FROM -"

大きなファイルを処理する前に先頭の数行のみを処理して試してみたりできます。


```console
head -100 big.csv|trdsql -icsv "SELECT * FROM -"
```
Expand All @@ -51,9 +50,7 @@ head -100 big.csv|trdsql -icsv "SELECT * FROM -"
例えば psコマンドでは、

```console
ps
```
```
$ ps
PID TTY TIME CMD
1157 pts/3 00:00:00 ps
22590 pts/3 00:00:03 zsh
Expand All @@ -66,7 +63,8 @@ ps
```console
ps|trdsql -ih -id " " -oat "SELECT \`PID\`, \`TTY\`, \`TIME\`, \`CMD\` FROM -"
```
```

```at
+-------+-------+----------+--------+
| PID | TTY | TIME | CMD |
+-------+-------+----------+--------+
Expand All @@ -85,9 +83,7 @@ ps|trdsql -ih -id " " -oat "SELECT \`PID\`, \`TTY\`, \`TIME\`, \`CMD\` FROM -"
```

```console
ps|trdsql -id " " -ih -a -
```
```
$ ps|trdsql -id " " -ih -a -
The table name is -.
The file type is CSV.

Expand Down
11 changes: 4 additions & 7 deletions content/trdsql/12_postgres.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ UNIX domain sockets can also be connected.

When PostgreSQL is installed with a package, a UNIX domain socket file is created in a location like the following.

```path
```file
/var/run/postgresql/.s.PGSQL.5432
```

Expand All @@ -62,7 +62,7 @@ trdsql -driver postgres -dsn "host=/var/run/postgresql/ port=5432 dbname=trdsql_

If you installed from source, the default is to create a Unix domain socket in /tmp/.

```path
```file
/tmp/.s.PGSQL.5120
```

Expand All @@ -81,10 +81,7 @@ First, note that the character "\`" used for escaping column names becomes `"`.
When specifying the PostgreSQL driver and performing analysis with the -a option, the SQL examples are also changed.

```console
trdsql -driver postgres -dsn "host=localhost dbname=trdsql_test" -ih -a sample.csv
```

```
$ trdsql -driver postgres -dsn "host=localhost dbname=trdsql_test" -ih -a sample.csv
The table name is sample.csv.
The file type is CSV.

Expand Down Expand Up @@ -125,7 +122,7 @@ For example, it is easy to output an actual table in MarkDown.
trdsql -driver postgres -dsn "host=localhost dbname=noborus" -omd -ih "SELECT * FROM city LIMIT 10"
```

```
```md
| city_id | city | country_id | last_update |
|---------|--------------------|------------|----------------------|
| 1 | A Corua (La Corua) | 87 | 2006-02-15T09:45:25Z |
Expand Down
20 changes: 7 additions & 13 deletions content/trdsql/12_postgres.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ dsnの項目には以下が指定できます。デフォルトの場合は省

例えば、ローカルホストのportが5433でデータベース名がtrdsql_testに接続するには以下のようにします。


```console
trdsql -driver postgres -dsn "host=localhost port=5433 dbname=trdsql_test" "SELECT 1"
```
Expand All @@ -56,31 +55,27 @@ UNIXドメインソケットへ接続もできます。

パッケージ等でPostgreSQLをインストールすると以下のような場所にUNIXドメインソケットファイルが作成されています。

```path
```file
/var/run/postgresql/.s.PGSQL.5432
```

上記の場合、hostに`/var/run/postgresql/`を指定します。「`/`」から始まるとUnixドメインソケットとみなされます。portは`.s.PGSQL.`の後にある「5432」を指定します。

```console
trdsql -driver postgres -dsn "host=/var/run/postgresql/ port=5432 dbname=trdsql_test" "SELECT VERSION()"
```
```
$ trdsql -driver postgres -dsn "host=/var/run/postgresql/ port=5432 dbname=trdsql_test" "SELECT VERSION()"
"PostgreSQL 10.10 (Ubuntu 10.10-0ubuntu0.18.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0, 64-bit"
```

ソースからインストールした場合のデフォルトは、/tmp/にUnixドメインソケットが作成されています。

```path
```file
/tmp/.s.PGSQL.5120
```

というファイルがあれば、以下のようにして接続します。

```console
trdsql -driver postgres -dsn "host=/tmp/ port=5120 dbname=postgres" "SELECT VERSION()"
```
```
$ trdsql -driver postgres -dsn "host=/tmp/ port=5120 dbname=postgres" "SELECT VERSION()"
"PostgreSQL 12.0 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0, 64-bit"
```

Expand All @@ -93,9 +88,7 @@ trdsql -driver postgres -dsn "host=/tmp/ port=5120 dbname=postgres" "SELECT VERS
PostgreSQLドライバを指定して、-aオプションによる解析をおこなうとSQLの例も変更されています。

```console
trdsql -driver postgres -dsn "host=localhost dbname=trdsql_test" -ih -a sample.csv
```
```
$ trdsql -driver postgres -dsn "host=localhost dbname=trdsql_test" -ih -a sample.csv
The table name is sample.csv.
The file type is CSV.

Expand Down Expand Up @@ -135,7 +128,8 @@ trdsqlは対象のファイルが無くてもSQLの実行するようになっ
```console
trdsql -driver postgres -dsn "host=localhost dbname=noborus" -omd -ih "SELECT * FROM city LIMIT 10"
```
```

```md
| city_id | city | country_id | last_update |
|---------|--------------------|------------|----------------------|
| 1 | A Corua (La Corua) | 87 | 2006-02-15T09:45:25Z |
Expand Down
2 changes: 1 addition & 1 deletion content/trdsql/13_mysql.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ As with the previous PostgreSQL, you can execute SQL on MySQL tables and output
trdsql -driver mysql -dsn "noborus:noborus@/trdsql_test" -oat -ih "SELECT * FROM actor LIMIT 10"
```

```
```at
+----------+------------+--------------+---------------------+
| actor_id | first_name | last_name | last_update |
+----------+------------+--------------+---------------------+
Expand Down
3 changes: 2 additions & 1 deletion content/trdsql/13_mysql.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ trdsql -driver mysql -dsn "noborus:noborus@tcp(localhost:3306)/trdsql_test" "SEL
```console
trdsql -driver mysql -dsn "noborus:noborus@/trdsql_test" -oat -ih "SELECT * FROM actor LIMIT 10"
```
```

```at
+----------+------------+--------------+---------------------+
| actor_id | first_name | last_name | last_update |
+----------+------------+--------------+---------------------+
Expand Down
9 changes: 3 additions & 6 deletions content/trdsql/14_sqlite3.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ By default, LIKE is not case sensitive.
trdsql -driver sqlite3 -dsn ":memory:" -ih "SELECT * FROM header.csv WHERE name LIKE '%a%'"
```

```
```csv
1,Orange
3,Apple
```
Expand All @@ -62,7 +62,7 @@ If you set _cslike=true, it is case sensitive.
trdsql -driver sqlite3 -dsn ":memory:?_cslike=true" -ih "SELECT * FROM header.csv WHERE name LIKE '%a%'"
```

```
```csv
1,Orange
```

Expand All @@ -77,10 +77,7 @@ trdsql -ih -driver sqlite3 -dsn "file:trdsql_test.db?mode=rwc" "CREATE TABLE use
Writing is prohibited and an error occurs with `mode=ro`.

```console
trdsql -ih -driver sqlite3 -dsn "file:trdsql_testro.db?mode=ro" "CREATE TABLE users AS SELECT CAST(id as int), CAST(name AS varchar(20)) FROM user.csv "
```

```
$ trdsql -ih -driver sqlite3 -dsn "file:trdsql_testro.db?mode=ro" "CREATE TABLE users AS SELECT CAST(id as int), CAST(name AS varchar(20)) FROM user.csv "
2020/01/08 14:02:54 ERROR(BEGIN):unable to open database file: no such file or directory
```

Expand Down
11 changes: 4 additions & 7 deletions content/trdsql/14_sqlite3.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dsnはsqlite3のデータファイル名を指定すれば、そのファイル
trdsql -driver sqlite3 -dsn "test.sqlite" -oat "SELECT * FROM test"
```

```
```at
+----+--------+-------+
| id | name | price |
+----+--------+-------+
Expand All @@ -51,7 +51,7 @@ trdsql -driver sqlite3 -dsn "test.sqlite" -oat "SELECT * FROM test"
trdsql -driver sqlite3 -dsn ":memory:" -ih "SELECT * FROM header.csv WHERE name LIKE '%a%'"
```

```
```csv
1,Orange
3,Apple
```
Expand All @@ -62,7 +62,7 @@ _cslike=trueにすると大文字小文字が区別されます。
trdsql -driver sqlite3 -dsn ":memory:?_cslike=true" -ih "SELECT * FROM header.csv WHERE name LIKE '%a%'"
```

```
```csv
1,Orange
```

Expand All @@ -77,10 +77,7 @@ trdsql -ih -driver sqlite3 -dsn "file:trdsql_test.db?mode=rwc" "CREATE TABLE use
`mode=ro`では書き込みが禁止されエラーになります。

```console
trdsql -ih -driver sqlite3 -dsn "file:trdsql_testro.db?mode=ro" "CREATE TABLE users AS SELECT CAST(id as int), CAST(name AS varchar(20)) FROM user.csv "
```

```
$ trdsql -ih -driver sqlite3 -dsn "file:trdsql_testro.db?mode=ro" "CREATE TABLE users AS SELECT CAST(id as int), CAST(name AS varchar(20)) FROM user.csv "
2020/01/08 14:02:54 ERROR(BEGIN):unable to open database file: no such file or directory
```

Expand Down
2 changes: 1 addition & 1 deletion content/trdsql/15_import.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ trdsql -driver postgres -dsn "dbname=trdsql_test" -ih \
```

```console
trdsql -driver postgres -dsn "dbname=trdsql_test" -ih -oh\
$ trdsql -driver postgres -dsn "dbname=trdsql_test" -ih -oh\
"SELECT * FROM fruits"
num,name
1,Orange
Expand Down
2 changes: 1 addition & 1 deletion content/trdsql/15_import.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ trdsql -driver postgres -dsn "dbname=trdsql_test" -ih \
```

```console
trdsql -driver postgres -dsn "dbname=trdsql_test" -ih -oh\
$ trdsql -driver postgres -dsn "dbname=trdsql_test" -ih -oh\
"SELECT * FROM fruits"
num,name
1,Orange
Expand Down
2 changes: 1 addition & 1 deletion content/trdsql/16_join.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ id:2 unit:箱
Join the result of the previous CSV JOIN with LTSV.

```console
trdsql -oat \
$ trdsql -oat \
"SELECT a.c1, a.c2, p.c2, unit" \
" FROM abc.csv AS a" \
"LEFT JOIN price.csv AS p" \
Expand Down
2 changes: 1 addition & 1 deletion content/trdsql/16_join.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ id:2 unit:箱
先程のCSVのJOINの結果に更にLTSVをJOINします。

```console
trdsql -oat \
$ trdsql -oat \
"SELECT a.c1, a.c2, p.c2, unit" \
" FROM abc.csv AS a" \
"LEFT JOIN price.csv AS p" \
Expand Down
6 changes: 3 additions & 3 deletions content/trdsql/17_file_table.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ By connecting to a database where a table already exists, you can also join file
For example, if there is a table called fruits in the database, you can join it with the previous abc.csv.

```console
trdsql -driver postgres -dsn "dbname=trdsql_test" \
$ trdsql -driver postgres -dsn "dbname=trdsql_test" \
"SELECT a.c1, a.c2, f.name FROM abc.csv AS a "\
"LEFT JOIN fruits AS f ON (CAST(a.c1 AS int) = f.id)"
1,AAA,Orange
Expand Down Expand Up @@ -47,7 +47,7 @@ id,name
```

```console
trdsql -driver postgres -dsn "dbname=trdsql_test" \
$ trdsql -driver postgres -dsn "dbname=trdsql_test" \
"SELECT u.id, u.name FROM users AS u "\
"INNER JOIN list.csv AS l ON (u.name = l.c1)"
3,tarou
Expand All @@ -56,7 +56,7 @@ trdsql -driver postgres -dsn "dbname=trdsql_test" \
Conversely, it is also possible to add information from a database table to a CSV file.

```console
trdsql -driver postgres -dsn "dbname=trdsql_test" \
$ trdsql -driver postgres -dsn "dbname=trdsql_test" \
"SELECT u.id, u.name FROM list.csv AS l "\
"LEFT JOIN users AS u ON (l.c1 = u.name)" \
"ORDER BY u.id"
Expand Down
8 changes: 4 additions & 4 deletions content/trdsql/17_file_table.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ categories = [
例えば、データベース内にfruitsというテーブルがあった場合に、前回のabc.csvとJOINできます。

```console
trdsql -driver postgres -dsn "dbname=trdsql_test" \
$ trdsql -driver postgres -dsn "dbname=trdsql_test" \
"SELECT a.c1, a.c2, f.name FROM abc.csv AS a "\
"LEFT JOIN fruits AS f ON (CAST(a.c1 AS int) = f.id)"
1,AAA,Orange
Expand All @@ -39,15 +39,15 @@ noborus

usersテーブル

```
```csv
id,name
1,taizou
2,momo
3,tarou
```

```console
trdsql -driver postgres -dsn "dbname=trdsql_test" \
$ trdsql -driver postgres -dsn "dbname=trdsql_test" \
"SELECT u.id, u.name FROM users AS u "\
"INNER JOIN list.csv AS l ON (u.name = l.c1)"
3,tarou
Expand All @@ -56,7 +56,7 @@ trdsql -driver postgres -dsn "dbname=trdsql_test" \
逆にCSVファイルにデータベースのテーブルから情報を足すといったことも考えられます。

```console
trdsql -driver postgres -dsn "dbname=trdsql_test" \
$ trdsql -driver postgres -dsn "dbname=trdsql_test" \
"SELECT u.id, u.name FROM list.csv AS l "\
"LEFT JOIN users AS u ON (l.c1 = u.name)" \
"ORDER BY u.id"
Expand Down

0 comments on commit 267a83f

Please sign in to comment.