Skip to content

v0.6.0

Latest

Choose a tag to compare

@mibk mibk released this 16 Nov 12:10

Breaking changes

  • Go 1.25 is required (was Go 1.20).
  • dialect.Dialect method PrintPlaceholderSign is renamed to WritePlaceholder. Custom dialects must rename the method; the built-in MySQL dialect is updated.
  • db:"-" and selectonly now apply to struct-typed fields. Previously dali recursed into such a field before reading its tag, so its subfields were still selected, inserted or updated. A field tagged db:"-" is now skipped entirely, and a selectonly struct field is skipped by ?values and ?set.
  • MySQL strings and byte slices escape ' as '' instead of \'. The doubled quote means a quote both in the default SQL mode and with NO_BACKSLASH_ESCAPES, where \' let a value break out of the literal. Only code that asserts on the generated SQL is affected.
  • Open returns an error for an unsupported driver instead of panicking.
  • Query.String returns error: … for a query that fails to expand instead of panicking.

Renames (old names kept as deprecated aliases)

  • Translator → Expander, and Translator.Translate → Expander.Expand.
  • dialect.Dialect → dialect.Escaper.

Existing code, including Marshaler implementations taking a Translator, keeps compiling.

New

  • DB.AddMiddlewareFunc adds a middleware on top of those already set, instead of replacing them as SetMiddlewareFunc does.

  • Errors from a driver.Valuer or a Marshaler are wrapped with %w, so errors.Is and errors.As see them.

  • dalivet, a go vet-style analyzer for dali, released as its own module (dalivet/v0.1.0). Building it needs Go 1.26 or newer. It reports non-constant query strings, placeholder/argument mismatches, wrong destinations of One, All and ScanAllRows, slices passed to ?... or ?values... without a length check, and unknown db tag options:

    go install github.com/mibk/dali/dalivet/cmd/dalivet@latest
    go vet -vettool=$(which dalivet) ./...
    

Fixes

  • Fields of a struct nested three levels deep (embedded or a named struct field) all got the index of the struct’s last field, so every one of them was loaded into, or inserted from, that last field.

Performance

  • Derived column lists are cached per type, and escaping identifiers no longer allocates a replacer per call.

Upcoming

  • dali ignores unknown db tag options today (db:"id,readonly" still inserts the field). A future version will reject them at run time; run dalivet to find them now.

Notes

  • An empty or nil slice passed to ?... is an error, as in v0.5. Check the length before running the query.
  • dali escapes values itself rather than sending bind parameters. It is safe on MySQL/MariaDB connections using a UTF-8 character set; see the README for the caveats about multi-byte charsets such as GBK and NO_BACKSLASH_ESCAPES.