-
-
Notifications
You must be signed in to change notification settings - Fork 499
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): ensure custom types are processed in `em.upsert/upsertMany…
…/insertMany` Closes #4070
- Loading branch information
Showing
4 changed files
with
118 additions
and
5 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { Entity, PrimaryKey, Property } from '@mikro-orm/core'; | ||
import { MikroORM } from '@mikro-orm/sqlite'; | ||
|
||
@Entity() | ||
class MyEntity { | ||
|
||
@PrimaryKey() | ||
id?: number; | ||
|
||
@Property({ type: 'json' }) | ||
postIds!: number[]; | ||
|
||
} | ||
|
||
let orm: MikroORM; | ||
|
||
beforeAll(async () => { | ||
orm = await MikroORM.init({ | ||
entities: [MyEntity], | ||
dbName: `:memory:`, | ||
}); | ||
await orm.schema.refreshDatabase(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await orm.close(true); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await orm.schema.clearDatabase(); | ||
}); | ||
|
||
test('insertMany array of numbers to JSON', async () => { | ||
await orm.em.insertMany(MyEntity, [ | ||
{ | ||
id: 1, | ||
postIds: [10, 11, 12], | ||
}, | ||
{ | ||
id: 2, | ||
postIds: [20, 21], | ||
}, | ||
]); | ||
}); | ||
|
||
test('insertMany entities array of numbers to JSON', async () => { | ||
await orm.em.insertMany([ | ||
orm.em.create(MyEntity, { | ||
id: 1, | ||
postIds: [10, 11, 12], | ||
}), | ||
orm.em.create(MyEntity, { | ||
id: 2, | ||
postIds: [20, 21], | ||
}), | ||
]); | ||
}); | ||
|
||
test('upsertMany array of numbers to JSON', async () => { | ||
await orm.em.upsertMany(MyEntity, [ | ||
{ | ||
id: 1, | ||
postIds: [10, 11, 12], | ||
}, | ||
{ | ||
id: 2, | ||
postIds: [20, 21], | ||
}, | ||
]); | ||
}); | ||
|
||
test('upsert array of numbers to JSON', async () => { | ||
await orm.em.upsert(MyEntity, { | ||
id: 1, | ||
postIds: [10, 11, 12], | ||
}); | ||
}); | ||
|
||
test('insert array of numbers to JSON', async () => { | ||
await orm.em.insert(MyEntity, { | ||
id: 1, | ||
postIds: [10, 11, 12], | ||
}); | ||
}); | ||
|
||
test('flush one array of numbers to JSON', async () => { | ||
orm.em.create(MyEntity, { | ||
id: 1, | ||
postIds: [10, 11, 12], | ||
}); | ||
await orm.em.flush(); | ||
}); | ||
|
||
test('flush many array of numbers to JSON', async () => { | ||
orm.em.create(MyEntity, { | ||
id: 1, | ||
postIds: [10, 11, 12], | ||
}); | ||
orm.em.create(MyEntity, { | ||
id: 2, | ||
postIds: [20, 21], | ||
}); | ||
await orm.em.flush(); | ||
}); |