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
5 changes: 0 additions & 5 deletions .changeset/cli-version.md

This file was deleted.

9 changes: 0 additions & 9 deletions .changeset/clickhouse-http-late-failures.md

This file was deleted.

9 changes: 0 additions & 9 deletions .changeset/clickhouse-quoted-names.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/mariadb-union-integer-literal.md

This file was deleted.

7 changes: 0 additions & 7 deletions .changeset/mysql-on-duplicate-key-update.md

This file was deleted.

7 changes: 0 additions & 7 deletions .changeset/mysql-write-results.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/stable-1-0.md

This file was deleted.

30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
# @maple-dev/effect-orm

## 1.0.0

### Major Changes

- 6708ad8: 1.0.0. The package follows semantic versioning from here: a breaking change to a documented export is a major release. Every export of every entry is named in the API reference (`docs/reference.md`), and `bun run test` now fails when one is not; before, only the four dialect entries were checked. The Alpha notice is gone from the README and the docs site. `package.json` declares `engines.node >= 20.19.0`, the oldest Node the build was run on.

### Minor Changes

- 2d2fe62: ClickHouse names are quoted when they need to be. The ClickHouse dialect wrote every identifier bare, so a select key such as `"p-95"` or `"by service"` was a syntax error, a key named `null` ordered by the literal, and a key built from input was SQL: `{ "x FROM system.users --": $.Name }` compiled to `events.Name AS x FROM system.users --`. A plain name (letters, digits, `_`, dots for a Nested column) is still bare, so existing SQL does not change; any other is written in backticks with `` ` `` and `\` escaped. That covers select keys, GROUP BY and ORDER BY keys, column names of an external table, source and join aliases, and CTE names. As a select key, an alias or a CTE name, the words ClickHouse reads as something else there are quoted too (`all`, `cube`, `distinct`, `false`, `inf`, `infinity`, `nan`, `not`, `null`, `recursive`, `rollup`, `select`, `top`, `true`); a column of such a name is still read bare, so a table's DDL does not change, and `generate` does not recreate a materialized view whose SELECT differs from its snapshot only by those backticks. A select key with a dot is quoted too, so selecting a Nested column by name (`.select("Events.Name")`) works: it used to write `AS Events.Name`, a syntax error. A ClickHouse table name is still written as given, since an external table's name may be a table function or a subquery; `Dialect.rawTableNames` says so.

A name that spells the reserved param marker `__PARAM_` is escaped on ClickHouse and refused with `InvalidLiteral` on the other dialects. On Postgres it used to be rewritten into the placeholder's text (`AS "$1"`).

`contains("")` is written with one wildcard (`LIKE '%'`) instead of two. It means the same, and ClickHouse 26.2 turns a `LEFT JOIN` filtered by `LIKE '%%'` on the joined table into an inner join, losing the unmatched rows.
- 2fcf943: MySQL and MariaDB upserts: `insertInto(table).values(rows).onDuplicateKeyUpdate({ set })` writes `INSERT ... ON DUPLICATE KEY UPDATE`. `set` takes the forms `onConflictDoUpdate`'s does: a record of values, params or expressions, a callback `($, excluded) => ({ ... })` of the existing and proposed rows, `excluded(columns)` or `excludedAll(except?)`. MySQL reads the proposed row through a row alias, `VALUES (...) AS excluded` (MySQL 8.0.19+); MariaDB reads `VALUES(col)`. (For MySQL before 8.0.19, spread `mysqlDialect` with `clauses.onDuplicateKey: "valuesFunction"`.) It fires on any unique key and takes no target or `where`, so `excludedAll` leaves out the table's declared primary key and its `tenantColumn`, and a bare `excludedAll()` on a table with no declared key is a `QueryBuilderDefect` asking for `except`. On a table with a `tenantColumn` the insert is `"cross-tenant"`. A proposed-row column the SET reads but no row writes joins the insert with `DEFAULT` cells, as Postgres's `excluded` holds the default. `values` rows only; with `select`, on a table named `excluded` on MySQL, or on another dialect, compiling is a `QueryBuilderDefect`. `onConflictDoUpdate` / `onConflictDoNothing` on MySQL now name `onDuplicateKeyUpdate` / `onDuplicateKeyDoNothing` in their errors, and the reverse on Postgres and SQLite. New: `Dialect.clauses.onDuplicateKey`, and the `OnDuplicateKeyUpdate` type.

`onDuplicateKeyDoNothing()` skips a row that conflicts on any unique key, on MySQL and MariaDB. It writes `ON DUPLICATE KEY UPDATE col = table.col` on the first written column, not `INSERT IGNORE`: `IGNORE` also turns truncation, NOT NULL and foreign key errors into warnings and stores or drops the row, while these still fail. A skipped row counts as 1 affected row with mysql2's default `CLIENT_FOUND_ROWS`, 0 without it. It keeps the inserted rows' tenant scope, since the statement writes no existing row; it is still an UPDATE of the matched row, so a `BEFORE UPDATE` trigger runs, and then `affectedRows` is 2 and `insertId` the matched row's id.
- f69f39c: `Db.runWrite` runs an insert, update or delete and returns a `WriteResult`: `affectedRows`, and for an insert `insertId`, the key of the row it wrote. It is how MySQL, which has no `RETURNING` (and MariaDB, whose `RETURNING` the builder does not write), reads an `AUTO_INCREMENT` key; it reads `@effect/sql-mysql2`, `@effect/sql-pg`, PGlite, node:sqlite and D1 results, and refuses a ClickHouse write before sending it. `layerTest` takes a `TestWriteReply` (`{ affectedRows, insertId? }`) to answer one.

MySQL and MariaDB constraint failures are now refined like the other dialects': `refineConstraints` reads the server's error number, so a foreign key (1451, 1452), NOT NULL (1048, 1364) or CHECK (3819, MariaDB 4025) failure becomes `ForeignKeyViolation`, `NotNullViolation` or `CheckViolation`, with the key, constraint, table or column the message names. Before, only a duplicate key was refined, and without names. A MySQL `DatabaseError` now also carries the server's `sqlState` and its error number as `errorCode`. Names are read from the server's whole message and anchored where the server writes them, so a duplicated value quoted in the message cannot name the key. A Node error name (`EPIPE`, `EBUSY`) is no longer read as a SQLSTATE.

### Patch Changes

- 6955a28: `effect-orm --version` and `ch-bench --version` print the package version. `effect-orm` names a command it does not have (`unknown command "frobnicate"`) before it looks for a config file; it used to report that `effect-orm.config.ts` could not be imported.
- e972080: `/clickhouse-http` no longer returns the rows of a query that failed. ClickHouse answers `200` with the first block of rows, so a timeout, a memory limit or any exception after that arrives inside the body. On servers before 25.11 (25.8 LTS among them) the client read the rows sent so far as the whole result: `sql.unsafe(...)` succeeded with 900,000 of 2,000,000 rows, and `.stream` ended normally. On 25.11 and later it failed, but as "the response is not valid JSON" or "the stream failed", with the server's code lost, so a timeout was not a `StatementTimeoutError`.

Queries now send `http_write_exception_in_output_format=1`, and the client reads the exception wherever the server puts it: an `exception` key beside `data`, a JSONEachRow exception line, the `__exception__` block (tagged or not), or the text after the rows of a compressed reply. The statement fails with the server's reason and message; a stream fails after the rows before the exception. A statement whose `200` carries `X-ClickHouse-Exception-Code` (a command with progress headers on) fails too; it used to succeed. A body that cannot be read to the end is a `ConnectionError`, not an `UnknownError`. Needs ClickHouse 23.9 or later. A `readonly = 1` user, who cannot change settings, sets both built-in settings in `settings` to the server's current values (`http_write_exception_in_output_format` is `1` before 25.11 and `0` from it).

Bound values: `null` binds as NULL (it was the text `null`), an array holding a null is `Array(Nullable(T))` (its nulls were the type's default), and a `bigint` binds as the narrowest of `Int64`, `UInt64`, `Int128`, `UInt256` and `Int256` that holds it (2^64 - 1 arrived as -1). An array's element type is read from all of its elements, nested arrays included.
- b35749b: MariaDB: an integer literal in a `unionAll` branch keeps its value beside a DECIMAL in another branch. MariaDB 11.4 sizes an integer literal one digit short when a union branch is a derived table, which is how `mariadbDialect` writes branches, and cut it down to fit: `lit(97)` in one branch and a `DECIMAL(5,4)` in the other came back `9.9999`. A selected integer literal is now written `CAST(n AS SIGNED) + 0` on MariaDB, which has the digits. MySQL is unaffected and unchanged.

## 0.11.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@maple-dev/effect-orm",
"version": "0.11.0",
"version": "1.0.0",
"description": "Type-safe ClickHouse, Postgres, SQLite and MySQL queries, result decoding, and reproducible benchmarks for Effect and TypeScript",
"keywords": [
"clickhouse",
Expand Down