nodejs-itoolkit icon indicating copy to clipboard operation
nodejs-itoolkit copied to clipboard

feat: Add data type wrappers

Open abmusse opened this issue 5 years ago • 3 comments

Resolves #75 Resolves #77

abmusse avatar Jan 20 '21 20:01 abmusse

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.

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 type key set to the return value.

abmusse avatar Jan 21 '21 00:01 abmusse

I think we also should we add checks to enforce length parameter was passed for

  • Char
  • Varchar
  • LongVarchar

As is if no length is provided to these functions we end up something like this:

> const { Varchar } = require('itoolkit');

> console.log({...itoolkit.Varchar()})
{ type: 'undefineda', varying: '2' }

Check could be something like ...

function Varchar(length) {
  if (!length) { throw TypeError('Must provide valid length for Varchar'); }
  return { type: `${length}a`, varying: '2' };
}
> const { Varchar } = require('itoolkit');

> console.log({...itoolkit.Varchar()})
Uncaught TypeError: Must provide length for Varchar

Alternatively we could have a default length or no-op when no length is passed.

abmusse avatar Jan 21 '21 00:01 abmusse

:wave: Hi! This pull request has been marked stale due to inactivity. If no further activity occurs, it will automatically be closed.

github-actions[bot] avatar Feb 21 '21 00:02 github-actions[bot]