deno-postgres を試す

github.com

こちらの記事を参考に REPL で試した。

Deno Postgres

その Console log。

mitsuaki@kuwahara-mac deno-web-2 % deno repl --unstable
Deno 1.14.1
exit using ctrl+d or close()
> import { Client } from "https://deno.land/x/postgres/mod.ts";

Download https://deno.land/x/postgres/mod.ts
Warning Implicitly using latest version (v0.12.0) for https://deno.land/x/postgres/mod.ts
Download https://deno.land/x/postgres@v0.12.0/mod.ts
Download https://deno.land/x/postgres@v0.12.0/connection/warning.ts
Download https://deno.land/x/postgres@v0.12.0/pool.ts
Download https://deno.land/x/postgres@v0.12.0/query/query.ts
Download https://deno.land/x/postgres@v0.12.0/connection/connection_params.ts
Download https://deno.land/x/postgres@v0.12.0/query/transaction.ts
Download https://deno.land/x/postgres@v0.12.0/client.ts
Download https://deno.land/x/postgres@v0.12.0/connection/packet_reader.ts
Download https://deno.land/x/postgres@v0.12.0/query/decode.ts
Download https://deno.land/x/postgres@v0.12.0/query/encode.ts
Download https://deno.land/x/postgres@v0.12.0/utils/deferred.ts
Download https://deno.land/x/postgres@v0.12.0/utils/utils.ts
Download https://deno.land/x/postgres@v0.12.0/connection/connection.ts
Download https://deno.land/x/postgres@v0.12.0/query/decoders.ts
Download https://deno.land/x/postgres@v0.12.0/query/oid.ts
Download https://deno.land/x/postgres@v0.12.0/deps.ts
Download https://deno.land/x/postgres@v0.12.0/query/types.ts
Download https://deno.land/x/postgres@v0.12.0/query/array_parser.ts
Download https://deno.land/std@0.98.0/hash/sha256.ts
Download https://deno.land/std@0.98.0/bytes/mod.ts
Download https://deno.land/std@0.98.0/hash/mod.ts
Download https://deno.land/std@0.98.0/io/bufio.ts
Download https://deno.land/std@0.98.0/encoding/base64.ts
Download https://deno.land/std@0.98.0/async/mod.ts
Download https://deno.land/std@0.98.0/fmt/colors.ts
Download https://deno.land/x/postgres@v0.12.0/connection/packet_writer.ts
Download https://deno.land/x/postgres@v0.12.0/connection/scram.ts
Download https://deno.land/std@0.98.0/hash/_wasm/hash.ts
Download https://deno.land/std@0.98.0/hash/hasher.ts
Download https://deno.land/std@0.98.0/async/pool.ts
Download https://deno.land/std@0.98.0/async/mux_async_iterator.ts
Download https://deno.land/std@0.98.0/async/tee.ts
Download https://deno.land/std@0.98.0/async/deferred.ts
Download https://deno.land/std@0.98.0/async/delay.ts
Download https://deno.land/std@0.98.0/io/util.ts
Download https://deno.land/std@0.98.0/_util/assert.ts
Download https://deno.land/std@0.98.0/bytes/bytes_list.ts
Download https://deno.land/std@0.98.0/encoding/hex.ts
Download https://deno.land/std@0.98.0/hash/_wasm/wasm.js
Download https://deno.land/std@0.98.0/testing/asserts.ts
Download https://deno.land/std@0.98.0/io/buffer.ts
Download https://deno.land/std@0.98.0/testing/_diff.ts
Download https://deno.land/std@0.98.0/io/types.d.ts
Check https://deno.land/x/postgres/mod.ts
undefined
> const client = new Client({
  user: "user",
  password: "password",
  database: "db_1",
  hostname: "localhost",
  port: 15432,
});

undefined
> await client.connect();
undefined
> const array_result = await client.queryArray("SELECT * FROM table_1");
undefined
> array_result;
QueryArrayResult {
  query: Query { args: [], fields: undefined, result_type: 0, text: "SELECT * FROM table_1" },
  _done: true,
  command: "SELECT",
  rowCount: 1,
  rowDescription: RowDescription {
    columnCount: 2,
    columns: [
      Column {
        name: "id",
        tableOid: 16387,
        index: 1,
        typeOid: 20,
        columnLength: 8,
        typeModifier: -1,
        format: 0
      },
      Column {
        name: "text_1",
        tableOid: 16387,
        index: 2,
        typeOid: 1043,
        columnLength: -1,
        typeModifier: -1,
        format: 0
      }
    ]
  },
  warnings: [],
  rows: [ [ 1n, "aaaa" ] ]
}
> await client.queryArray(`CREATE SEQUENCE table_2_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1`);
QueryArrayResult {
  query: Query {
    args: [],
    fields: undefined,
    result_type: 0,
    text: "CREATE SEQUENCE table_2_id_seq INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1"
  },
  _done: true,
  command: "CREATE",
  rowCount: NaN,
  rowDescription: undefined,
  warnings: [],
  rows: []
}
> await client.queryArray(`CREATE TABLE "public"."table_2" (
    "id" bigint DEFAULT nextval('table_2_id_seq') NOT NULL,
    "text_1" character varying NOT NULL,
    CONSTRAINT "table_2_pkey" PRIMARY KEY ("id")
) WITH (oids = false)`);

QueryArrayResult {
  query: Query {
    args: [],
    fields: undefined,
    result_type: 0,
    text: `CREATE TABLE "public"."table_2" (\n    "id" bigint DEFAULT nextval('table_2_id_seq') NOT NULL,\n    "t...`
  },
  _done: true,
  command: "CREATE",
  rowCount: NaN,
  rowDescription: undefined,
  warnings: [],
  rows: []
}
>

以上です。

PostgreSQL docker container を動かしてみた

下記記事を参考に、PostgresSQL を Docker Container で動かしてみた。  

Docker Compose 入門 - Qiita

docker-compose.yml は以下。

GitHub - quwahara/docker-postgres: PostgreSQL docker container for my local environment.

Adminer という便利ツールがあるのは知らなかった。知って良かった。  

Adminer - Database management in a single PHP file

純喫茶トルンカ、純喫茶トルンカ しあわせの香り (八木沢里志) の2冊を読んだ。

2冊で全6話のオムニバス仕立て。

趣のある佇まいの喫茶店に集まる人々を各話ごとに主人公にして、物語を展開していく。

各登場人物が過去につらい思い出を持ちながらも、トルンカに集まる人に支えられながら、温かい結末を迎える。

ちゃんとみんな幸せになる。

ちょっとほっこり気分転換したいときにおすすめ。

get-status

簡単なShellを公開した。
ホスト名とテキストファイル内にあるファイル名の一覧を順に連結して、GET Requestし、HTTP Status Code を表示する。

GitHub - quwahara/get-status: Print URL and its http status code by each line in text file.

見えちゃいけないファイルが見えてないかの確認用。