Skip to content

refactor(data-types): convert db2 data-types to TS - #14220

Closed
wbourne0 wants to merge 1 commit into
typeify-data-typesfrom
typeify-db2-data-types
Closed

wbourne0 wants to merge 1 commit into
typeify-data-typesfrom
typeify-db2-data-types

Conversation

@wbourne0

Copy link
Copy Markdown
Member

Note: This is a child PR of #13799 - it should only be merged into that branch when both this pr and that pr have been approved.

Description Of Change

converts db2-specific data-types and tests to TS.

Also refactors the data-types to work with the (proposed) format from the master pr, #13799.

@wbourne0 wbourne0 added type: refactor DEPRECATED: replace with the "meta" issue type typescript For issues and PRs. Things that involve typescript, such as typings and intellisense. dialect: db2 For issues and PRs. Things that involve db2 (and do not involve all dialects). labels Mar 10, 2022
@wbourne0 wbourne0 self-assigned this Mar 10, 2022
@wbourne0
wbourne0 force-pushed the typeify-db2-data-types branch from 4591eef to 915a5b7 Compare March 10, 2022 06:00
Comment on lines +181 to +202
protected _sanitize(value: RawTypeOf<BaseTypes.BOOLEAN>) {
if (value !== null && value !== undefined) {
if (Buffer.isBuffer(value) && value.length === 1) {
// Bit fields are returned as buffers
value = value[0];
}

if (typeof value === 'string') {
// Only take action on valid boolean strings.
value = value === 'true' ? true : value === 'false' ? false : value;
value = value === '\u0001' ? true : value === '\u0000' ? false : value;
} else if (typeof value === 'number') {
// Only take action on valid boolean integers.
value = value === 1 ? true : value === 0 ? false : value;
}
}

return typeof value === 'boolean' ? value : null;
}

static readonly parse = this.prototype._sanitize;
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note: this is kinda breaking since we'd default to returning value even if it wasn't a boolean.

I don't see why we'd get 4 different types for booleans in the same dialect, seems like a lot of this logic should be redundant imo.

}

export class STRING extends BaseTypes.STRING {
static readonly escape: false;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is super spooky imo.

IIRC I determined this was safe, though I don't remember exactly why.

I'm not entirely certain that _stringify is always going to be called when formatting a user's input, but assuming it is this is safe?


export class UUID extends BaseTypes.UUID {
toSql() {
return 'CHAR(36) FOR BIT DATA';

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not strictly DB2 related: This seems to be what we do in other dialects without proper UUID support too, but ideally we'd store it as a 16 byte buffer / binary instead.

This would reduce the size of uuids by >50% and in theory speed things up a lil' too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sounds good to me :)

Comment on lines +253 to +254
// @ts-expect-error what type is value?
value = value.string();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have no idea what type this is. In mysql this was the type the underlying lib returned and parse was called via mysql's connection-manager but it looked like db2 didn't use this (at least not in the same way mysql does) when I looked.

Comment on lines +350 to +354
export class ENUM<Member extends string> extends BaseTypes.ENUM<Member> {
toSql() {
return 'VARCHAR(255)';
}
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Should we drop support for this entirely? It seems misleading to support it as a string.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree, its constructor should throw & say to use DataTypes.STRING + the isIn column validator instead

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

My only concern with this is that it'll be pretty annoying to change w/ an upgrade.

Thoughts on leaving this for now and then in a different change add an ENUM_VIRTUAL datatype + deprecate fake enum usage?

@wbourne0
wbourne0 changed the base branch from main to typeify-data-types March 10, 2022 06:09
@wbourne0
wbourne0 force-pushed the typeify-db2-data-types branch from 915a5b7 to bc570fb Compare March 10, 2022 06:11
@wbourne0 wbourne0 changed the title Typeify db2 data types refactor(data-types): convert db2 data-types to TS Mar 10, 2022
@wbourne0
wbourne0 force-pushed the typeify-data-types branch from 6de690b to 210279c Compare March 12, 2022 05:20
Refactors db2-specific dialect types to be TS and to work with the new
DataTypes format.
@wbourne0
wbourne0 force-pushed the typeify-db2-data-types branch from bc570fb to 3b329bc Compare March 12, 2022 05:44
@ephys ephys mentioned this pull request May 13, 2022
38 of 42 tasks
@wbourne0

Copy link
Copy Markdown
Member Author

Closing in favor of #14505.

@wbourne0 wbourne0 closed this Sep 16, 2022
@ephys
ephys deleted the typeify-db2-data-types branch October 3, 2022 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dialect: db2 For issues and PRs. Things that involve db2 (and do not involve all dialects). type: refactor DEPRECATED: replace with the "meta" issue type typescript For issues and PRs. Things that involve typescript, such as typings and intellisense.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants