Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reverted json/jsonb changes introduced in 0.3.1 #8777

Merged
merged 1 commit into from
Mar 22, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/driver/postgres/PostgresDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ export class PostgresDriver implements Driver {
columnMetadata.type,
) >= 0
) {
return value // JSON.stringify()
return JSON.stringify(value)
} else if (columnMetadata.type === "hstore") {
if (typeof value === "string") {
return value
Expand Down
2 changes: 1 addition & 1 deletion test/benchmark/bulk-save-case2/entity/Document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class Document {
@Column("text")
context: string

@Column({ type: "jsonb", array: true })
@Column({ type: "jsonb" })
distributions: Distribution[]

@Column({ type: "timestamp with time zone" })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,18 @@ describe("find options > find operators > ArrayContainedBy", () => {
const post1 = new Post()
post1.title = "Post #1"
post1.authors = ["dmitry", "olimjon"]
post1.categories = [{ name: "typescript" }, { name: "programming" }]
post1.statuses = [PostStatus.draft, PostStatus.published]
await manager.save(post1)

const post2 = new Post()
post2.title = "Post #2"
post2.authors = ["olimjon"]
post2.categories = [{ name: "programming" }]
post2.statuses = [PostStatus.published]
await manager.save(post2)

const post3 = new Post()
post3.title = "Post #3"
post3.authors = []
post3.categories = []
post3.statuses = []
await manager.save(post3)
}
Expand All @@ -62,24 +59,18 @@ describe("find options > find operators > ArrayContainedBy", () => {
id: 1,
title: "Post #1",
authors: ["dmitry", "olimjon"],
categories: [
{ name: "typescript" },
{ name: "programming" },
],
statuses: [PostStatus.draft, PostStatus.published],
},
{
id: 2,
title: "Post #2",
authors: ["olimjon"],
categories: [{ name: "programming" }],
statuses: [PostStatus.published],
},
{
id: 3,
title: "Post #3",
authors: [],
categories: [],
statuses: [],
},
])
Expand All @@ -97,84 +88,12 @@ describe("find options > find operators > ArrayContainedBy", () => {
id: 2,
title: "Post #2",
authors: ["olimjon"],
categories: [{ name: "programming" }],
statuses: [PostStatus.published],
},
{
id: 3,
title: "Post #3",
authors: [],
categories: [],
statuses: [],
},
])
}),
))

it("should find entries in jsonb", () =>
Promise.all(
connections.map(async (connection) => {
await prepareData(connection.manager)

const loadedPost1 = await connection.manager.find(Post, {
where: {
categories: ArrayContainedBy([
{ name: "typescript" },
{ name: "programming" },
]),
},
order: {
id: "asc",
},
})
loadedPost1.should.be.eql([
{
id: 1,
title: "Post #1",
authors: ["dmitry", "olimjon"],
categories: [
{ name: "typescript" },
{ name: "programming" },
],
statuses: [PostStatus.draft, PostStatus.published],
},
{
id: 2,
title: "Post #2",
authors: ["olimjon"],
categories: [{ name: "programming" }],
statuses: [PostStatus.published],
},
{
id: 3,
title: "Post #3",
authors: [],
categories: [],
statuses: [],
},
])

const loadedPost2 = await connection.manager.find(Post, {
where: {
categories: ArrayContainedBy([{ name: "programming" }]),
},
order: {
id: "asc",
},
})
loadedPost2.should.be.eql([
{
id: 2,
title: "Post #2",
authors: ["olimjon"],
categories: [{ name: "programming" }],
statuses: [PostStatus.published],
},
{
id: 3,
title: "Post #3",
authors: [],
categories: [],
statuses: [],
},
])
Expand Down Expand Up @@ -202,24 +121,18 @@ describe("find options > find operators > ArrayContainedBy", () => {
id: 1,
title: "Post #1",
authors: ["dmitry", "olimjon"],
categories: [
{ name: "typescript" },
{ name: "programming" },
],
statuses: [PostStatus.draft, PostStatus.published],
},
{
id: 2,
title: "Post #2",
authors: ["olimjon"],
categories: [{ name: "programming" }],
statuses: [PostStatus.published],
},
{
id: 3,
title: "Post #3",
authors: [],
categories: [],
statuses: [],
},
])
Expand All @@ -237,14 +150,12 @@ describe("find options > find operators > ArrayContainedBy", () => {
id: 2,
title: "Post #2",
authors: ["olimjon"],
categories: [{ name: "programming" }],
statuses: [PostStatus.published],
},
{
id: 3,
title: "Post #3",
authors: [],
categories: [],
statuses: [],
},
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ export class Post {
})
authors: string[]

@Column({
type: "jsonb",
array: true,
})
categories: PostCategory[]

@Column({
type: "enum",
enum: PostStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,18 @@ describe("find options > find operators > ArrayContains", () => {
const post1 = new Post()
post1.title = "Post #1"
post1.authors = ["dmitry", "olimjon"]
post1.categories = [{ name: "typescript" }, { name: "programming" }]
post1.statuses = [PostStatus.draft, PostStatus.published]
await manager.save(post1)

const post2 = new Post()
post2.title = "Post #2"
post2.authors = ["olimjon"]
post2.categories = [{ name: "programming" }]
post2.statuses = [PostStatus.published]
await manager.save(post2)

const post3 = new Post()
post3.title = "Post #3"
post3.authors = []
post3.categories = []
post3.statuses = []
await manager.save(post3)
}
Expand All @@ -62,10 +59,6 @@ describe("find options > find operators > ArrayContains", () => {
id: 1,
title: "Post #1",
authors: ["dmitry", "olimjon"],
categories: [
{ name: "typescript" },
{ name: "programming" },
],
statuses: [PostStatus.draft, PostStatus.published],
},
])
Expand All @@ -83,73 +76,12 @@ describe("find options > find operators > ArrayContains", () => {
id: 1,
title: "Post #1",
authors: ["dmitry", "olimjon"],
categories: [
{ name: "typescript" },
{ name: "programming" },
],
statuses: [PostStatus.draft, PostStatus.published],
},
{
id: 2,
title: "Post #2",
authors: ["olimjon"],
categories: [{ name: "programming" }],
statuses: [PostStatus.published],
},
])
}),
))

it("should find entries in jsonb", () =>
Promise.all(
connections.map(async (connection) => {
await prepareData(connection.manager)

const loadedPost1 = await connection.manager.find(Post, {
where: {
categories: ArrayContains([{ name: "typescript" }]),
},
order: {
id: "asc",
},
})
loadedPost1.should.be.eql([
{
id: 1,
title: "Post #1",
authors: ["dmitry", "olimjon"],
categories: [
{ name: "typescript" },
{ name: "programming" },
],
statuses: [PostStatus.draft, PostStatus.published],
},
])

const loadedPost2 = await connection.manager.find(Post, {
where: {
categories: ArrayContains([{ name: "programming" }]),
},
order: {
id: "asc",
},
})
loadedPost2.should.be.eql([
{
id: 1,
title: "Post #1",
authors: ["dmitry", "olimjon"],
categories: [
{ name: "typescript" },
{ name: "programming" },
],
statuses: [PostStatus.draft, PostStatus.published],
},
{
id: 2,
title: "Post #2",
authors: ["olimjon"],
categories: [{ name: "programming" }],
statuses: [PostStatus.published],
},
])
Expand All @@ -174,10 +106,6 @@ describe("find options > find operators > ArrayContains", () => {
id: 1,
title: "Post #1",
authors: ["dmitry", "olimjon"],
categories: [
{ name: "typescript" },
{ name: "programming" },
],
statuses: [PostStatus.draft, PostStatus.published],
},
])
Expand All @@ -195,17 +123,12 @@ describe("find options > find operators > ArrayContains", () => {
id: 1,
title: "Post #1",
authors: ["dmitry", "olimjon"],
categories: [
{ name: "typescript" },
{ name: "programming" },
],
statuses: [PostStatus.draft, PostStatus.published],
},
{
id: 2,
title: "Post #2",
authors: ["olimjon"],
categories: [{ name: "programming" }],
statuses: [PostStatus.published],
},
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ export class Post {
})
authors: string[]

@Column({
type: "jsonb",
array: true,
})
categories: PostCategory[]

@Column({
type: "enum",
enum: PostStatus,
Expand Down