Repository navigation
Conversation
4591eef to
915a5b7
Compare
| 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; | ||
| } |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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.
| // @ts-expect-error what type is value? | ||
| value = value.string(); |
There was a problem hiding this comment.
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.
| export class ENUM<Member extends string> extends BaseTypes.ENUM<Member> { | ||
| toSql() { | ||
| return 'VARCHAR(255)'; | ||
| } | ||
| } |
There was a problem hiding this comment.
Should we drop support for this entirely? It seems misleading to support it as a string.
There was a problem hiding this comment.
I agree, its constructor should throw & say to use DataTypes.STRING + the isIn column validator instead
There was a problem hiding this comment.
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?
915a5b7 to
bc570fb
Compare
6de690b to
210279c
Compare
Refactors db2-specific dialect types to be TS and to work with the new DataTypes format.
bc570fb to
3b329bc
Compare
|
Closing in favor of #14505. |
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.