Skip to content

Commit

Permalink
v1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
opaoz committed Feb 27, 2024
1 parent e112d8f commit c65953a
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 490 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ko_fi: opa_oz
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
action
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": true,
"trailingComma": "none",
"singleQuote": true,
"printWidth": 120,
"tabWidth": 4
}
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Make query to PostgreSQL and return JSON

[![Test `query-postgresql` action](https://github.com/yakubique/query-postgresql/actions/workflows/test-myself.yaml/badge.svg)](https://github.com/yakubique/query-postgresql/actions/workflows/test-myself.yaml)

## Usage

For live examples, please see [actions](https://github.com/yakubique/query-postgresql/actions/workflows/test-myself.yaml)
Expand All @@ -18,3 +20,38 @@ with:
db: ${{ env.PG_DB }}
ssl: 'false'
```
## Inputs
<!-- AUTO-DOC-INPUT:START - Do not remove or modify this section -->
| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION |
|-----------|--------|----------|----------|--------------------------------------------|
| db | string | true | | PostgreSQL db |
| host | string | true | | PostgreSQL host |
| username | string | true | | PostgreSQL username |
| password | string | true | | PostgreSQL password |
| port | string | true | `"5432"` | PostgreSQL port (default: 5432) |
| query | string | true | | SQL query (query file if `from_file=true`) |
| ssl | string | false | `"true"` | SSL enabled (default: 'true') |
| from_file | string | false | | Read query from file (default: 'false') |
| to_file | string | false | | Save result to file (default: 'false') |

<!-- AUTO-DOC-INPUT:END -->


## Outputs

<!-- AUTO-DOC-OUTPUT:START - Do not remove or modify this section -->

| OUTPUT | TYPE | DESCRIPTION |
|--------|--------|-------------------------------------|
| count | string | Rows count |
| result | string | PostgreSQL response OR path to file |

<!-- AUTO-DOC-OUTPUT:END -->


----

[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/S6S1UZ9P7)
467 changes: 0 additions & 467 deletions action/LICENSE

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "query-postgresql",
"version": "1.1.0",
"version": "1.2.0",
"description": "Make query to PostgreSQL and return JSON",
"main": "action/index.js",
"scripts": {
Expand All @@ -19,7 +19,7 @@
"action",
"versions"
],
"author": "Vladimir <opa-oz>",
"author": "Vladimir <opa-oz> Levin",
"license": "MIT",
"bugs": {
"url": "https://github.com/yakubique/query-postgresql/issues"
Expand Down
18 changes: 9 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as core from '@actions/core';
import { readFileSync } from 'node:fs';
import { ActionInputs, getInputs } from './io-helper';
import { Client } from 'pg';
import { buildOutput, outputJson } from "@yakubique/atils/dist";
import { buildOutput, outputJson } from '@yakubique/atils/dist';

enum Outputs {
result = 'result',
Expand All @@ -19,7 +19,7 @@ const setOutputs = buildOutput(Outputs);
let query = inputs.query;

if (inputs.fromFile) {
query = readFileSync(query, { encoding: 'utf8', flag: 'r' })
query = readFileSync(query, { encoding: 'utf8', flag: 'r' });
}

client = new Client({
Expand All @@ -28,21 +28,21 @@ const setOutputs = buildOutput(Outputs);
host: inputs.host,
database: inputs.db,
port: inputs.port,
ssl: inputs.ssl,
})
await client.connect()
ssl: inputs.ssl
});
await client.connect();

const res = await client.query(query)
const res = await client.query(query);

setOutputs({
result: outputJson(res.rows, inputs.toFile),
count: res.rowCount,
})
count: res.rowCount
});

core.info('Success!');
} catch (err: any) {
core.setFailed(err.message);
} finally {
await client?.end()
await client?.end();
}
})();
24 changes: 12 additions & 12 deletions src/io-helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as core from '@actions/core';
import { isBlank, getBooleanInput } from "@yakubique/atils/dist";
import { isBlank, getBooleanInput } from '@yakubique/atils/dist';

enum Inputs {
Query = 'query',
Expand Down Expand Up @@ -28,22 +28,22 @@ export interface ActionInputs {
export function getInputs(): ActionInputs {
const result: ActionInputs | any = {};

result.query = `${core.getInput(Inputs.Query, { required: true })}`
result.host = `${core.getInput(Inputs.Host, { required: true })}`
result.db = `${core.getInput(Inputs.Database, { required: true })}`
result.username = `${core.getInput(Inputs.Username, { required: true })}`
result.password = `${core.getInput(Inputs.Password, { required: true })}`
result.query = `${core.getInput(Inputs.Query, { required: true })}`;
result.host = `${core.getInput(Inputs.Host, { required: true })}`;
result.db = `${core.getInput(Inputs.Database, { required: true })}`;
result.username = `${core.getInput(Inputs.Username, { required: true })}`;
result.password = `${core.getInput(Inputs.Password, { required: true })}`;

const port = `${core.getInput(Inputs.Port, { required: false })}`
const port = `${core.getInput(Inputs.Port, { required: false })}`;
if (isBlank(port)) {
result.port = 5432
result.port = 5432;
} else {
result.prot = parseInt(port, 10)
result.prot = parseInt(port, 10);
}

result.toFile = getBooleanInput(Inputs.ToFile, { required: false })
result.fromFile = getBooleanInput(Inputs.FromFile, { required: false })
result.ssl = getBooleanInput(Inputs.SSL, { required: false })
result.toFile = getBooleanInput(Inputs.ToFile, { required: false });
result.fromFile = getBooleanInput(Inputs.FromFile, { required: false });
result.ssl = getBooleanInput(Inputs.SSL, { required: false });

return result;
}

0 comments on commit c65953a

Please sign in to comment.