Documentation version: latest
Colour theme
The simple API provides high-level functions for linting, fixing, and parsing SQL strings.
An exception which holds a set of violations.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
violations | list[SQLBaseError] | ||
args | Any |
fix(
sql,
dialect=None,
rules=None,
exclude_rules=None,
config=None,
config_path=None,
fix_even_unparsable=None
) → strFix a SQL string.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
sql | str | The SQL to be fixed. | |
dialect | str | None | None | A reference to the dialect of the SQL to be fixed. Defaults to ansi. |
rules | list[str] | None | None | A subset of rule references to fix for. Defaults to None. |
exclude_rules | list[str] | None | None | A subset of rule references to avoid fixing for. Defaults to None. |
config | FluffConfig | None | None | A configuration object to use for the operation. Defaults to None. |
config_path | str | None | None | A path to a .sqlfluff config, which is only used if a config is not already provided. Defaults to None. |
fix_even_unparsable | bool | None | None | Optional override for the corresponding SQLFluff configuration value. |
Returns:
str — str for the fixed SQL if possible.
get_simple_config(
dialect=None,
rules=None,
exclude_rules=None,
config_path=None
) → FluffConfigGet a config object from simple API arguments.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
dialect | str | None | None | |
rules | list[str] | None | None | |
exclude_rules | list[str] | None | None | |
config_path | str | None | None |
Returns:
FluffConfig — See return type above
lint(
sql,
dialect=None,
rules=None,
exclude_rules=None,
config=None,
config_path=None
) → list[dict[str, Any]]Lint a SQL string.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
sql | str | The SQL to be linted. | |
dialect | str | None | None | A reference to the dialect of the SQL to be linted. Defaults to ansi. |
rules | list[str] | None | None | A list of rule references to lint for. Defaults to None. |
exclude_rules | list[str] | None | None | A list of rule references to avoid linting for. Defaults to None. |
config | FluffConfig | None | None | A configuration object to use for the operation. Defaults to None. |
config_path | str | None | None | A path to a .sqlfluff config, which is only used if a config is not already provided. Defaults to None. |
Returns:
list[dict[str, Any]] — list[dict[str, Any]] for each violation found.
parse(
sql,
dialect=None,
config=None,
config_path=None
) → dict[str, Any]Parse a SQL string.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
sql | str | The SQL to be parsed. | |
dialect | str | None | None | A reference to the dialect of the SQL to be parsed. Defaults to ansi. |
config | FluffConfig | None | None | A configuration object to use for the operation. Defaults to None. |
config_path | str | None | None | A path to a .sqlfluff config, which is only used if a config is not already provided. Defaults to None. |
Returns:
dict[str, Any] — Dict[str, Any] JSON containing the parsed structure.
Note: In the case of multiple potential variants from the raw source file only the first variant is returned by the simple API. For access to the other variants, use the underlying main API directly.