davidlienhard/database-query-validator

🐘 php tool to validate database queries

0.4.7 2022-11-07 21:01 UTC

README

🐘 php tool to validate database queries written using davidlienhard/database

Latest Stable Version Source Code Software License Minimum PHP Version CI Status

Configuration

This tool requires a file named query-validator.json in your main project directory. CLI arguments are not supported at the moment. The following configuration options are possible:

  • paths (array): list of paths (folders or files) to scan.
  • exclusions (array): list of paths to exclude from the scans
  • dumpfile (string): path to a mysql dump file to use for type-checks
  • parameters (object):
    • ignoresyntax (bool): whether or not to ignore syntax-errors in the queries
    • strictinserts (bool): checks if inserts contains all text-colums of table that are set to not null
    • strictinsertsignoremissingtablenames (bool): whether to ignore queries where the tablename could not be extracted on strict imports

All paths are relative to the path of the configuration file. If no configuration file can be found all the files in your currect folder will be scanned.

Example Configuration-File

JSON

{
    "paths": [
        "src"
    ],
    "exclusions": [
        "**/exclude.php"
    ],
    "dumpfile": "dump.sql",
    "parameters": {
        "ignoresyntax": false,
        "strictinserts": false
    }
}

YAML

paths:
  - src
exclusions:
  - "**/exclude.php"
dumpfile: dump.sql
parameters:
  ignoresyntax: false
  strictinserts: false

Todo

This project is still work in progress and there is a lot of work todo.

  • improve validation of queries
  • improve documentation (of course)
  • add unit tests
  • improve recognition of database-queries
  • improve config
    • add support of CLI arguments

License

The MIT License (MIT). Please see LICENSE for more information.