PHPackages                             aryelgois/yasql-php - 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. aryelgois/yasql-php

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

aryelgois/yasql-php
===================

A PHP implementation for YAML Ain't SQL

v0.6.0(8y ago)41053MITPHPPHP ^7.0

Since Dec 22Pushed 8y ago1 watchersCompare

[ Source](https://github.com/aryelgois/yasql-php)[ Packagist](https://packagist.org/packages/aryelgois/yasql-php)[ RSS](/packages/aryelgois-yasql-php/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (1)Versions (14)Used By (3)

YASQL-PHP
=========

[](#yasql-php)

Index:

- [Intro](#intro)
- [Install](#install)
- [Setup](#setup)
- [Usage](#usage)
    - [yasql-build](#yasql-build)
    - [yasql-generate](#yasql-generate)
- [API](#api)
    - [Composer](#composer)
    - [Controller](#controller)
    - [Parser](#parser)
    - [Generator](#generator)
    - [Builder](#builder)
        - [config file](#config-file)
    - [Populator](#populator)
    - [Utils](#utils)
- [Changelog](CHANGELOG.md)

Intro
=====

[](#intro)

This is a PHP implementation for **YAML Ain't SQL**, whose specification can be found in [aryelgois/yasql](https://github.com/aryelgois/yasql).

Install
=======

[](#install)

Enter the terminal, navigate to your project root and run:

`composer require aryelgois/yasql-php`

Setup
=====

[](#setup)

This package provides CLI tools to work with YASQL files. To use them, add the following in your `composer.json`:

```
{
    "scripts": {
        "yasql-build": "aryelgois\\YaSql\\Composer::build",
        "yasql-generate": "aryelgois\\YaSql\\Composer::generate"
    }
}
```

You also need a [config file](#config-file) for the builder command. The default is to place it in `config/databases.yml`, but you can choose another place or have more than one configuration.
*(see [Builder](#builder) specifications)*

Usage
=====

[](#usage)

### yasql-build

[](#yasql-build)

First, create databases following the [YASQL](https://github.com/aryelgois/yasql) schema and list them in your [config file](#config-file). Then run the following command in your project root:

```
composer yasql-build -- [ config=path/to/config_file.yml | -c ]
                        [ output=path/to/output/ ]
                        [ vendor=vendor/package ]
```

- `config`: Lists YASQL databases to be built and vendors to include
    - The `-c` flag indicates that you do not want any config file. It is useful when using `vendor` arguments. It is the same as `config=''`
- `output`: Directory where files are generated
- `vendor`: Additional vendor to include (using default config file location)

Notes:

- Paths in the command line are relative to the project root
- Paths in the config file are relative to the file itself
- Absolut paths are absolut (they start with `/`)
- Vendors are located in Composer's `vendor dir`
- You can omit `config` for using the default `config/databases.yml`
- You can omit `output` for using the default `build/`
- You can add multiple `vendor` arguments
- It might be a good idea to add the output directory to your .gitignore

This command creates `.sql` files in the output directory, so you can import them into your sql server.

### yasql-generate

[](#yasql-generate)

If you only want to generate the SQL from one YASQL schema, run the following command:

`composer yasql-generate -- path/to/yasql.yml [ indentation ]`

The first argument is the path to a YASQL file, the second is a optional indentation to be used (default is 2 spaces).

It will output to stdout, so you can add something like ` > output_database.sql`to write the result in a file.

API
===

[](#api)

This package provides some classes to parse YASQL and generate SQL. They are under the namespace `aryelgois\YaSql`.

[Composer](src/Composer.php)
----------------------------

[](#composer)

Provides Composer scripts to use this package from the command line.
*(see how to configure the commands in [Setup](#setup))*

- *static* **build(** [Event](https://getcomposer.org/apidoc/master/Composer/Script/Event.html) $event **)**

    It accepts arguments described in [yasql-build](#yasql-build).
- *static* **generate(** [Event](https://getcomposer.org/apidoc/master/Composer/Script/Event.html) $event **)**

    It accepts arguments described in [yasql-generate](#yasql-generate).

[Controller](src/Controller.php)
--------------------------------

[](#controller)

This class wrapps others, to make them easier to use.

- *static* **build(** [string](https://secure.php.net/manual/en/language.types.string.php) $output , [string](https://secure.php.net/manual/en/language.types.string.php) $config , [string](https://secure.php.net/manual/en/language.types.string.php) $vendor \[, [array](https://secure.php.net/manual/en/language.types.array.php) $vendors \] **)**

    Use this method to build your databases into a specific directory.
    *(see [Builder](#builder))*
- *static* **generate(** [string](https://secure.php.net/manual/en/language.types.string.php) $yasql \[, [int](https://secure.php.net/manual/en/language.types.integer.php) $indent \] **)**

    Use this to generate the SQL from a YASQL and get the result in a string.
    *(see [Generator](#generator))*
- *static* **parse(** [string](https://secure.php.net/manual/en/language.types.string.php) $yasql **)**

    Use it to dump the parsed data from a YASQL. Basically, good for debugging.
    *(see [Parser](#parser))*

[Parser](src/Parser.php)
------------------------

[](#parser)

- **\_\_construct(** [string](https://secure.php.net/manual/en/language.types.string.php) $yasql **)**

    It parses a YASQL and extracts some data from each column, making them ready for the Generator.

    See the `$yasql` specification [here](https://github.com/aryelgois/yasql).
- **getData()**

    Retrieves the parsed data in a multidimensional array.

[Generator](src/Generator.php)
------------------------------

[](#generator)

- **\_\_construct(** [Parser](src/Parser.php) $parser \[, [int](https://secure.php.net/manual/en/language.types.integer.php) $indent \] **)**

    Produces SQL that generates a database. It asks for a Parser object to ensure the data is valid.
- **output()**

    Retrieves the generated SQL in a multi line string.

[Builder](src/Builder.php)
--------------------------

[](#builder)

- **\_\_construct(** \[ [string](https://secure.php.net/manual/en/language.types.string.php) $output \[, [string](https://secure.php.net/manual/en/language.types.string.php) $vendor \] \] **)**

    Creates a new Builder object. Databases will go into `$output`, and vendors are searched in `$vendors`. Both paths can be absolut or relative, and default to `build/` and `vendor/` in the current working directory, respectively.
- **build(** [string](https://secure.php.net/manual/en/language.types.string.php) $config \[, [array](https://secure.php.net/manual/en/language.types.array.php) $vendors \] **)**

    Generates a list of databases listed in `$config` file into the object's output directory.
- **getLog()**

    Retrieves log information from the build process.

### config file

[](#config-file)

A [YAML](http://yaml.org/) with the following keys: (all are optional)

- `databases`: sequence of files with YASQL database schemas. It can be a string or a mapping of the YASQL `path` and a `post` sql (or a sequence of post files)

    Also, a `name` can be defined to overwrite the database's name. It is useful when you want to combine multiple database schemas in a single database. Just be careful with conflicting tables. Also note that external foreigns require special care in the file order that you run in the sql server
- `indentation`: used during the sql generation
- `vendors`: a map of vendors installed by Composer to config files inside them. It can be a string (for a single config) or a sequence of paths. They are relative to the vendor package root. Using `~` (yaml null) denotes the [default config file path](#setup)

Example:

```
databases:
  - ../tests/example.yml
  - path: ../data/mydatabase.yml
    post: ../data/mydatabase_populate.sql
    name: AwesomeExample

indentation: 4

vendors:
  someone/package: config/databases.yml
```

The post file is useful for pre populated rows or to apply sql commands not covered by YASQL specification. Its content is appended to the generated sql.

[Populator](src/Populator.php)
------------------------------

[](#populator)

A helper class for [Builder](#builder). Use it to generate `INSERT INTO` statements to populate your databases.

This class is *abstract*, so you have to write a class that extends it. The reason is that the YAML with the data might be in a arbitrary layout, depending on your database schema.

To use it, you need a special post in the [builder config](#config-file):

Example from [aryelgois/databases](https://github.com/aryelgois/databases):

```
databases:
  - path: ../data/address.yml
    post:
      - ../data/address/populate_countries.sql
      - call: aryelgois\Databases\AddressPopulator
        with:
          - ../data/address/source/Brazil.yml
```

The post must map to a sequence, and the desired item is a map of:

- `call`: a fully qualified class that extends [Populator](#populator), autoloadable by Composer
- `with`: path to a YAML with the data to be processed. It can be a sequence

[Utils](src/Utils.php)
----------------------

[](#utils)

There is also a class with utility methods. They are used internally and can be used by whoever requires this package.

- **arrayAppendLast(** [array](https://secure.php.net/manual/en/language.types.array.php) $array , [string](https://secure.php.net/manual/en/language.types.string.php) $last \[, [string](https://secure.php.net/manual/en/language.types.string.php) $others \] **)**

    Appends a string to the last item. Optionally, appends a string to the others. It is useful to generate sql statements with a list of comma separated items, and a semicolon at the last item.

[Changelog](CHANGELOG.md)
=========================

[](#changelog)

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~14 days

Recently: every ~27 days

Total

12

Last Release

2955d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0f95855ecc3be665cdac87d201a24f763b0abb9c0fea4297b5f0bab4bff5e3b0?d=identicon)[aryelgois](/maintainers/aryelgois)

---

Top Contributors

[![aryelgois](https://avatars.githubusercontent.com/u/21041013?v=4)](https://github.com/aryelgois "aryelgois (163 commits)")

---

Tags

databasephpschemasqlyamlyaml-aint-sqlyasqlphpschemadatabaseyamlsqlyasql

### Embed Badge

![Health badge](/badges/aryelgois-yasql-php/health.svg)

```
[![Health](https://phpackages.com/badges/aryelgois-yasql-php/health.svg)](https://phpackages.com/packages/aryelgois-yasql-php)
```

###  Alternatives

[clouddueling/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k23.1k](/packages/clouddueling-mysqldump-php)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1175.2k](/packages/rcsofttech-audit-trail-bundle)[perplorm/perpl

Perpl is an improved and still maintained fork of Propel2, an open-source Object-Relational Mapping (ORM) for PHP.

249.4k](/packages/perplorm-perpl)[friedolinfoerder/wp-activerecord

An ActiveRecord implementation for WordPress

237.6k](/packages/friedolinfoerder-wp-activerecord)

PHPackages © 2026

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