Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gajus/slonik
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v35.2.1
Choose a base ref
...
head repository: gajus/slonik
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v36.0.0
Choose a head ref
  • 1 commit
  • 5 files changed
  • 1 contributor

Commits on Sep 28, 2023

  1. feat: add bigint support (fixes #454 #338 #184) (#510)

    BREAKING CHANGE: int8 now returns bigint
    gajus authored Sep 28, 2023
    Copy the full SHA
    6904705 View commit details
4 changes: 2 additions & 2 deletions src/factories/typeParsers/createBigintTypeParser.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { type TypeParser } from '../../types';

// eslint-disable-next-line unicorn/prefer-native-coercion-functions
const bigintParser = (value: string) => {
// @todo Use bigint when value is greater than Number.MAX_SAFE_INTEGER.
return Number.parseInt(value, 10);
return BigInt(value);
};

export const createBigintTypeParser = (): TypeParser => {
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -353,6 +353,7 @@ export type UnnestSqlToken = {

export type PrimitiveValueExpression =
| Buffer
| bigint
| boolean
| number
| string
3 changes: 2 additions & 1 deletion src/utilities/isPrimitiveValueExpression.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
export const isPrimitiveValueExpression = (
maybe: unknown,
): maybe is boolean | number | string | null => {
): maybe is bigint | boolean | number | string | null => {
return (
typeof maybe === 'string' ||
typeof maybe === 'number' ||
typeof maybe === 'boolean' ||
typeof maybe === 'bigint' ||
maybe === null
);
};
13 changes: 13 additions & 0 deletions test/helpers/createIntegrationTests.ts
Original file line number Diff line number Diff line change
@@ -141,6 +141,19 @@ export const createIntegrationTests = (
test: TestFn<TestContextType>,
PgPool: new () => PgPoolType,
) => {
test('inserts and retrieves bigint', async (t) => {
const pool = await createPool(t.context.dsn, {
PgPool,
});
const result = await pool.oneFirst(sql.unsafe`
SELECT ${BigInt(9_007_199_254_740_999n)}::bigint
`);

t.is(result, BigInt(9_007_199_254_740_999n));

await pool.end();
});

test('NotNullIntegrityConstraintViolationError identifies the table and column', async (t) => {
const pool = await createPool(t.context.dsn, {
PgPool,
15 changes: 15 additions & 0 deletions test/slonik/templateTags/sql/array.ts
Original file line number Diff line number Diff line change
@@ -14,6 +14,21 @@ test('binds an empty array', (t) => {
});
});

test('binds bigint', (t) => {
const query = sql.fragment`SELECT ${sql.array(
// eslint-disable-next-line unicorn/numeric-separators-style
[9007199254740999n],
'int8',
)}`;

t.deepEqual(query, {
sql: 'SELECT $1::"int8"[]',
type: FragmentToken,
// eslint-disable-next-line unicorn/numeric-separators-style
values: [[BigInt(9007199254740999n)]],
});
});

test('binds an array with multiple values', (t) => {
const query = sql.fragment`SELECT ${sql.array([1, 2, 3], 'int4')}`;