Metadata-Version: 2.4
Name: qseed
Version: 0.3.0a0
Summary: Generate test data from MSSQL stored procedures — automatically
Author-email: Aldi <hello@aldimhr.dev>
License: MIT
Project-URL: Homepage, https://github.com/aldimhr/qseed
Project-URL: Repository, https://github.com/aldimhr/qseed
Project-URL: Issues, https://github.com/aldimhr/qseed/issues
Keywords: mssql,test-data,data-generator,sql-server,cli
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Database
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pymssql>=2.3
Requires-Dist: requests>=2.31
Requires-Dist: keyring>=25.0
Requires-Dist: pyperclip>=1.8
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-mock>=3.10; extra == "dev"
Requires-Dist: responses>=0.23; extra == "dev"
Dynamic: license-file

# qseed

Generate test data from your MSSQL stored procedures — automatically.

**`qseed`** connects to your MSSQL database, fetches all DDL needed by a stored procedure or query, calls the datagen API, and writes INSERT statements to stdout, a file, or your clipboard.

---

## Quick Start

```bash
# Point to your datagen-core API
qseed config set-api https://datagen.aldimhr.dev

# Add your database (password stored in OS keyring)
qseed config add default

# Generate 10 rows for a stored procedure
qseed --procedure GetCustomerOrders --rows 10

# Pipe directly to sqlcmd
qseed --procedure GetCustomerOrders --rows 50 | sqlcmd -S myserver -d mydb
```

Or skip the config file and pass everything on the command line:

```bash
qseed \
  --server mydb.company.com --database SalesDB --user sa --password secret \
  --procedure GetCustomerOrders --rows 10 -o test_data.sql
```

---

## Installation

### From PyPI

```bash
pip install qseed
```

### From Repository

```bash
git clone https://github.com/aldimhr/qseed.git
cd qseed
pip install .
```

### Ubuntu / Raspberry Pi

pymssql requires FreeTDS:

```bash
sudo apt-get install -y python3-dev freetds-dev freetds-bin libssl-dev
pip install qseed
```

### macOS

```bash
brew install freetds
pip install qseed
```

---

## Commands

### `run` (default)

Generate INSERT statements. The `run` subcommand is optional — if you pass `--procedure`, `--sql`, or `--sql-file`, it's implied automatically.

```bash
# From a stored procedure
qseed --procedure GetCustomerOrders --rows 10

# From raw SQL
qseed --sql "SELECT * FROM Orders WHERE Status = 'ACTIVE'" --rows 5

# From a .sql file
qseed --sql-file query.sql --rows 20

# Explicit run (same as above)
qseed run --procedure GetCustomerOrders --rows 10
```

#### Connection options

| Flag | Description |
|---|---|
| `--server HOST` | MSSQL server hostname or IP |
| `--port PORT` | Port (default: 1433) |
| `--database DB` | Database name |
| `--user USER` | SQL Server login |
| `--password PASS` | Password |
| `--password-env VAR` | Read password from environment variable |
| `--profile NAME` | Use a saved connection profile |

#### Generation options

| Flag | Description |
|---|---|
| `-r, --rows N` | Target row count (default: 10) |
| `-p, --param @N=V` | Parameter binding, repeatable |
| `--schema SCHEMA` | Schema for object lookup (default: dbo) |

#### Sub-procedure handling

| Flag | Description |
|---|---|
| `--recursive` | Discover tables from sub-procedures called via EXEC |
| `--max-depth N` | Max recursion depth (default: 5) |
| `--no-sub-proc-warning` | Suppress the sub-procedure warning |

#### Output options

| Flag | Description |
|---|---|
| `-o, --output PATH` | Write to file (default: stdout) |
| `--copy` | Copy to clipboard |
| `--open` | Open in `$DATAGEN_EDITOR` or `$EDITOR` |

#### Debug options

| Flag | Description |
|---|---|
| `--dry-run` | Fetch DDL and print it without calling the API |
| `--show-ddl` | Print fetched DDL alongside the output |
| `--timeout N` | DB connection timeout in seconds (default: 30) |
| `--api-timeout N` | API call timeout in seconds (default: 120) |

### `list`

Browse stored procedures in the database.

```bash
qseed list
qseed list --schema sales
qseed list --search Customer
qseed list --json
```

### `config`

Manage connection profiles.

```bash
qseed config add production      # Interactive prompts
qseed config list                # All profiles (passwords masked)
qseed config show default        # Profile details
qseed config test production     # Test DB + API reachability
qseed config remove old-profile  # Remove a profile
qseed config set-default production  # Set the default profile
qseed config set-api https://... # Set the API URL
```

### `version`

```bash
qseed version
```

---

## Configuration

### Config File

`~/.qseed/config.json`:

```json
{
  "api_url": "https://datagen.aldimhr.dev",
  "api_timeout": 120,
  "default_profile": "default",
  "profiles": {
    "default": {
      "server": "localhost",
      "port": 1433,
      "database": "MyDatabase",
      "user": "sa",
      "password_keyring": true,
      "schema": "dbo"
    }
  }
}
```

### Password Storage

Passwords are stored in your OS keyring (`keyring` package):
- **macOS**: Keychain
- **Linux**: libsecret / GNOME Keyring / KWallet
- **Windows**: Windows Credential Manager

If the keyring is unavailable, the CLI prompts for the password on each run.

### Environment Variables

All settings can be set via environment variables (no config file needed):

```bash
export DATAGEN_API_URL=https://datagen.aldimhr.dev
export DATAGEN_SERVER=mydb.company.com
export DATAGEN_DATABASE=SalesDB
export DATAGEN_USER=datagen_readonly
export DATAGEN_PASSWORD=$DB_PASSWORD
```

Env vars take priority over the config file. CLI flags take priority over env vars.

### CI/CD Usage

```bash
DATAGEN_API_URL=https://datagen.aldimhr.dev \
DATAGEN_SERVER=mydb.company.com \
DATAGEN_DATABASE=SalesDB \
DATAGEN_USER=datagen_readonly \
DATAGEN_PASSWORD=${{ secrets.DB_PASSWORD }} \
qseed --procedure GetCustomerOrders --rows 50 -o test_data.sql
```

---

## How It Works

```
qseed                    datagen-core (API)
─────────────                  ──────────────────
1. Connect to your MSSQL
2. Fetch SP DDL + table DDL
   + view DDL
3. POST /generate ──────────► 4. Parse constraints
                              5. Generate INSERTs
6. Write output ◄────────────  (plain SQL text)
   (stdout / file / clipboard)
```

**Credentials never leave your machine.** Only DDL text is sent to the API.

---

## Dependencies

- `pymssql >=2.3` — MSSQL connection
- `requests >=2.31` — HTTP calls to datagen-core
- `keyring >=25.0` — OS password storage
- `pyperclip >=1.8` — Clipboard output

---

## Development

```bash
git clone https://github.com/aldimhr/qseed.git
cd qseed
pip install -e ".[dev]"
python -m datagen_cli --help
```
