Skip to content

Latest commit

 

History

History
130 lines (101 loc) · 3.58 KB

codespaces.md

File metadata and controls

130 lines (101 loc) · 3.58 KB

Codespaces

You can create a GitHub Codespace for pgmp that has PostgreSQL setup with instructions from GitHub on creating a codespace. Some CLI convenience snippets follow.

Firstly, follow the GitHub CLI installation instructions for your OS.

Clone the pgmp repository:

gh repo clone shortishly/pgmp

Create a codespace for pgmp:

gh codespace create \
    --repo $(gh repo view \
        --json nameWithOwner \
        --jq .nameWithOwner) \
    --branch develop \
    --machine basicLinux32gb

Run a secure shell into the codespace:

gh codespace ssh \
    --codespace $(gh codespace ls \
        --repo $(gh repo view \
            --json nameWithOwner \
            --jq .nameWithOwner) \
        --json name \
        --jq '.[].name')

Once in the secure shell environment, you can check that PostgreSQL is running OK:

docker compose ps

To build pgmp, dialyze and run the unit tests:

make deps app dialyze eunit

To run the common tests against the PostgreSQL already running in the codespace:

make ct

To run an interactive Erlang/OTP shell with the pgmp application running:

make shell

You can then run various commands:

1> pgmp_connection_sync:query(#{sql => "select 2 + 2"}).
[{row_description,[<<"?column?">>]},
 {data_row,[4]},
 {command_complete,{select,1}}]
 
 
1> pgmp_connection_sync:parse(#{sql => "select $1::varchar::tsvector"}).
[{parse_complete,[]}]

1> pgmp_connection_sync:bind(#{args => ["a fat cat sat on a mat and ate a fat rat"]}).
[{bind_complete,[]}]

1> pgmp_connection_sync:execute(#{}).
[{row_description,[<<"tsvector">>]},
 {data_row,[#{<<"a">> => #{},<<"and">> => #{},<<"ate">> => #{},
              <<"cat">> => #{},<<"fat">> => #{},<<"mat">> => #{},
              <<"on">> => #{},<<"rat">> => #{},<<"sat">> => #{}}]},
 {command_complete,{select,1}}]

1> pgmp_connection_sync:parse(#{sql => "select $1::varchar::tsquery"}).
[{parse_complete,[]}]

1> pgmp_connection_sync:bind(#{args => ["fat & rat"]}).
[{bind_complete,[]}]

1> pgmp_connection_sync:execute(#{}).
[{row_description,[<<"tsquery">>]},
 {data_row,[['and',
             #{operand => <<"rat">>,prefix => false,weight => 0},
             #{operand => <<"fat">>,prefix => false,weight => 0}]]},
 {command_complete,{select,1}}]

pgmp_connection_sync:query(
  #{sql => "SELECT '{\"reading\": 1.230e-5}'::json,"
           " '{\"reading\": 1.230e-5}'::jsonb"}).
[{row_description,[<<"json">>,<<"jsonb">>]},
 {data_row,[#{<<"reading">> => 1.23e-5},
            #{<<"reading">> => 1.23e-5}]},
 {command_complete,{select,1}}]

Once you are finished you can delete the codespace using:

gh codespace delete \
    --codespace $(gh codespace ls \
        --repo $(gh repo view \
            --json nameWithOwner \
            --jq .nameWithOwner) \
        --json name \
        --jq '.[].name')