fix(pglite-sync): serialize COPY initial sync with Postgres TEXT format#1035
Draft
AntonOfTheWoods wants to merge 1 commit into
Draft
fix(pglite-sync): serialize COPY initial sync with Postgres TEXT format#1035AntonOfTheWoods wants to merge 1 commit into
AntonOfTheWoods wants to merge 1 commit into
Conversation
The COPY-based initial insert path (`initialInsertMethod: 'csv'` / the
deprecated `useCopy`) hand-rolled a CSV encoder that broke on many column
types: arrays were emitted via `Array.toString` as `1,2,3` instead of the
`{1,2,3}` literal, `json`/`jsonb` objects became `[object Object]`, and
embedded delimiters, newlines and backslashes were mishandled.
Replace it with a faithful port of PostgreSQL's own COPY TEXT
serialization — `CopyAttributeOutText` (copyto.c) for field escaping and
`array_out` (arrayfuncs.c) for array literals — driven by the JS types the
Electric client produces. Column types are looked up from
`information_schema` to disambiguate `json`/`jsonb` (whose parsed values are
indistinguishable from SQL arrays by runtime type alone).
Adds unit tests plus round-trip tests that push the generated stream through
a real PGlite `COPY ... FROM` for scalars, strings with special characters,
arrays (incl. multi-dimensional), json/jsonb (incl. `jsonb[]`), bytea and
timestamps.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VkNJeV2Ju2TnjxSxSzgL9i
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The COPY-based initial insert path (
initialInsertMethod: 'csv'/ the deprecateduseCopy) hand-rolled a CSV encoder that broke on many column types: arrays were emitted viaArray.toStringas1,2,3instead of the{1,2,3}literal,json/jsonbobjects became[object Object], and embedded delimiters, newlines and backslashes were mishandled.Replace it with a faithful port of PostgreSQL's own COPY TEXT serialization —
CopyAttributeOutText(copyto.c) for field escaping andarray_out(arrayfuncs.c) for array literals — driven by the JS types the Electric client produces. Column types are looked up frominformation_schemato disambiguatejson/jsonb(whose parsed values are indistinguishable from SQL arrays by runtime type alone).Adds unit tests plus round-trip tests that push the generated stream through a real PGlite
COPY ... FROMfor scalars, strings with special characters, arrays (incl. multi-dimensional), json/jsonb (incl.jsonb[]), bytea and timestamps.Claude-Session: https://claude.ai/code/session_01VkNJeV2Ju2TnjxSxSzgL9i