forked from electric-sql/electric
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(electric): Add support for the JSONB column type (electric-sql#661)
Co-authored-by: Kevin <kevin@electric-sql.com>
- Loading branch information
Showing
35 changed files
with
2,340 additions
and
179 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"electric-sql": patch | ||
"@electric-sql/prisma-generator": patch | ||
--- | ||
|
||
[VAX-825] Add client-side support for JSON type. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@core/electric": patch | ||
--- | ||
|
||
[VAX-825] Add support for the JSONB column type in electrified tables. |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './io' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { readFile, writeFile } from 'fs/promises' | ||
|
||
/* | ||
* Replaces the first occurence of `find` by `replace` in the file `file`. | ||
* If `find` is a regular expression that sets the `g` flag, then it replaces all occurences. | ||
*/ | ||
export async function findAndReplaceInFile( | ||
find: string | RegExp, | ||
replace: string, | ||
file: string | ||
) { | ||
const content = await readFile(file, 'utf8') | ||
const replacedContent = content.replace(find, replace) | ||
await writeFile(file, replacedContent) | ||
} |
27 changes: 27 additions & 0 deletions
27
clients/typescript/src/client/conversions/datatypes/json.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// not the most precise JSON type | ||
// but good enough for serialising/deserialising | ||
type JSON = string | number | boolean | Array<any> | Record<string, any> | ||
|
||
export function serialiseJSON(v: JSON): string { | ||
if (isJsonNull(v)) { | ||
// user provided the special `JsonNull` value | ||
// to indicate a JSON null value rather than a DB NULL | ||
return JSON.stringify(null) | ||
} | ||
return JSON.stringify(v) | ||
} | ||
|
||
export function deserialiseJSON(v: string): JSON { | ||
if (v === JSON.stringify(null)) return { __is_electric_json_null__: true } | ||
return JSON.parse(v) | ||
} | ||
|
||
function isJsonNull(v: JSON): boolean { | ||
return ( | ||
typeof v === 'object' && | ||
!Array.isArray(v) && | ||
v !== null && | ||
Object.hasOwn(v, '__is_electric_json_null__') && | ||
v['__is_electric_json_null__'] | ||
) | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.