Metadata-Version: 2.4
Name: sqliac-snowflake
Version: 0.1.6
Summary: Snowflake adapter for SQLIaC — a Terraform alternative for SQL databases without a state file.
Requires-Python: >=3.12
Description-Content-Type: text/markdown
Requires-Dist: sqliac>=0.1.6
Requires-Dist: snowflake-connector-python
Requires-Dist: asn1crypto
Requires-Dist: certifi
Requires-Dist: charset-normalizer
Requires-Dist: cryptography
Requires-Dist: filelock
Requires-Dist: idna
Requires-Dist: packaging
Requires-Dist: platformdirs
Requires-Dist: pyjwt
Requires-Dist: pyOpenSSL
Requires-Dist: pytz
Requires-Dist: requests
Requires-Dist: sortedcontainers
Requires-Dist: tomlkit
Requires-Dist: typing_extensions

# sqliac-snowflake

Snowflake adapter for [SQLIaC](https://pypi.org/project/sqliac/) — a Terraform alternative for SQL databases that uses no state file.

This package provides the Snowflake database connector and credential handling so SQLIaC can query Snowflake's live state and execute DDL to reconcile your declared resource definitions.

## Installation

```bash
pip install sqliac-snowflake
```

This also installs `sqliac` (the CLI and core engine) and `snowflake-connector-python`.

## Quick Start

### Credentials

SQLIaC looks for Snowflake credentials in two places, in order of precedence:

**1. Environment variables** (recommended)

```bash
export SNOWFLAKE_ACCOUNT="my_account"
export SNOWFLAKE_USER="my_user"
export SNOWFLAKE_PASSWORD="my_password"
export SNOWFLAKE_WAREHOUSE="my_warehouse"
# Optional:
export SNOWFLAKE_DATABASE="my_db"
export SNOWFLAKE_SCHEMA="my_schema"
export SNOWFLAKE_ROLE="my_role"
```

**2. Configuration file** `.sqliac/provider/credentials.toml`

```toml
[snowflake]
account = "my_account"
user = "my_user"
password = "my_password"
warehouse = "my_warehouse"
```

Environment variables take precedence. Run `sqliac init` to scaffold this file.

### Private key authentication

Set `SNOWFLAKE_PRIVATE_KEY_PATH` (relative path inside `.sqliac/provider/`) or `SNOWFLAKE_PRIVATE_KEY` (PEM string), optionally with `SNOWFLAKE_PRIVATE_KEY_PASSPHRASE`:

```bash
export SNOWFLAKE_ACCOUNT="my_account"
export SNOWFLAKE_USER="my_user"
export SNOWFLAKE_PRIVATE_KEY_PATH="rsa_key.p8"
```

### Using SQLIaC with Snowflake

```bash
# Scaffold a project with Snowflake examples
sqliac init

# Configure your credentials and edit definitions/
# then preview and apply:

sqliac apply --dry-run
sqliac apply
```

The `init` command creates Snowflake-ready example templates for `database`, `schema`, and `table` resources under `.sqliac/provider/`.

### Provider config

The adapter is registered via the `sqliac.adapters` entry point group. Your `.sqliac/provider/config.toml` should start with a top-level `[snowflake]` section:

```toml
[snowflake.database.ddl_command]
create = "CREATE OR ALTER"
alter  = "CREATE OR ALTER"
drop   = "DROP"

[snowflake.database.ddl_context]
object_name = "MODELING"
transient = false
data_retention_time_in_days = 1
wait_time = 0
[snowflake.database.ddl_context.depends_on]
```

## API

The adapter exposes three classes, all available from the top-level package:

```python
from sqliac_snowflake import SnowflakeAdapter, SnowflakeCredentials, SnowflakeConnectionManager
```

| Class | Role |
|-------|------|
| `SnowflakeAdapter` | Concrete `BaseAdapter` — executes queries and manages connections |
| `SnowflakeCredentials` | Frozen dataclass — validates and stores `account`, `user`, `password`, `warehouse`, etc. |
| `SnowflakeConnectionManager` | Thread-safe per-thread connection pool with keypair and password auth |

All three are registered via the entry point `sqliac.adapters / snowflake` and resolved automatically by the SQLIaC CLI. You don't need to import them directly unless building custom tooling.

### Supported credential fields

| Field | Required | Env var |
|-------|----------|---------|
| `account` | Yes | `SNOWFLAKE_ACCOUNT` |
| `user` | Yes | `SNOWFLAKE_USER` |
| `password` | (one of) | `SNOWFLAKE_PASSWORD` |
| `private_key_path` | (one of) | `SNOWFLAKE_PRIVATE_KEY_PATH` |
| `private_key` | (one of) | `SNOWFLAKE_PRIVATE_KEY` |
| `private_key_passphrase` | No | `SNOWFLAKE_PRIVATE_KEY_PASSPHRASE` |
| `warehouse` | No | `SNOWFLAKE_WAREHOUSE` |
| `database` | No | `SNOWFLAKE_DATABASE` |
| `schema` | No | `SNOWFLAKE_SCHEMA` |
| `role` | No | `SNOWFLAKE_ROLE` |

## License

MIT — see the [sqliac](https://pypi.org/project/sqliac/) package for details.
