feat(sqlite): add support for jsonb column type in SQLite#11933
feat(sqlite): add support for jsonb column type in SQLite#11933gioboa merged 2 commits intotypeorm:masterfrom
Conversation
User descriptionDescription of ChangeThis pull request (PR) introduces support for the Closes #11930 Changes Made
Pull-Request Checklist
PR TypeEnhancement Description
Diagram Walkthroughflowchart LR
A["SQLite Driver"] -->|"Add jsonb type"| B["Supported Types"]
C["Column Metadata"] -->|"Persist/Hydrate"| D["preparePersistentValue<br/>prepareHydratedValue"]
E["Default Values"] -->|"Semantic Compare"| F["compareDefaults Method"]
F -->|"JSON/JSONB"| G["Deep Compare"]
F -->|"Other Types"| H["Normalize Compare"]
I["Tests"] -->|"Extend Coverage"| J["SQLite + Variants"]
|
| Relevant files | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| Enhancement |
| ||||||||
| Documentation |
| ||||||||
| Tests |
|
PR Code Suggestions ✨Latest suggestions up to 1a2d2b4
Previous suggestions✅ Suggestions up to commit 32b2688
✅ Suggestions up to commit 1f110b4
✅ Suggestions up to commit 039c900
✅ Suggestions up to commit 0d57335
✅ Suggestions up to commit bf6bec7
✅ Suggestions up to commit 336aa4d
✅ Suggestions up to commit 9e9459b
✅ Suggestions up to commit 9fbe961
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Code Review by Qodo
1. SQLite jsonb primitive defaults
|
9fbe961 to
9e9459b
Compare
commit: |
|
Persistent review updated to latest commit 9e9459b |
|
Persistent review updated to latest commit 336aa4d |
336aa4d to
bf6bec7
Compare
|
Persistent review updated to latest commit bf6bec7 |
bf6bec7 to
0d57335
Compare
|
Persistent review updated to latest commit 0d57335 |
73b741e to
6866b22
Compare
User descriptionDescription of ChangeThis pull request (PR) introduces support for the Example: @Entity()
export class Record {
@PrimaryGeneratedColumn()
id: number
@Column("jsonb")
data: any
@Column({
type: "jsonb",
default: { foo: "bar" }
})
defaultData: any
}-- Create
CREATE TABLE "record" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "data" jsonb, "defaultData" jsonb DEFAULT (jsonb('{"foo":"bar"}')))
-- Insert
INSERT INTO "record"("id", "data", "defaultData") VALUES (NULL, jsonb(?), jsonb('{"hello":"world","foo":"bar"}')) -- PARAMETERS: ["{\"key\":\"value\",\"nested\":{\"num\":42}}"]
-- Select
SELECT "Record"."id" AS "Record_id", json("Record"."data") AS "Record_data", json("Record"."defaultData") AS "Record_defaultData" FROM "record" "Record" WHERE (("Record"."id" = 1)) LIMIT 1
Closes #11930 Changes Made
Pull-Request Checklist
PR TypeEnhancement Description
Diagram Walkthroughflowchart LR
A["SQLite JSONB Support"] --> B["Driver Updates"]
A --> C["Query Builder Updates"]
A --> D["Tests & Docs"]
B --> B1["AbstractSqliteDriver: Add jsonb to supported types"]
B --> B2["Add defaultEqual method for semantic comparison"]
B --> B3["Handle jsonb in preparePersistentValue/prepareHydratedValue"]
C --> C1["InsertQueryBuilder: Wrap jsonb with jsonb function"]
C --> C2["UpdateQueryBuilder: Wrap jsonb with jsonb function"]
C --> C3["SelectQueryBuilder: Wrap jsonb with json function"]
D --> D1["Add sqlite-jsonb.test.ts with comprehensive tests"]
D --> D2["Update column-types-sqlite.test.ts"]
D --> D3["Update sqlite.md documentation"]
|
| Relevant files | |||
|---|---|---|---|
| Enhancement | |||
| Error handling | 1 files
| ||
| Documentation | |||
| Tests |
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||||
1f110b4 to
32b2688
Compare
1a2d2b4 to
bf746e8
Compare
Code Review by Qodo
1. defaultEqual swallows JSON errors
|
d328328 to
fce4d84
Compare
fce4d84 to
c3fcbbc
Compare
c3fcbbc to
7869adb
Compare
|
Persistent review updated to latest commit b66ca86 |
|



Description of Change
This pull request (PR) introduces support for the
jsonbdatatype in SQLite.Example:
Closes #11930
Changes Made
jsonbin both thepreparePersistentValueandprepareHydratedValuemethods to ensure proper persistence and retrieval of the value.jsonbin the supported data types for theAbstractSqliteDriver.jsonandjsonbin the Column Types sectionPull-Request Checklist
masterbranchFixes #11930tests/**.test.ts)docs/docs/**.md)