-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: add parseInt8 option to postgres driver * chore: formatting
- Loading branch information
Showing
5 changed files
with
106 additions
and
1 deletion.
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,13 @@ | ||
import { Column, Entity, PrimaryGeneratedColumn } from "../../../../src" | ||
|
||
@Entity() | ||
export class TestEntity { | ||
@PrimaryGeneratedColumn() | ||
id: number | ||
|
||
@Column({ type: "bigint", nullable: true }) | ||
big_int: number | ||
|
||
@Column({ type: "numeric", nullable: true }) | ||
big_decimal: number | ||
} |
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,53 @@ | ||
import "reflect-metadata" | ||
import { expect } from "chai" | ||
import { DataSource } from "../../../src/data-source/DataSource" | ||
import { | ||
closeTestingConnections, | ||
createTestingConnections, | ||
reloadTestingDatabases, | ||
} from "../../utils/test-utils" | ||
import { TestEntity } from "./entity/TestEntity" | ||
|
||
describe('github issues > #9341 "bigNumberStrings:false" is not working for postgres', () => { | ||
let connections: DataSource[] | ||
before( | ||
async () => | ||
(connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
enabledDrivers: ["postgres"], | ||
driverSpecific: { | ||
parseInt8: true, | ||
}, | ||
})), | ||
) | ||
beforeEach(() => reloadTestingDatabases(connections)) | ||
after(() => closeTestingConnections(connections)) | ||
|
||
it("should fetch big int as number not string when using parseInt8=true", async () => { | ||
for (const connection of connections) { | ||
const origin = await connection.getRepository(TestEntity).save({ | ||
big_int: Number.MAX_SAFE_INTEGER, | ||
big_decimal: 1.23456789, | ||
}) | ||
|
||
const result = await connection.getRepository(TestEntity).findOne({ | ||
where: { id: origin.id }, | ||
}) | ||
|
||
// count also returns bigint (as string by default) | ||
const [{ count }] = await connection.query( | ||
`select count(*) from (VALUES (1), (2), (3)) as tmp`, | ||
) | ||
|
||
// big int should be number | ||
expect(typeof result?.big_int).to.eq("number") | ||
expect(result?.big_int).to.eq(Number.MAX_SAFE_INTEGER) | ||
// big decimal should remain string, only int8 is parsed | ||
expect(typeof result?.big_decimal).to.eq("string") | ||
expect(result?.big_decimal).to.eq("1.23456789") | ||
// count should be number (it is int8) | ||
expect(typeof count).to.eq("number") | ||
expect(count).to.eq(3) | ||
} | ||
}) | ||
}) |