# validate

A command to confirm whether one or more SurrealQL files are valid or not.

Validate SurrealQL query files, or a query read from standard input, without connecting to a server.

> [!NOTE]
> **Before you start** - make sure you’ve [installed SurrealDB](/docs/running/installation.md).

<Synopsis>
surreal validate [OPTIONS] [PATTERNS]...
</Synopsis>

<OptionsTable
    title="Arguments"
    options={[
        {
            "name": "[PATTERNS]...",
            "default": "**/*.surql",
            "description": "Glob pattern for the files to validate. Several paths or patterns can be given at once."
        }
    ]}
/>

<OptionsTable
    title="Options"
    options={[
        {
            "name": "--stdin",
            "description": "Read the query from standard input instead of from files."
        },
        {
            "name": "--log",
            "short": "-l",
            "value": "<LOG>",
            "default": "info",
            "env": "SURREAL_LOG",
            "description": "The logging level for the command-line tool. Possible values: `none`, `full`, `error`, `warn`, `info`, `debug`, `trace`."
        }
    ]}
/>

## Example usage

To perform validation on a SurrealQL local file, in a terminal run the `surreal validate` command with the required argument.

Using the command on its own will validate all the `.surql` files in the current directory.

```bash
surreal validate
```

```text
user1.surql: OK
user2.surql: OK
user3.surql: OK
```

You can perform validation on a single file, regardless of extension.

```bash
surreal validate user.surql
surreal validate user.txt
```

You can also perform validation on multiple files using a single glob pattern:

```bash
# equivalent to "surreal validate"
surreal validate **/*.surql
```

Finally, you can also perform validation on multiple files using multiple paths/patterns:

```bash
surreal validate index.surql schemas/*.surql queries/*.surql
surreal validate *.(txt|surql)
```

If any files are invalid, the command will abort at this point and return an error.

```bash
surreal validate
```

```text
user1.surql: OK
user2.surql: KO
Parse error: Unexpected token `an identifier`, expected Eof
 --> [1:15]
  |
1 | CREATE person SE name = "Billy";
  |               ^^
```

## Validating input from stdin

_(since v3.1.0)_

In addition to files, this command can also be used on the terminal with the `--stdin` flag to validate input from stdin.

An example of a valid query:

```bash
echo "SELECT * FROM example;" | surreal validate --stdin
```

```text
<stdin>: OK
```

An example of an invalid query:

```bash
echo "CREATE WHERE value = ''" | surreal validate --stdin
```

```text
<stdin>: FAIL
Parse error: Unexpected token `VALUE`, expected Eof
 --> [1:14]
  |
1 | CREATE WHERE value = ''
  |              ^^^^^
```

## Command help

To see the help information and usage instructions, in a terminal run the `surreal validate --help` command without any further arguments. This command gives general information on the arguments, inputs, and additional options for the `validate` command.

```bash
surreal validate --help
```

The output of the above command:

```text
Validate SurrealQL query files

Usage: surreal validate [OPTIONS] [PATTERNS]...

Arguments:
  [PATTERNS]...  Glob pattern for the files to validate [default: **/*.surql]

Options:
  --stdin  Read query from standard input
  -h, --help  Print help

Logging:
  -l, --log <LOG>                              The logging level for the command-line tool [env: SURREAL_LOG=] [default: info] [possible
                                               values: none, full, error, warn, info, debug, trace]
      --log-format <LOG_FORMAT>                The format for terminal log output [env: SURREAL_LOG_FORMAT=] [default: text] [possible
                                               values: text, json]
      --log-socket <LOG_SOCKET>                Send logs to the specified host:port [env: SURREAL_LOG_SOCKET=]
      --log-file-level <LOG_FILE_LEVEL>        Override the logging level for file output [env: SURREAL_LOG_FILE_LEVEL=] [possible values:
                                               none, full, error, warn, info, debug, trace]
      --log-otel-level <LOG_OTEL_LEVEL>        Override the logging level for OpenTelemetry output [env: SURREAL_LOG_OTEL_LEVEL=] [possible
                                               values: none, full, error, warn, info, debug, trace]
      --log-socket-level <LOG_SOCKET_LEVEL>    Override the logging level for unix socket output [env: SURREAL_LOG_SOCKET_LEVEL=] [possible
                                               values: none, full, error, warn, info, debug, trace]
      --log-socket-format <LOG_SOCKET_FORMAT>  The format for socket output [env: SURREAL_LOG_SOCKET_FORMAT=] [default: text] [possible
                                               values: text, json]
      --log-file-enabled                       Whether to enable log file output [env: SURREAL_LOG_FILE_ENABLED=]
      --log-file-path <LOG_FILE_PATH>          The directory where log files will be stored [env: SURREAL_LOG_FILE_PATH=] [default: logs]
      --log-file-name <LOG_FILE_NAME>          The name of the log file [env: SURREAL_LOG_FILE_NAME=] [default: surrealdb.log]
      --log-file-format <LOG_FILE_FORMAT>      The format for log file output [env: SURREAL_LOG_FILE_FORMAT=] [default: text] [possible
                                               values: text, json]
      --log-file-rotation <LOG_FILE_ROTATION>  The log file rotation interval [env: SURREAL_LOG_FILE_ROTATION=] [default: daily] [possible
                                               values: daily, hourly, never]
```
