Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ package qfv
// (https://www.postgresql.org/docs/current/features-sql-standard.html), and
// against what its manual calls an extension.
//
// A Dialect is one of the values below; the zero value is DialectPostgreSQL,
// the grammar this package has always parsed.
// A Dialect is one of the values below, each a version of its SQL: PostgreSQL
// 18, SQL:2023. The zero value is DialectPostgreSQL, the grammar this package
// has always parsed.
type Dialect struct {
name string
}
Expand All @@ -27,7 +28,7 @@ var (
DialectPostgreSQL = Dialect{}

// DialectSQLStandard is the SQL standard, ISO/IEC 9075:2023 (SQL:2023),
// Part 2 (Foundation). It is PostgreSQL's grammar without what
// Part 2 (Foundation). It is PostgreSQL 18's grammar without what
// PostgreSQL's manual calls its own:
//
// - != (the standard's "not equal" is <>);
Expand All @@ -50,10 +51,11 @@ var (
DialectSQLStandard = Dialect{name: "SQL:2023"}
)

// String is the dialect's name, as error messages write it.
// String is the dialect's name with its version, as error messages write it:
// "PostgreSQL 18", "SQL:2023".
func (d Dialect) String() string {
if d.name == "" {
return "PostgreSQL"
return "PostgreSQL 18"
}

return d.name
Expand Down
6 changes: 3 additions & 3 deletions dialect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func TestTheDefaultDialectIsPostgreSQL(t *testing.T) {
t.Parallel()

var zero Dialect
if zero != DialectPostgreSQL || zero.String() != "PostgreSQL" {
t.Errorf("the zero Dialect is %q, want PostgreSQL", zero)
if zero != DialectPostgreSQL || zero.String() != "PostgreSQL 18" {
t.Errorf("the zero Dialect is %q, want PostgreSQL 18", zero)
}

if got := DialectPostgreSQL.Operators(); !slices.Equal(got, AllOperators()) {
Expand All @@ -73,7 +73,7 @@ func TestTheDefaultDialectIsPostgreSQL(t *testing.T) {
} {
for _, tt := range postgresOnly {
if _, err := parser.Parse(tt.input); err != nil {
t.Errorf("Parse(%q): %v, want it accepted in PostgreSQL", tt.input, err)
t.Errorf("Parse(%q): %v, want it accepted in PostgreSQL 18", tt.input, err)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// The filter parser reads an SQL boolean expression and returns its AST. It
// checks an expression and does not translate one, so what it accepts is
// what the SQL it will run as accepts: by default PostgreSQL's grammar, as
// what the SQL it will run as accepts: by default PostgreSQL 18's grammar, as
// PostgreSQL 18 runs it; with WithDialect(DialectSQLStandard), the SQL
// standard's (ISO/IEC 9075:2023), which refuses PostgreSQL's own spellings
// such as != and ILIKE. WithAllowedOperators and WithAllowedOperatorGroups
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ flowchart TB
allow -. gates .-> FilterParser
allow -. gates .-> SortParser

dialect(["SQL dialect<br/>PostgreSQL (default) · SQL:2023"])
dialect(["SQL dialect<br/>PostgreSQL 18 (default) · SQL:2023"])
dialect -. grammar .-> FilterParser
```

Expand Down
5 changes: 3 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Configuration

By default the filter parser reads PostgreSQL's grammar and accepts every
By default the filter parser reads PostgreSQL 18's grammar and accepts every
operator, and the sort parser accepts both `ASC` and `DESC`. You can choose
the SQL dialect, and narrow either, with functional options at construction
time.
Expand Down Expand Up @@ -50,7 +50,8 @@ The dialect comes before the allow-list: an operator the dialect does not have
is refused whether `WithAllowedOperators` allows it or not.

A dialect is a value of the `Dialect` type, and the zero value is
`DialectPostgreSQL`; there is no way to name one that does not exist.
`DialectPostgreSQL`; there is no way to name one that does not exist. Each
names its version: `String()` is `PostgreSQL 18` or `SQL:2023`.
Another database's grammar (MySQL's, for instance: `REGEXP`, `<=>`,
backslash escapes in strings) is a dialect to add, with its own tests run
against that database.
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ explicitly permit can appear in a query. This is the primary defense against
invalid or malicious input reaching your database.

The filter parser checks an expression in the grammar of the SQL it will run
as, and does not translate it: **PostgreSQL's by default**, or the SQL
as, and does not translate it: **PostgreSQL 18's by default**, or the SQL
standard's with `WithDialect(qfv.DialectSQLStandard)`. See
[the SQL dialect](configuration.md#the-sql-dialect).

Expand Down
10 changes: 8 additions & 2 deletions docs/migration.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# Migration Guide

## v1.1.0 → v1.1.1

`DialectPostgreSQL.String()` is `PostgreSQL 18`, where it was `PostgreSQL`:
each dialect names its version, as `DialectSQLStandard`'s `SQL:2023` does.
Only a caller that compares the string changes; the grammar does not.

## v1.0.5 → v1.1.0

Two additions: the SQL dialect a filter is written in, and the `ESCAPE`
clause. A caller that changes nothing gets PostgreSQL's grammar, as before,
clause. A caller that changes nothing gets PostgreSQL 18's grammar, as before,
with `ESCAPE` accepted.

### The SQL dialect

`WithDialect` chooses the grammar a filter is checked in:
`DialectPostgreSQL`, the default and what every earlier version parsed, or
`DialectPostgreSQL` (PostgreSQL 18), the default and what every earlier version parsed, or
`DialectSQLStandard`, ISO/IEC 9075:2023, which refuses PostgreSQL's own
spellings (`!=`, `ILIKE`, the `~~` and `~` operators, `ISNULL`/`NOTNULL`, an
empty `ESCAPE`). The table is in
Expand Down
Loading