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

Nullable expressions: undefined -> null #2

Merged
merged 16 commits into from
Oct 14, 2023
Merged

Nullable expressions: undefined -> null #2

merged 16 commits into from
Oct 14, 2023

Conversation

carterzenk
Copy link
Contributor

@carterzenk carterzenk commented Oct 11, 2023

  • Changes expressions to use the null data type instead of undefined.
  • This change caused some issues with the type snapshot checks. Refactored the test snapshots to use jest-runner-tsd. These tests now can check on the actual result set data type, rather than having to use the GetDataType class to extract nullability.
  • Refactors the result set types to reduce duplication, and better explain that the GetDataType helper is now only used in FromItemQuery, rather than for testing only.
  • Modifies the toSql helper to accept Tokenable types.

…ue or not. Use function overloading to handle issue with incorrect nullability with no type arg.
@@ -7,6 +7,8 @@ export type PickByValue<T, ValueType> = Pick<
}[keyof T]
>;

export type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a comment for what this does?

"js"
],
"coveragePathIgnorePatterns": [
"__tests__",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code used __tests__ and __checks__ folders. Can we keep that structure or is that hard?

(If we're starting out with the hope that this fork goes away eventually, it might be nice to avoid unnecessary changes.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this for less ignore configuration in these files, but if you'd prefer I can switch it back.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think I'd prefer to leave it unchanged in this case, to stay close to the upstream code.

(I don't think that's always the right answer, e.g. changing the type testing library like a change that's worth it.)

src/insert.ts Outdated
@@ -327,7 +327,7 @@ export class InsertQuery<
>
? IsNotNull extends true
? DataType | Expression<DataType, IsNotNull, any> | Query<any>
: DataType | undefined | Expression<DataType, IsNotNull, any> | Query<any>
: DataType | null | Expression<DataType, IsNotNull, any> | Query<any>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth defining a type DbNull = null somewhere and using that everywhere instead of the literal null?

(Right now, when I see null, I'm not sure if it represents a DB null value or if it's just one of the normal TS uses of null.)

Copy link
Contributor

@cakoose cakoose left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I commented on a thread.

import { DefaultExpression, Expression } from './expression';

import { Query } from './query';
import { Table } from './TableType';

export interface Tokenable {
toTokens(): Token[];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird indentation...

I thought this project had a prettier?

@carterzenk carterzenk merged commit 707a866 into main Oct 14, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants