Skip to content

Brand SQL fragments and segments with runtime symbols - #10190

Merged
tim-smart merged 8 commits into
mainfrom
sql-symbol-brands
Oct 30, 2026
Merged

tim-smart merged 8 commits into
mainfrom
sql-symbol-brands

Conversation

@effect-bot

@effect-bot effect-bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

sql template interpolation, Statement.isFragment and Statement.isCustom decided whether a value was a fragment or segment from string keys and _tag fields alone. Any plain object with a matching shape was therefore inlined as SQL rather than bound as a parameter.

Fragments and segments are now branded with exported Symbol.for TypeIds, in the same style as Effect 3. The guards only trust those brands, so plain objects that share a fragment or segment shape are bound as parameters.

Changes

  • Statement.ts exports FragmentTypeId and SegmentTypeId, both unique symbol values created with Symbol.for.
  • Fragment is keyed by FragmentTypeId, replacing the previous string key. Every segment interface (Literal, Identifier, Parameter, ArrayHelper, the record helpers and Custom) now requires SegmentTypeId.
  • The constructors set the brands: fragment, statements, literal, identifier, parameter, arrayHelper, the record helpers and custom.
  • isFragment, isSegment and isCustom check only these brands. ClickHouse's placeholder-type inference uses Statement.isCustom, so it gets the same behaviour with no package change.
  • Explicit composition APIs such as Statement.fragment, csv and join still accept the segments they are given at runtime.

Release

This targets main as an effect patch. Fragments and segments must come from the Statement constructors: object literals shaped like them no longer type check, and the sql template binds them as parameters. Values typed by a different copy of effect carry a different unique symbol type, although the runtime brands are shared through Symbol.for.

Tests

  • effect Statement.test.ts: plain objects shaped like fragments or segments are bound as parameters.
  • @effect/sql-clickhouse Client.test.ts: plain objects shaped like ClickhouseClient.param values are bound as String parameters.
  • typetest/sql/Statement.tst.ts: constructor results are accepted, and structural fragment and segment look-alikes are rejected.

Closes EFF-3166

@changeset-bot

changeset-bot Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4cc8bcd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 33 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-cloudflare Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/ai-typesafe Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/docgen Patch
@effect/doctest Patch
@effect/graphql-generator Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-janitor effect-janitor Bot added the 4.0 label Oct 30, 2026
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 39.40 KB 39.35 KB +0.06 KB (+0.14%)
basic.ts 7.23 KB 7.18 KB +0.05 KB (+0.74%)
batching.ts 11.08 KB 11.06 KB +0.02 KB (+0.16%)
brand.ts 6.87 KB 6.84 KB +0.04 KB (+0.53%)
cache.ts 11.54 KB 11.49 KB +0.05 KB (+0.40%)
config.ts 22.84 KB 22.77 KB +0.07 KB (+0.32%)
differ.ts 22.00 KB 21.92 KB +0.09 KB (+0.39%)
http-client.ts 26.95 KB 26.86 KB +0.09 KB (+0.33%)
http-router.ts 36.91 KB 36.85 KB +0.06 KB (+0.16%)
logger.ts 12.01 KB 11.96 KB +0.05 KB (+0.43%)
metric.ts 9.47 KB 9.42 KB +0.05 KB (+0.52%)
optic.ts 7.10 KB 7.05 KB +0.05 KB (+0.67%)
pubsub.ts 16.03 KB 15.97 KB +0.06 KB (+0.35%)
queue.ts 12.82 KB 12.77 KB +0.05 KB (+0.42%)
schedule.ts 11.80 KB 11.74 KB +0.06 KB (+0.49%)
schema-bigdecimal.ts 14.11 KB 14.02 KB +0.09 KB (+0.61%)
schema-binary.ts 41.26 KB 41.06 KB +0.20 KB (+0.49%)
schema-class.ts 21.73 KB 21.65 KB +0.08 KB (+0.38%)
schema-fromJsonSchemaDocument.ts 29.58 KB 29.51 KB +0.07 KB (+0.25%)
schema-representation-roundtrip.ts 27.99 KB 27.91 KB +0.08 KB (+0.29%)
schema-string-transformation.ts 15.35 KB 15.27 KB +0.08 KB (+0.52%)
schema-string.ts 12.34 KB 12.26 KB +0.09 KB (+0.73%)
schema-template-literal.ts 16.27 KB 16.19 KB +0.09 KB (+0.53%)
schema-toArbitrary.ts 38.94 KB 38.87 KB +0.08 KB (+0.20%)
schema-toCodeDocument.ts 26.15 KB 26.10 KB +0.05 KB (+0.19%)
schema-toCodecJson.ts 20.90 KB 20.83 KB +0.08 KB (+0.37%)
schema-toEquivalence.ts 21.05 KB 20.97 KB +0.07 KB (+0.35%)
schema-toFormatter.ts 21.14 KB 21.07 KB +0.08 KB (+0.36%)
schema-toJsonSchemaDocument.ts 26.17 KB 26.11 KB +0.06 KB (+0.22%)
schema-toRepresentation.ts 21.23 KB 21.16 KB +0.07 KB (+0.35%)
schema.ts 20.82 KB 20.75 KB +0.06 KB (+0.30%)
stm.ts 14.20 KB 14.15 KB +0.05 KB (+0.35%)
stream.ts 10.38 KB 10.33 KB +0.05 KB (+0.52%)

@effect-bot
effect-bot changed the base branch from main to v4/next-minor October 30, 2026 05:47
@effect-janitor effect-janitor Bot removed the 4.0 label Oct 30, 2026
Comment thread .changeset/sql-symbol-brands.md Outdated
@@ -0,0 +1,7 @@
---
"effect": minor

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a patch change targeting main

Comment thread packages/effect/src/sql/Statement.ts Outdated
* Runtime type identifier for SQL `Fragment` values.
*
* @stability unstable
* @category type IDs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @category type IDs
* @category Type ID

@effect-bot
effect-bot changed the base branch from v4/next-minor to main October 30, 2026 06:55
@effect-janitor effect-janitor Bot added the 4.0 label Oct 30, 2026
@tim-smart
tim-smart enabled auto-merge (squash) October 30, 2026 07:01
@tim-smart
tim-smart merged commit 136ddf9 into main Oct 30, 2026
18 of 31 checks passed
@tim-smart
tim-smart deleted the sql-symbol-brands branch October 30, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants