# @acquary/cli

> @acquary/cli is a tool to use @acquary/core from the command line

Latest version **2.2.1** (published 2024-05-21) · 0 weekly downloads

## Install

```sh
npm install @acquary/cli
pnpm add @acquary/cli
yarn add @acquary/cli
bun add @acquary/cli
```

Provides the command `acquary`.

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.1 |
| Published | 2024-05-21 |
| First published | 2023-04-05 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=16 |
| Dependencies | 0 |
| Unpacked size | 90.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Douglas Sousa |
| Maintainers | dodevs |

## Links

- npm: https://www.npmjs.com/package/@acquary/cli
- Repository: https://github.com/dodevs/Acquary
- Homepage: https://github.com/dodevs/Acquary#readme
- Issues: https://github.com/dodevs/Acquary/issues
- npm.io page: https://npm.io/package/@acquary/cli

## Recent versions

- 2.2.1 (latest) — 2024-05-21
- 2.2.0 — 2024-05-21
- 2.1.3 — 2024-01-19
- 2.1.2 — 2024-01-19
- 2.1.1 — 2024-01-19
- 2.1.0 — 2024-01-19
- 2.0.0 — 2023-04-14
- 1.0.3 — 2023-04-07
- 1.0.2 — 2023-04-07
- 1.0.1 — 2023-04-05
- 1.0.0 — 2023-04-05

## README

# Acquary CLI

## Installation

To install, just run the command below:

```bash
npm install -g @acquary/cli
```

## Usage

### ENV

First, you need to configure an _ENV_, that is a folder with a `config.json` file for azure databases config and
a `cache.json` file for caching MFA tokens.

You can configure multiple ENVs, and switch between them using the `--env` flag.

```bash
acquary configure --add prod
```

This will create a `prod` folder in the `<HOME>/.acquary` folder, and you should edit the `config.json` file to add your configuration.\
For `server` section, see more information [here](https://tediousjs.github.io/tedious/api-connection.html).\
For `authentication`, you only need to edit the `authority`. The `clientId` and `clientSecret` are from Azure Data Studio hehe.\
For `clients`, you can define a query or a list of databases.

#### Parameters

`--add` - Add a new ENV\
`--remove` - Remove a ENV\
`--list` - List all ENVs\
`--test` - Test a ENV connection\
`--logout` - Logout from a ENV (Only for MFA)

### Generate

You need to generate a `clients.json` file to use the CLI. This is a file that contains all the
databases you want to connect to or a SQL Query to get the databases.

```bash
acquary generate clients clients.json
```

#### Arguments
```bash
acquary generate <type> <file>
```
Where `type` can be `clients`, `script` or `postprocess`

### Execute

After create a _ENV_ and generate a file with the `databases` configuration, you can execute a script against all the databases.

```bash
acquary execute --env prod --clients clients.json --query "SELECT * FROM SomeTable"
```

#### Parameters
`--e, --env` - The ENV to use\
`--c, --clients` - The clients file\
`--q, --query` - The SQL Query to execute\
`--f, --file` - The SQL File to execute\
`--s, --script` - The javascript file to execute. [See more](#Script)\
`--o, --output` - The output format. Can be `json`, `xls` or `stdout`. [See more](#Stdout)\
`--empty` - If the output should contain empty results\
`--unique` - If the _xls_ output should contain only one sheet with all the results\
`--mc, --maxConcurrent` - Max concurrent clients\
`--mr, --maxRetries` - Max retries after an error\

#### Script

You can also execute a javascript file that contains a function that will be executed against all the databases. [See more](https://github.com/tediousjs/node-mssql#request)

```javascript
exports.default = async function(transaction, client) {
    const request = new Request(transaction);
    const result = await request.query("SELECT * FROM SomeTable");
    return result.recordset;
}
```

#### Stdout

With the `--output stdout` flag, you can pipe all databases outputs to another command.\
For example, you can pipe the output to `jq` to filter the result.

```bash
acquary execute --env prod --clients clients.json --query "SELECT COUNT(*) AS Qtd FROM SomeTable" --output stdout | jq '.[] | select(.Qtd > 10)'
```

Or to `postprocess` generated python script.

---
_Source: https://npm.io/package/@acquary/cli · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
