sails: error: function lower(enum_users_status) does not exist

From @slavafomin on August 8, 2016 22:36

Hello!

Thank you for this great library!

However, I’m having an error: function lower(enum_users_status) does not exist.

I’m not sure if this issue relates to this module or to waterline.

Here’s my other comment (left unnoticed): https://github.com/balderdashy/sails-postgresql/issues/99#issuecomment-236730862


The enum_users_status is a custom enumeration type used in our PostgreSQL database. The schema for it is:

CREATE TYPE "enum_users_status" AS ENUM (
  'foo',
  'bar',
  'baz'
);

Such database type should be easily mapped to string or text type.

It’s defined in my model as:

    status: {
      type: 'string',
      size: 20,
      enum: ['foo', 'bar', 'baz'],
      defaultsTo: 'foo',
      required: true
    }

What is the reason for this error? Such configuration works perfectly fine with Sequelize in our other project.

$ npm ls waterline
app
├─┬ sails@0.12.3
│ └── waterline@0.11.2 
└─┬ sails-hook-validation@0.4.6
  └── waterline@0.10.31

Please advise, thank you!

Copied from original issue: balderdashy/sails-postgresql#256

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (15 by maintainers)

Most upvoted comments

From @slavafomin on September 2, 2016 0:47

If someone will get into the same situation as me: the dirty workaround would be to create a lower function for each enumeration type. You can do so in PostgreSQL this way:

-- enum_users_gender
CREATE OR REPLACE FUNCTION lower(enum_users_gender) RETURNS text AS $$
  SELECT lower($1::text);
$$ LANGUAGE SQL;

It was a terrible mistake to ever use Sails.js and especially Waterline in our products. Seems like we will have to pay for this dearly…