-
Notifications
You must be signed in to change notification settings - Fork 37
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
feat: Add data type wrappers #321
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks OK to me. I'd probably group them by type instead of alphabetically. Might want to add aliases to the Signed* functions without the "Signed" (ie. Int, BigInt, etc).
Does the spread operator work when the value is a string instead of an object? If not, I think the functions should all return objects.
lib/Types.js
Outdated
return '8F4'; | ||
} | ||
|
||
/** | ||
* @returns {string} - The float data type format expected by xml service. | ||
*/ | ||
function Float() { | ||
return '4F2'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that it's case sensitive, but for consistency I think we should use lowercase f in the types returned here.
lib/Types.js
Outdated
* @param {number} decimalDigits - The number of decimal digits. | ||
* @returns {string} - The packed data type format expected by xml service. | ||
*/ | ||
function Packed(totalDigits, decimalDigits) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems more clear as PackedDecimal. Same goes for Zoned later.
Spread operator does work on strings but not in the way we want. It essentially will split each character in the string with a space: function SignedBigInt() {
return '20i0';
}
console.log('Signed Big Int:', ...SignedBigInt()) // Signed Big Int: 2 0 i 0 I agree we should return an object with |
I think we also should we add checks to enforce length parameter was passed for
As is if no length is provided to these functions we end up something like this:
Check could be something like ... function Varchar(length) {
if (!length) { throw TypeError('Must provide valid length for Varchar'); }
return { type: `${length}a`, varying: '2' };
}
Alternatively we could have a default length or no-op when no length is passed. |
👋 Hi! This pull request has been marked stale due to inactivity. If no further activity occurs, it will automatically be closed. |
lib/Types.js
Outdated
* data - data value name (tag) | ||
* values - value, | ||
* type | ||
* 3i0 int8/byte D myint8 3i 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 3i0 int8/byte D myint8 3i 0 | |
* xmlservice C/SQL Fixed-format RPG | |
* 3i0 int8/byte D myint8 3i 0 |
Maybe add a header?
I think it would also be nicer to space out the columns a bit and maybe put in some separator bars. The RPG example is a bit close to the "C" example.
lib/Types.js
Outdated
* 32a {varying2} varchar D mychar 32a varying | ||
* 32a {varying4} varchar4 D mychar 32a varying(4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 32a {varying2} varchar D mychar 32a varying | |
* 32a {varying4} varchar4 D mychar 32a varying(4) | |
* 32a (varying=2) varchar D mychar 32a varying | |
* 32a (varying=4) varchar4 D mychar 32a varying(4) |
lib/Types.js
Outdated
* 5u0 uint16/ushort D myint16 5u 0 | ||
* 10u0 uint32/uint D myint32 10u 0 | ||
* 20u0 uint64/uint64 D myint64 20u 0 | ||
* 32a char D mychar 32a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 32a char D mychar 32a | |
* 32a char[32] D mychar 32a |
lib/Types.js
Outdated
const Short = SignedShort; | ||
|
||
/** | ||
* @returns {string} The unsigned big int (int64) data type format expected by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these @returns
be adjusted? They don't actually return a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup these need to updated to return objects instead.
Resolves #75
Resolves #77