This repository has been archived by the owner on Mar 18, 2022. It is now read-only.
forked from typeorm/typeorm
-
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: add
set
datatype support for MySQL/MariaDB (typeorm#4538)
Set possible values defined using existing enum column option. Sets are implemented as arrays. Closes: typeorm#2779
- Loading branch information
Showing
8 changed files
with
129 additions
and
2 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
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,15 @@ | ||
import { Column, Entity, PrimaryGeneratedColumn } from "../../../../src"; | ||
import { Role } from "../set"; | ||
|
||
@Entity("post") | ||
export class Post { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column("set", { | ||
default: [Role.Admin, Role.Developer], | ||
enum: Role | ||
}) | ||
roles: Role[]; | ||
} |
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,44 @@ | ||
import "reflect-metadata"; | ||
import { Connection } from "../../../src/connection/Connection"; | ||
import { closeTestingConnections, createTestingConnections } from "../../utils/test-utils"; | ||
import { Post } from "./entity/Post"; | ||
import { expect } from "chai"; | ||
import { Role } from "./set"; | ||
|
||
describe("github issues > #2779 Could we add support for the MySQL/MariaDB SET data type?", () => { | ||
|
||
let connections: Connection[]; | ||
before(async () => { | ||
connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
enabledDrivers: ["mariadb", "mysql"], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
}); | ||
}); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should create column with SET datatype", () => Promise.all(connections.map(async connection => { | ||
|
||
const queryRunner = connection.createQueryRunner(); | ||
const table = await queryRunner.getTable("post"); | ||
table!.findColumnByName("roles")!.type.should.be.equal("set"); | ||
await queryRunner.release(); | ||
|
||
}))); | ||
|
||
it("should persist and hydrate sets", () => Promise.all(connections.map(async connection => { | ||
|
||
const targetValue = [Role.Support, Role.Developer]; | ||
|
||
const post = new Post(); | ||
post.roles = targetValue; | ||
await connection.manager.save(post); | ||
post.roles.should.be.deep.equal(targetValue); | ||
|
||
const loadedPost = await connection.manager.findOne(Post); | ||
expect(loadedPost).not.to.be.undefined; | ||
loadedPost!.roles.should.be.deep.equal(targetValue); | ||
}))); | ||
|
||
}); |
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 @@ | ||
export enum Role { | ||
Admin = "Admin", | ||
Support = "Support", | ||
Developer = "Developer" | ||
} |