# db-knife

> `load.ts` is a CLI tool that allows you to

Latest version **1.0.1** (published 2020-12-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install db-knife
pnpm add db-knife
yarn add db-knife
bun add db-knife
```

Provides the command `db-knife`.

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-12-23 |
| First published | 2020-08-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 29.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | divyenduz |

## Links

- npm: https://www.npmjs.com/package/db-knife
- npm.io page: https://npm.io/package/db-knife

## Dependencies (3)

- [arg](https://npm.io/package/arg.md) 5.0.0
- [connection-string-parser](https://npm.io/package/connection-string-parser.md) 1.0.3
- [@pimeys/connection-string](https://npm.io/package/@pimeys/connection-string.md) 0.1.10

## Recent versions

- 1.0.1 (latest) — 2020-12-23
- 1.0.0 — 2020-12-22
- 0.0.9 — 2020-09-03
- 0.0.8 — 2020-09-03
- 0.0.7 — 2020-09-03
- 0.0.6 — 2020-09-03
- 0.0.5 — 2020-08-26
- 0.0.4 — 2020-08-26
- 0.0.3 — 2020-08-26
- 0.0.2 — 2020-08-26
- 0.0.1 — 2020-08-26

## README

# Introduction

`load.ts` is a CLI tool that allows you to

1. Load schemas from file system to a database
2. Provide custom template to produce any command line operations

Note: Folder strucutre read by `load.ts` is not configurable as of today. It should be like

`<database-server>/<database-name>/schema.sql`

There can be multiple databases (`database-name`) inside a `database-server` folder. `database-schema-examples` repo follows this structure.

# CLI Arguments Reference

| Arg          | Required | Description                                                                                                                                                                                |
| ------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| --folder     | true     | Load a folder containing database schemas (making them available in templates) assuming the following structure. `<dbname>/schema.sql`. This is similar to `database-schema-examples` repo |
| --db         | true     | Connection string of the database URL that will be parsed and made available as template args.                                                                                             |
| --subfolders | false    | Comma separated, load selective folders from --folder                                                                                                                                      |
| --template   | false    | Template to produce output. See Template Variables below.                                                                                                                                  |
| --data       | false    | Also include `data.sql` (defaults to false, i.e. `load.ts` only picks `schema.sql`)                                                                                                        |

# Template Variables

All examples are based on this connection string: `sqlserver://localhost:1433;database=test;user=root;password=prisma;trustServerCertificate=true;encrypt=DANGER_PLAINTEXT`

In all the examples below,

1. Respective database is derived from the connection string provided in `--db` argument.
2. Folder structure is assumed to be similar to `database-schema-examples` https://github.com/prisma/database-schema-examples/tree/main/mssql

| Name                    | Description                                                                 | Example                                                        |
| ----------------------- | --------------------------------------------------------------------------- | -------------------------------------------------------------- |
| 'db_cli'                | Default CLI of the respective database                                      | `sqlcmd` for SQL Server                                        |
| 'db_user_flag'          | User flag of the respective database                                        | `-U` for SQL Server                                            |
| 'db_pass_flag'          | Password flag of the respective database                                    | `-P` for SQL Server                                            |
| 'db_host_flag'          | Host flag of the respective database                                        | `-S` for SQL Server                                            |
| 'db_name_flag'          | Database name flag of the respective database                               | `-d` for SQL Server                                            |
| 'db_file_flag'          | File input flag of the respective database                                  | `-i` for SQL Server                                            |
| 'db_eval_flag'          | Command line query flag of the respective database                          | `-Q` for SQL Server                                            |
| 'db_quote'              | Quote delimiter used by the respective database                             | `'` for SQL Server                                             |
| 'db_ignore_errors_flag' | Flag to prompt database CLI to ignore any errors of the respective database |                                                                |
| 'db_user'               | User from the provided connection string                                    | `root`                                                         |
| 'db_pass'               | Password from the provided connection string                                | `prisma`                                                       |
| 'db_host'               | Host from the provided connection string                                    | `localhost`                                                    |
| 'db_name'               | Database name from the provided connection string                           | `test`                                                         |
| 'db_schema'             | Schema from the provided connection string                                  | `dbo` (for SQL Server)                                         |
| 'file_path'             | `schema.sql` (or `data.sql` ) file path from the provided folder            | Multiple values for each `schema.sql` file in the given folder |

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