# SQLAlchemy Connection Pool based Snowflake connector for microservices.

Connection pools of SQLAlchemy are lazy, so for each newly established connection we have a 1 sec penalty +
some time to execute 4 `USE ...;` (or 2, if we're using only `USE ROLE` and `USE WAREHOUSE`, but instead of `USE
DATABASE` and `USE SCHEMA` we use fully qualified names in SQL templates, which is possible only with raw SQL approach,
but not with ORM) statements, but after we have parametrized connections which reside in pool.

## Raw SQL usage
Since SQLAlchemy ORM sometimes isn't optimal when generating queries, it would be better to use raw SQL via
`session.execute(sql_template, params_to_bind)`. We suggest to store SQL in plain text files, load them via SQLLoader
class and parametrize with identifiers (db, schema, table name) via BaseValidator class. For all the "bindable" params
we should always use binding. Such approach will help us to avoid SQL injections.


## Environment variables
Required env vars:
```bash
export SNOWFLAKE_ACCOUNT=
export SNOWFLAKE_USER=
export SNOWFLAKE_PASSWORD=
```

Optional env vars (it would be much safer to specify defaults in env anyway, otherwise it'll be your responsibility to make an app to use them):
```bash
export SNOWFLAKE_ROLE=
export SNOWFLAKE_DATABASE=
export SNOWFLAKE_SCHEMA=
export SNOWFLAKE_WAREHOUSE=
```

You can't specify SNOWFLAKE_SCHEMA and not specify SNOWFLAKE_DATABASE.  
