drizzle 0.2.0

A type-safe SQL query builder for Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
name: CI

on:
  workflow_dispatch:
  # CI normally runs on pull requests only. The manual dispatch path is used by
  # update.yml for release-plz PRs, because PRs opened by GITHUB_TOKEN do not
  # trigger normal pull_request workflow runs.
  pull_request:
    branches: [main]

env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: 1
  RUST_TEST_THREADS: 4

jobs:
  lint:
    name: Lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6

      - name: Install Rust
        uses: dtolnay/rust-toolchain@nightly
        with:
          components: rustfmt, clippy

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: nightly
          save-if: ${{ github.ref == 'refs/heads/main' }}

      - name: Check formatting
        run: cargo fmt --all -- --check

      - name: Run clippy
        run: cargo clippy --workspace --all-targets --all-features -- -D warnings

  test-matrix:
    name: Test Matrix
    runs-on: ubuntu-latest
    needs: lint
    outputs:
      sqlite: ${{ steps.matrix.outputs.sqlite }}
      pg: ${{ steps.matrix.outputs.pg }}
    steps:
      - uses: actions/checkout@v6

      - name: Install just
        uses: taiki-e/install-action@just

      - name: Generate matrices
        id: matrix
        run: |
          echo "sqlite=$(just test::sqlite-matrix-json)" >> $GITHUB_OUTPUT
          echo "pg=$(just test::pg-matrix-json)" >> $GITHUB_OUTPUT

  test-sqlite:
    name: "test::sqlite (${{ matrix.features }})"
    runs-on: ubuntu-latest
    needs: test-matrix
    strategy:
      fail-fast: false
      matrix:
        features: ${{ fromJson(needs.test-matrix.outputs.sqlite) }}
    steps:
      - uses: actions/checkout@v6

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Install just
        uses: taiki-e/install-action@just

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: stable
          save-if: ${{ github.ref == 'refs/heads/main' }}

      - name: Run tests
        run: just test::sqlite "${{ matrix.features }}"

      - name: Run SQLite INSERT SELECT compile-time tests
        if: matrix.features == 'rusqlite'
        run: >-
          cargo test -p drizzle --no-default-features
          --features std,sqlite,serde
          --test compile_fail insert_select_sqlite_ui

      - name: Run SQLite math-extension tests
        # .cargo/config.toml builds bundled rusqlite with SQLITE_ENABLE_MATH_FUNCTIONS.
        if: startsWith(matrix.features, 'rusqlite,')
        run: >-
          cargo test -p drizzle --features "${{ matrix.features }},math"
          --test lib -- shared_math_extensions optional_math_functions

      - name: Run SQLite strict-decode compile-time tests
        if: matrix.features == 'rusqlite'
        run: >-
          cargo test -p drizzle --features rusqlite,uuid,serde
          --test compile_fail strict_decode_ui

      - name: Run example
        if: contains(matrix.features, 'uuid')  && startsWith(matrix.features, 'rusqlite')
        run: cargo run --example rusqlite --features "rusqlite,uuid,serde"

  test-sqlite-unification:
    name: Test SQLite Feature Unification
    runs-on: ubuntu-latest
    needs: lint
    steps:
      - uses: actions/checkout@v6

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: stable
          save-if: ${{ github.ref == 'refs/heads/main' }}

      - name: Run feature-unification regression
        run: cargo test -p drizzle --test sqlite_backend_feature_gating --features "rusqlite,libsql,uuid" -- --test-threads=4

  test-downstream:
    name: Test Downstream Consumers
    runs-on: ubuntu-latest
    needs: lint
    steps:
      - uses: actions/checkout@v6

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: stable
          save-if: ${{ github.ref == 'refs/heads/main' }}

      - name: Download locked dependencies
        # The fixtures check offline against Cargo.lock, so every crate it
        # lists must already be in the registry cache, including the ones the
        # test harness itself never builds.
        run: cargo fetch --locked

      - name: Compile consumer crates against the derive macros
        # Standalone crates that depend only on `drizzle`: catches expansions
        # that read the consumer's cargo features or name crates it may not
        # depend on. See tests/downstream_consumers.rs.
        run: cargo test -p drizzle --test downstream_consumers -- --ignored --test-threads=2

  test-pg:
    name: "test::pg (${{ matrix.features }})"
    runs-on: ubuntu-latest
    needs: test-matrix
    strategy:
      fail-fast: false
      matrix:
        features: ${{ fromJson(needs.test-matrix.outputs.pg) }}
    steps:
      - uses: actions/checkout@v6

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Install just
        uses: taiki-e/install-action@just

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: stable
          save-if: ${{ github.ref == 'refs/heads/main' }}

      - name: Run tests
        run: just test::pg "${{ matrix.features }}"

      - name: Run PostgreSQL INSERT SELECT compile-time tests
        if: matrix.features == 'postgres-sync'
        run: >-
          cargo test -p drizzle --no-default-features
          --features std,postgres,serde
          --test compile_fail insert_select_postgres_ui

  test-mysql:
    name: "Test MySQL (${{ matrix.name }})"
    runs-on: ubuntu-latest
    needs: lint
    strategy:
      fail-fast: false
      matrix:
        include:
          - name: sync
            mysql-version: "8.4"
            features: mysql-sync
            test-features: mysql-sync,query,serde,uuid,chrono,time,jiff,rust-decimal,arrayvec,compact-str,bytes,smallvec-types
          - name: async
            mysql-version: "8.4"
            features: mysql-async
            test-features: mysql-async,query,serde,uuid,chrono,time,jiff,rust-decimal,arrayvec,compact-str,bytes,smallvec-types
          - name: unified
            mysql-version: "8.4"
            features: mysql-sync,mysql-async
            test-features: mysql-sync,mysql-async,query,serde,uuid,chrono,time,jiff,rust-decimal,arrayvec,compact-str,bytes,smallvec-types
          # Run the same minimal/full/live contracts through each adapter on
          # the oldest server in the documented compatibility range.
          - name: minimum-sync
            mysql-version: "8.0.31"
            features: mysql-sync
            test-features: mysql-sync,query,serde,uuid,chrono,time,jiff,rust-decimal,arrayvec,compact-str,bytes,smallvec-types
          - name: minimum-async
            mysql-version: "8.0.31"
            features: mysql-async
            test-features: mysql-async,query,serde,uuid,chrono,time,jiff,rust-decimal,arrayvec,compact-str,bytes,smallvec-types
    services:
      mysql:
        image: mysql:${{ matrix.mysql-version }}
        env:
          MYSQL_ROOT_PASSWORD: mysql
          MYSQL_DATABASE: drizzle_test
          MYSQL_USER: drizzle
          MYSQL_PASSWORD: drizzle
        ports:
          - 3306:3306
        options: >-
          --health-cmd="mysqladmin ping -h 127.0.0.1 -udrizzle -pdrizzle --silent && mysql -h 127.0.0.1 -udrizzle -pdrizzle drizzle_test -e 'SELECT 1'"
          --health-interval=2s
          --health-timeout=5s
          --health-retries=30
    env:
      DRIZZLE_MYSQL_URL: mysql://drizzle:drizzle@127.0.0.1:3306/drizzle_test
    steps:
      - uses: actions/checkout@v6

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: stable
          save-if: ${{ github.ref == 'refs/heads/main' }}

      - name: Check adapter features
        run: cargo check -p drizzle --no-default-features --features "${{ matrix.features }},query"

      - name: Check driver-neutral dialect surface
        if: matrix.name == 'sync'
        run: cargo check -p drizzle --no-default-features --features mysql

      - name: Reject async runtime dependencies
        if: matrix.name == 'sync'
        shell: bash
        run: |
          if cargo tree -p drizzle --no-default-features --features mysql-sync,query --edges normal \
            | grep -E '(^|[[:space:]])(tokio|mysql_async) v'; then
            echo "mysql-sync pulled an async runtime dependency"
            exit 1
          fi
          if cargo tree -p drizzle-cli --no-default-features --features mysql-sync --edges normal \
            | grep -E '(^|[[:space:]])(tokio|mysql_async) v'; then
            echo "drizzle-cli mysql-sync pulled an async runtime dependency"
            exit 1
          fi

      - name: Run MySQL compile-time tests
        if: matrix.name == 'sync'
        # The relational `query` feature exposes a second public
        # `QueryBuilder` and another generated projection path. Those only
        # change rustc diagnostics, so keep the macro and dialect-builder
        # snapshots on their native feature graph and exercise them once.
        run: |
          cargo test -p drizzle --no-default-features \
            --features mysql-sync,serde \
            --test compile_fail mysql_macros_ui
          cargo test -p drizzle --no-default-features \
            --features mysql-sync,serde \
            --test compile_fail mysql_builder_ui

      - name: Run minimal MySQL adapter tests
        # The bare adapter graph proves that optional query and value-codec
        # integrations are additions, not hidden requirements.
        run: cargo test -p drizzle --no-default-features --features "${{ matrix.features }}"

      - name: Run full MySQL adapter tests
        # `query` runs the same relational behavior suite against both MySQL
        # adapters. Every row also executes optional codec projections against
        # a real MySQL server instead of merely compiling them in lint.
        # The dialect builder UI suite is feature-gated and runs above without
        # `query`, where its diagnostics are stable; every other test remains
        # in this full run.
        run: cargo test -p drizzle --no-default-features --features "${{ matrix.test-features }}"

      - name: Run MySQL example
        if: matrix.name == 'sync'
        run: cargo run --example mysql --no-default-features --features mysql-sync

      - name: Run shared CLI parity contract
        # CLI feature names match the adapter features, but the CLI does not
        # expose the root crate's query/codec feature set.
        run: >-
          cargo test -p drizzle-cli --no-default-features
          --features "${{ matrix.features }}"
          --test parity_integration

  test-all-features:
    name: Test All-Feature Cross-Driver Contracts
    runs-on: ubuntu-latest
    needs: lint
    services:
      postgres:
        image: postgres:18-alpine
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: drizzle_test
        ports:
          - 5432:5432
        options: >-
          --health-cmd="pg_isready -U postgres -d drizzle_test"
          --health-interval=2s
          --health-timeout=5s
          --health-retries=30
      mysql:
        image: mysql:8.4
        env:
          MYSQL_ROOT_PASSWORD: mysql
          MYSQL_DATABASE: drizzle_test
          MYSQL_USER: drizzle
          MYSQL_PASSWORD: drizzle
        ports:
          - 3306:3306
        options: >-
          --health-cmd="mysqladmin ping -h 127.0.0.1 -udrizzle -pdrizzle --silent && mysql -h 127.0.0.1 -udrizzle -pdrizzle drizzle_test -e 'SELECT 1'"
          --health-interval=2s
          --health-timeout=5s
          --health-retries=30
    env:
      DRIZZLE_MYSQL_URL: mysql://drizzle:drizzle@127.0.0.1:3306/drizzle_test
    steps:
      - uses: actions/checkout@v6

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: stable
          save-if: ${{ github.ref == 'refs/heads/main' }}

      - name: Compile every workspace target with every feature
        # Turso remains experimental and has its own non-blocking runtime job.
        # This still proves that its feature unifies with every stable driver.
        run: cargo test --workspace --all-features --no-run

      - name: Run all-feature library and driver-neutral contracts
        run: |
          cargo test --workspace --all-features --lib -- --test-threads=1
          cargo test -p drizzle-core -p drizzle-mysql -p drizzle-migrations --all-features --tests

      - name: Run stable cross-driver integration contracts
        # One root suite executes the shared contracts with SQLite, PostgreSQL,
        # and MySQL adapters simultaneously. A single thread satisfies libSQL's
        # connection-safety requirement and avoids shared server-schema races.
        run: >-
          cargo test -p drizzle --test lib
          --features
          "rusqlite,libsql,postgres-sync,tokio-postgres,mysql-sync,mysql-async,query,serde,uuid,chrono,time,jiff,rust-decimal,arrayvec,compact-str,bytes,smallvec-types,cidr,geo-types,bit-vec"
          -- --test-threads=1

  test-turso:
    name: Test (Turso - Experimental)
    runs-on: ubuntu-latest
    needs: lint
    continue-on-error: true
    steps:
      - uses: actions/checkout@v6

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: stable
          save-if: ${{ github.ref == 'refs/heads/main' }}

      - name: Run tests
        id: test
        run: |
          mkdir -p test-output
          cargo test --workspace --features "turso,query,uuid,serde" 2>&1 | tee test-output/output.txt || true

          if grep -q "FAILED" test-output/output.txt; then
            echo "has_failures=true" >> $GITHUB_OUTPUT
            echo "::warning::Turso tests failed (expected - turso is experimental)"
          else
            echo "has_failures=false" >> $GITHUB_OUTPUT
            echo "::notice::Turso tests passed"
          fi

      - name: Extract failure reports
        id: extract
        if: steps.test.outputs.has_failures == 'true'
        run: |
          python3 -c "
          import sys

          text = open('test-output/output.txt').read()
          reports = []
          in_report = False
          buffer = []
          prev_line = ''
          box_chars = set('╔═╗║╚╝├─┤│')

          for line in text.splitlines(True):
              if 'TEST FAILURE REPORT' in line:
                  in_report = True
                  buffer = []
                  if any(c in box_chars for c in prev_line):
                      buffer.append(prev_line)
                  buffer.append(line)
              elif in_report:
                  if line.strip() == '' or any(c in box_chars for c in line):
                      buffer.append(line)
                  else:
                      reports.append(''.join(buffer))
                      buffer = []
                      in_report = False
              prev_line = line

          if buffer:
              reports.append(''.join(buffer))

          if reports:
              with open('test-output/failure-reports.txt', 'w') as f:
                  for i, report in enumerate(reports):
                      if i > 0:
                          f.write('\n' + '=' * 80 + '\n\n')
                      f.write(report)
              print(f'Extracted {len(reports)} failure report(s)')
          else:
              print('No structured failure reports found in output')
          "

          # Set output based on whether the file was created
          if [ -f test-output/failure-reports.txt ]; then
            echo "has_reports=true" >> $GITHUB_OUTPUT
          fi

      - name: Upload failure reports
        if: steps.extract.outputs.has_reports == 'true'
        uses: actions/upload-artifact@v7
        with:
          name: turso-failure-reports
          path: test-output/failure-reports.txt
          retention-days: 7

  docs:
    name: Documentation
    runs-on: ubuntu-latest
    needs: lint
    steps:
      - uses: actions/checkout@v6

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: stable
          save-if: ${{ github.ref == 'refs/heads/main' }}

      - name: Check documentation
        run: |
          RUSTDOCFLAGS="-D warnings" cargo doc --workspace --all-features --no-deps --exclude drizzle-cli
          RUSTDOCFLAGS="-D warnings" cargo doc -p drizzle-cli --all-features --no-deps
          cargo test --workspace --all-features --doc

  build-matrix:
    name: Build (${{ matrix.rust }})
    runs-on: ubuntu-latest
    needs: lint
    strategy:
      matrix:
        rust: [stable, nightly]

    steps:
      - uses: actions/checkout@v6

      - name: Install Rust ${{ matrix.rust }}
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust }}

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: ${{ matrix.rust }}
          save-if: ${{ github.ref == 'refs/heads/main' }}

      - name: Build
        run: cargo build --workspace --all-features

  msrv:
    name: MSRV Check
    runs-on: ubuntu-latest
    needs: lint
    steps:
      - uses: actions/checkout@v6

      - name: Get Rust version
        id: rust-version
        run: |
          RUST_VERSION=$(grep '^rust-version = ' Cargo.toml | sed 's/rust-version = "\(.*\)"/\1/')
          echo "version=$RUST_VERSION" >> $GITHUB_OUTPUT

      - name: Install Rust (MSRV)
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ steps.rust-version.outputs.version }}

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: msrv
          save-if: ${{ github.ref == 'refs/heads/main' }}

      - name: Check MSRV
        run: |
          cargo check -p drizzle --no-default-features --features mysql-sync
          cargo check -p drizzle --no-default-features --features mysql-async
          cargo check -p drizzle --no-default-features --features mysql-sync,mysql-async
          cargo check --workspace --all-targets --all-features

      - name: Check CLI driver builds for warnings
        # Clippy lints the CLI only with --all-features, which hides code that
        # goes dead without a driver or with only one. Users install those
        # builds, so check no driver, then each driver feature on its own.
        # `build.warnings` denies warnings without RUSTFLAGS, so artifact
        # fingerprints and the cache key stay the same. Cargo before 1.97
        # ignores it silently.
        run: |
          failed=()
          for features in "" rusqlite libsql turso postgres-sync tokio-postgres mysql-sync mysql-async d1-http; do
            echo "::group::drizzle-cli features: ${features:-none}"
            cargo check -p drizzle-cli --all-targets --no-default-features --features "$features" \
              --config 'build.warnings="deny"' || failed+=("${features:-none}")
            echo "::endgroup::"
          done
          if (( ${#failed[@]} )); then
            echo "::error::drizzle-cli check failed with features: ${failed[*]}"
            exit 1
          fi

  wasm-drivers:
    name: WASM Driver Checks
    runs-on: ubuntu-latest
    needs: lint
    steps:
      - uses: actions/checkout@v6

      - name: Get Rust version
        id: rust-version
        run: |
          RUST_VERSION=$(grep '^rust-version = ' Cargo.toml | sed 's/rust-version = "\(.*\)"/\1/')
          echo "version=$RUST_VERSION" >> $GITHUB_OUTPUT

      - name: Install Rust (MSRV) with WASM target
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ steps.rust-version.outputs.version }}
          targets: wasm32-unknown-unknown

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: wasm-msrv
          save-if: ${{ github.ref == 'refs/heads/main' }}

      - name: Check D1 driver
        run: cargo check -p drizzle --target wasm32-unknown-unknown --no-default-features --features d1

      - name: Check D1 driver (query)
        run: cargo check -p drizzle --target wasm32-unknown-unknown --no-default-features --features d1,query

      - name: Check Durable driver
        run: cargo check -p drizzle --target wasm32-unknown-unknown --no-default-features --features durable

      - name: Check Durable driver (query)
        run: cargo check -p drizzle --target wasm32-unknown-unknown --no-default-features --features durable,query

      - name: Check Durable Object example
        run: cargo check --manifest-path examples/durable_object/Cargo.toml --target wasm32-unknown-unknown

      - name: Check Hyperdrive driver
        run: cargo check -p drizzle --target wasm32-unknown-unknown --no-default-features --features hyperdrive

      - name: Check Hyperdrive driver (query)
        run: cargo check -p drizzle --target wasm32-unknown-unknown --no-default-features --features hyperdrive,query