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

add support for direct postgres types #23

Open
sooraj1002 opened this issue Apr 16, 2024 · 0 comments
Open

add support for direct postgres types #23

sooraj1002 opened this issue Apr 16, 2024 · 0 comments

Comments

@sooraj1002
Copy link
Collaborator

the following field types should be mapped to the relevant prisma types.

we can use this as a starter.

    case 'BIGINT':
    case 'INT8':
    case 'BIGSERIAL':
    case 'SERIAL8':
    case 'INTEGER':
    case 'INT':
    case 'INT4':
    case 'SMALLINT':
    case 'INT2':
    case 'SMALLSERIAL':
    case 'SERIAL2':
    case 'SERIAL':
    case 'SERIAL4':
      return typeof singleValue === 'number' && Number.isInteger(singleValue);

    case 'BIT':
    case 'BIT VARYING':
    case 'VARBIT':
      return typeof singleValue === 'string' && bitPattern.test(singleValue);

    case 'BOOLEAN':
    case 'BOOL':
      return typeof singleValue === 'boolean';

    case 'BYTEA':
      return typeof singleValue === 'string';

    case 'CHARACTER':
    case 'CHAR':
    case 'CHARACTER VARYING':
    case 'VARCHAR':
    case 'TEXT':
      return typeof singleValue === 'string';

    case 'CIDR':
      return typeof singleValue === 'string' && cidrPattern.test(singleValue);

    case 'INET':
      return typeof singleValue === 'string' && inetPattern.test(singleValue);

    case 'MACADDR':
      return (
        typeof singleValue === 'string' && macaddrPattern.test(singleValue)
      );

    case 'UUID':
      return typeof singleValue === 'string' && uuidPattern.test(singleValue);

    case 'JSON':
    case 'JSONB':
      try {
        JSON.parse(singleValue);
        return true;
      } catch (e) {
        return false;
      }

    case 'NUMERIC':
    case 'DECIMAL':
    case 'MONEY':
    case 'DOUBLE PRECISION':
    case 'FLOAT8':
    case 'REAL':
    case 'FLOAT4':
    case 'FLOAT':
      return typeof singleValue === 'number';

    case 'DATE':
    case 'TIME':
    case 'TIME WITH TIME ZONE':
    case 'TIMETZ':
    case 'TIMESTAMP':
    case 'TIMESTAMP WITH TIME ZONE':
    case 'TIMESTAMPTZ':
      return typeof singleValue === 'string';
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

No branches or pull requests

1 participant