PHPackages                             keboola/table-backend-utils - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. keboola/table-backend-utils

ActiveLibrary[Database &amp; ORM](/categories/database)

keboola/table-backend-utils
===========================

Package allows to import files to Snowflake from multiple cloud storages

4.1.0(2mo ago)057.5k↑132.9%1[1 PRs](https://github.com/keboola/php-table-backend-utils/pulls)5MITPHPPHP ^8.2

Since Apr 6Pushed 1mo ago16 watchersCompare

[ Source](https://github.com/keboola/php-table-backend-utils)[ Packagist](https://packagist.org/packages/keboola/table-backend-utils)[ RSS](/packages/keboola-table-backend-utils/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (22)Versions (227)Used By (5)

Table backend utils
===================

[](#table-backend-utils)

Common stuff for table backends (Snowflake|Redshift) shared between apps.

Interfaces
----------

[](#interfaces)

### Database

[](#database)

#### Keboola\\TableBackendUtils\\Database\\DatabaseReflectionInterface

[](#keboolatablebackendutilsdatabasedatabasereflectioninterface)

```
interface DatabaseReflectionInterface
{
    public function getUsersNames(?string $like = null): array;
    public function getRolesNames(?string $like = null): array;
}
```

### Schema

[](#schema)

#### Keboola\\TableBackendUtils\\Schema\\SchemaReflectionInterface

[](#keboolatablebackendutilsschemaschemareflectioninterface)

Function to retrieve information's about schema:

```
interface SchemaReflectionInterface
{
    public function getTablesNames(): array;
    public function getViewsNames(): array;
}
```

### Table

[](#table)

#### Keboola\\TableBackendUtils\\Table\\TableReflectionInterface

[](#keboolatablebackendutilstabletablereflectioninterface)

Function to retrieve information's about table:

```
interface TableReflectionInterface
{
    public function getColumnsNames(): array;
    public function getColumnsDefinitions(): ColumnCollection;
    public function getRowsCount(): int;
    public function getPrimaryKeysNames(): array;
    public function getTableStats(): TableStatsInterface;
    public function isTemporary(): bool;
    public function getDependentViews(): array;
}
```

#### Keboola\\TableBackendUtils\\Table\\TableQueryBuilderInterface

[](#keboolatablebackendutilstabletablequerybuilderinterface)

Queries to work with table:

```
interface TableQueryBuilderInterface
{
    public const TIMESTAMP_COLUMN_NAME = '_timestamp';
    public function getDropTableCommand(string $schemaName, string $tableName): string;
    public function getRenameTableCommand(string $schemaName, string $sourceTableName, string $newTableName): string;
    public function getTruncateTableCommand(string $schemaName, string $tableName): string;
    public function getCreateTempTableCommand(
        string $schemaName,
        string $tableName,
        ColumnCollection $columns
    ): string;
    public function getCreateTableCommand(
        string $schemaName,
        string $tableName,
        ColumnCollection $columns,
        array $primaryKeys = []
    ): string;
    public function getCreateTableCommandFromDefinition(
        TableDefinitionInterface $definition,
        bool $definePrimaryKeys = self::CREATE_TABLE_WITHOUT_PRIMARY_KEYS
    ): string;
}
```

#### Keboola\\TableBackendUtils\\Table\\TableStatsInterface

[](#keboolatablebackendutilstabletablestatsinterface)

Table statistics

```
interface TableStatsInterface
{
    public function getDataSizeBytes(): int;
    public function getRowsCount(): int;
}
```

### Column

[](#column)

#### Keboola\\TableBackendUtils\\Column\\ColumnInterface

[](#keboolatablebackendutilscolumncolumninterface)

Table column definition:

```
interface ColumnInterface
{
    public function getColumnName(): string;
    public function getColumnDefinition(): Keboola\Datatype\Definition\DefinitionInterface;
    public static function createGenericColumn(string $columnName): self;
}
```

### View

[](#view)

#### Keboola\\TableBackendUtils\\View\\ViewReflectionInterface

[](#keboolatablebackendutilsviewviewreflectioninterface)

Function to retrieve information's about view:

```
interface ViewReflectionInterface
{
    public function getDependentViews(): array;
}
```

### Auth

[](#auth)

#### Keboola\\TableBackendUtils\\Auth\\UserReflectionInterface

[](#keboolatablebackendutilsauthuserreflectioninterface)

```
interface UserReflectionInterface
{
    public function endAllSessions(): void;
    public function getAllSessionIds(): array;
}
```

#### Keboola\\TableBackendUtils\\Auth\\GrantQueryBuilderInterface

[](#keboolatablebackendutilsauthgrantquerybuilderinterface)

```
interface GrantQueryBuilderInterface
{
    public function getGrantSql(GrantOptionsInterface $options): string;

    public function getRevokeSql(RevokeOptionsInterface $options): string;
}
```

Development
-----------

[](#development)

### Preparation

[](#preparation)

Set up envs:

```
cp .env.dist .env
```

Set `TEST_PREFIX=` ENV

#### AWS

[](#aws)

In order to download TD odbc driver, create a user who can access S3 bucket with the driver package.

set up env variables:

```
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
```

#### Snowflake

[](#snowflake)

Prepare credentials for Snowflake access

```
CREATE ROLE "KEBOOLA_CI_TABLE_UTILS";
CREATE DATABASE "KEBOOLA_CI_TABLE_UTILS";

GRANT ALL PRIVILEGES ON DATABASE "KEBOOLA_CI_TABLE_UTILS" TO ROLE "KEBOOLA_CI_TABLE_UTILS";
GRANT USAGE ON WAREHOUSE "DEV" TO ROLE "KEBOOLA_CI_TABLE_UTILS";

CREATE USER "KEBOOLA_CI_TABLE_UTILS"
PASSWORD = 'my_secret_password'
DEFAULT_ROLE = "KEBOOLA_CI_TABLE_UTILS";

GRANT ROLE "KEBOOLA_CI_TABLE_UTILS" TO USER "KEBOOLA_CI_TABLE_UTILS";
```

set up env variables:

```
SNOWFLAKE_HOST=
SNOWFLAKE_PORT=443
SNOWFLAKE_USER=KEBOOLA_CI_TABLE_UTILS
SNOWFLAKE_PASSWORD='my_secret_password
SNOWFLAKE_DATABASE=KEBOOLA_CI_TABLE_UTILS
SNOWFLAKE_WAREHOUSE=

```

##### Setup snowflake Key-pair authentication

[](#setup-snowflake-key-pair-authentication)

For the new key-pair authentication, which will be the only preferred method going forward, please follow these steps:

1. Open a terminal window and generate a private key and a public key using the following command:

```
openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM -out rsa_key.p8 -nocrypt
openssl rsa -in rsa_key.p8 -pubout -out rsa_key.pub
```

2. Assign the public key to a Snowflake user using the following command:

```
ALTER USER "KEBOOLA_CI_TABLE_UTILS" SET RSA_PUBLIC_KEY='MIIBIjANBgkqh...';
```

Alternatively, you can use a command that generates a query for you:

```
PUBLIC_KEY=$(sed '1d;$d' rsa_key.pub | tr -d '\n')
echo "ALTER USER \"KEBOOLA_CI_TABLE_UTILS\" SET RSA_PUBLIC_KEY='${PUBLIC_KEY}';"
```

3. For local tests and CI we need to edit the private key to one line and trim `-----BEGIN PRIVATE KEY----- -----END PRIVATE KEY-----` We can do this with `cat rsa_key.p8 | sed '1d;$d' | tr -d '\n'`
4. Let's save the output of the command as environment variable `SNOWFLAKE_PRIVATE_KEY` in the `.env` file or in your PhpStorm.

```
PRIVATE_KEY=$(sed '1d;$d' rsa_key.p8 | tr -d '\n'); if grep -q '^SNOWFLAKE_PRIVATE_KEY=' .env; then sed -i "s|^SNOWFLAKE_PRIVATE_KEY=.*|SNOWFLAKE_PRIVATE_KEY=\"$PRIVATE_KEY\"|" .env; else echo "SNOWFLAKE_PRIVATE_KEY=\"$PRIVATE_KEY\"" >> .env; fi
```

#### Bigquery

[](#bigquery)

To prepare the backend you can use [Terraform template](bq-backend-init.tf). You must have the `resourcemanager.folders.create` permission for the organization.

```
# run in provisioning/local/BigQuery folder
terraform init

terraform apply -var folder_id= -var backend_prefix= -var billing_account_id=
# and enter name for your backend prefix for example your name, all resources will create with this prefix
```

After terraform apply ends go to the service project in folder created by terraform.

1. go to the newly created service project, the project id are listed at the end of the terraform call. (service\_project\_id)
2. click on IAM &amp; Admin
3. on left panel choose Service Accounts
4. click on email of service account(there is only one)
5. on to the top choose Keys and Add Key =&gt; Create new key
6. select Key type JSON
7. click on the Create button and the file will automatically download
8. convert key to string`awk -v RS= '{$1=$1}1' .json >> .env`
9. set content on last line of .env as variable `BQ_KEY_FILE`

setup envs:

```
BQ_KEY_FILE=
```

### Tests

[](#tests)

Run tests with following command.

```
docker compose run --rm dev composer tests
```

Unit and functional test can be run sepparetly

```
#unit test
docker compose run --rm dev composer tests-unit

#functional test
docker compose run --rm dev composer tests-functional
```

### Code quality check

[](#code-quality-check)

```
#phplint
docker compose run --rm dev composer phplint

#phpcs
docker compose run --rm dev composer phpcs

#phpcbf
docker compose run --rm dev composer phpcbf

#phpstan
docker compose run --rm dev composer phpstan
```

### Full CI workflow

[](#full-ci-workflow)

This command will run all checks load fixtures and run tests

```
docker compose run --rm dev composer ci
```

Teradata connection
-------------------

[](#teradata-connection)

You can use following method to get connection to Teradata for your queries

```
\Keboola\TableBackendUtils\Connection\Teradata\TeradataConnection::getConnection([
            'host' => getenv('TERADATA_HOST'),
            'user' => getenv('TERADATA_USERNAME'),
            'password' => getenv('TERADATA_PASSWORD'),
            'port' => getenv('TERADATA_PORT'),
            'dbname' => '',
        ]);
```

If you want to use connection via PHPStorm DataGrip or other DB client, remove port when you setting up connection in client. Otherwise test connection will fail.

License
-------

[](#license)

MIT licensed, see [LICENSE](./LICENSE) file.

###  Health Score

62

—

FairBetter than 99% of packages

Maintenance87

Actively maintained with recent releases

Popularity31

Limited adoption so far

Community29

Small or concentrated contributor base

Maturity88

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~23 days

Recently: every ~38 days

Total

93

Last Release

82d ago

Major Versions

v0.20.0 → v1.0.02022-05-18

1.15.1 → 2.0.02023-04-03

2.11.0 → 3.0.02025-04-11

3.2.0 → 4.0.02026-01-04

PHP version history (5 changes)v0.1PHP ^7.1

v0.17.0PHP ^7.4

v1.0.0PHP ^7.4|^8

2.0.0PHP ^8.1

3.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/101dbf2551a0709ddab522f97669f13a2c4cc2d0a1e8d009f3af6ba80accb1a9?d=identicon)[Keboola](/maintainers/Keboola)

---

Top Contributors

[![zajca](https://avatars.githubusercontent.com/u/180148?v=4)](https://github.com/zajca "zajca (245 commits)")[![jirkasemmler](https://avatars.githubusercontent.com/u/13363655?v=4)](https://github.com/jirkasemmler "jirkasemmler (133 commits)")[![romanbracinik](https://avatars.githubusercontent.com/u/6448364?v=4)](https://github.com/romanbracinik "romanbracinik (68 commits)")[![vojtabiberle](https://avatars.githubusercontent.com/u/528942?v=4)](https://github.com/vojtabiberle "vojtabiberle (25 commits)")[![tomasfejfar](https://avatars.githubusercontent.com/u/642928?v=4)](https://github.com/tomasfejfar "tomasfejfar (20 commits)")[![ErikZigo](https://avatars.githubusercontent.com/u/1726727?v=4)](https://github.com/ErikZigo "ErikZigo (18 commits)")[![martinsifra](https://avatars.githubusercontent.com/u/1210906?v=4)](https://github.com/martinsifra "martinsifra (4 commits)")[![martinjunger](https://avatars.githubusercontent.com/u/84506613?v=4)](https://github.com/martinjunger "martinjunger (3 commits)")[![ondrajodas](https://avatars.githubusercontent.com/u/12143866?v=4)](https://github.com/ondrajodas "ondrajodas (2 commits)")[![devin-ai-integration[bot]](https://avatars.githubusercontent.com/in/811515?v=4)](https://github.com/devin-ai-integration[bot] "devin-ai-integration[bot] (2 commits)")[![themark147](https://avatars.githubusercontent.com/u/17779619?v=4)](https://github.com/themark147 "themark147 (2 commits)")[![ujovlado](https://avatars.githubusercontent.com/u/419849?v=4)](https://github.com/ujovlado "ujovlado (1 commits)")[![Halama](https://avatars.githubusercontent.com/u/903531?v=4)](https://github.com/Halama "Halama (1 commits)")

---

Tags

php

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/keboola-table-backend-utils/health.svg)

```
[![Health](https://phpackages.com/badges/keboola-table-backend-utils/health.svg)](https://phpackages.com/packages/keboola-table-backend-utils)
```

###  Alternatives

[martin-georgiev/postgresql-for-doctrine

Extends Doctrine with native PostgreSQL support for arrays, JSONB, ranges, PostGIS geometries, text search, ltree, uuid, and 100+ PostgreSQL-specific functions.

4485.3M4](/packages/martin-georgiev-postgresql-for-doctrine)[damienharper/auditor-bundle

Integrate auditor library in your Symfony projects.

4542.8M](/packages/damienharper-auditor-bundle)[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

644989.8k1](/packages/sonata-project-entity-audit-bundle)[overtrue/laravel-versionable

Make Laravel model versionable.

585308.0k5](/packages/overtrue-laravel-versionable)[worksome/foggy

Foggy is a tool for making database dumps with some data removed/changed.

26571.7k1](/packages/worksome-foggy)[flow-php/doctrine-dbal-bulk

Bulk inserts and updates for Doctrine DBAL

14295.2k1](/packages/flow-php-doctrine-dbal-bulk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
