PHPackages                             scaleplan/sql-templater - 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. scaleplan/sql-templater

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

scaleplan/sql-templater
=======================

Query templater for PostgreSQL

1.0.0(6y ago)1112PHPPHP &gt;=7.0

Since Nov 25Pushed 5y ago1 watchersCompare

[ Source](https://github.com/scaleplan/sql-templater)[ Packagist](https://packagist.org/packages/scaleplan/sql-templater)[ RSS](/packages/scaleplan-sql-templater/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

SqlTemplater
============

[](#sqltemplater)

Helper class for SQL templating.

#### Installation

[](#installation)

`composer reqire scaleplan/sql-templater`

#### Description

[](#description)

Includes several predefined directives that can be included in SQL queries for simplicity:

- \####\[fields\]

Instead of this part of the SQL query inserts a string of data keys that came to the input, i.e. if we have a query:

```
INSERT INTO
  user
 ([fields])
VALUES
  ...

```

And data:

```
$data = [
    'name' = > 'Ivan'
    'surname' = > 'Fuckov'
];

```

then after processing the request will take the form:

```
INSERT INTO
  user
 (name,
  surname)
VALUES
  ...

```

This is useful if we do not know exactly which set of data will come to the entrance.

- #### \[fields:not(...)\]

    [](#fieldsnot)

The action is similar to  **\[fields\]** + inside *: not(...)*  (instead of points) you can specify a comma separated list of non-include fields, for example:

```
INSERT INTO
  user
 ([fields:not (sur)])
VALUES
  ...

```

converted to:

```
INSERT INTO
  user
 (name)
VALUES
  ...

```

with the same data.

- \####\[expression\]

Similar to  *\[fields\]* only fills in another part of the query, for example:

Request:

```
INSERT INTO
  user
 ([fields])
VALUES
  [expression]

```

and data:

```
$data = [
    'name' = > 'Ivan'
    'surname' = > 'Fuckov'
];

```

The result will be:

```
INSERT INTO
  user
 (name,
    surname)
VALUES
 (:name,
  : surname)

```

If there are multiple lines in the input:

```
$data = [
    [
        'name' = > 'Ivan'
        'surname' = > 'Fuckov'
    ],
    [
        'name' = > 'Vasiliy'
        'surname' = > 'Chekhov'
    ]
];

```

the result will be:

```
INSERT INTO
  user
 (name,
  surname)
VALUES
 (: name0,
  : surname0),
 (: name1,
   : surname1)

```

and the data will look like:

```
$data = [
    'name0' = > 'Ivan'
    'surname0' = > 'Fuckov'
    'name1' = > 'Vasiliy'
    'surname1' = > 'Chekhov'
];

```

- #### \[expression:not(...)\]

    [](#expressionnot)

I think here everything is clear - the substitution of placeholders - all except those inside *not(...)*

It should be noted that if among the parameter values there is an array, it can also be correctly processed:

Request:

```
INSERT INTO
  user
 ([fields])
VALUES
  [expression]

```

Characteristic:

```
$data = [
    'name' = > 'Ivan'
    'surname' = > 'Fuckov',
    'phone_numbers' => [
        '+7905555555',
        '+7904444444'
    ]
];

```

Result:

```
INSERT INTO
  user
 (name,
  surname)
VALUES
 (:name,
  : surname,
  ARRAY [: phone_numbers0, phone_numbers1])

```

This conversion can be disabled by passing the template parameter *$convertArrays* with the value *false*.

In addition, it is possible to use the optional parts of the query, which are used only if the parameters used in them, for example:

```
SELECT
  *
FROM
  user
[WHERE
  group =: group]

```

If data is transferred:

```
$data = [
    'group' = > 'admins'
];

```

then the resulting query will be:

```
SELECT
  *
FROM
  user
WHERE
  group =: group

```

and if the *group* parameter is passed, the condition will be completely thrown out and the query will return all users.

[Class documentation](docs_en)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 89.3% of commits — single point of failure

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 ~764 days

Total

2

Last Release

2329d ago

Major Versions

v0.1 → 1.0.02019-12-30

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10077243?v=4)[Aleksandr Avtomonov](/maintainers/avtomon)[@avtomon](https://github.com/avtomon)

---

Top Contributors

[![avtomon](https://avatars.githubusercontent.com/u/10077243?v=4)](https://github.com/avtomon "avtomon (25 commits)")[![qooiz](https://avatars.githubusercontent.com/u/53611552?v=4)](https://github.com/qooiz "qooiz (3 commits)")

### Embed Badge

![Health badge](/badges/scaleplan-sql-templater/health.svg)

```
[![Health](https://phpackages.com/badges/scaleplan-sql-templater/health.svg)](https://phpackages.com/packages/scaleplan-sql-templater)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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