feathers-plus / cli

FeathersJS CLI supporting both REST and GraphQL architectural concepts and their query languages.
https://generator.feathers-plus.com/
Other
43 stars 7 forks source link

Service fields in mongo/mongoose/sequelize are all string/TEXT, even for numbers #36

Closed Madsn closed 5 years ago

Madsn commented 5 years ago

Steps to reproduce

Expected behavior

I would expect the generated mongo/sequelize/mongoose files contain properties/fields of the same (or equivalent) type as specified in .schema.ts

Actual behavior

All properties are created as string for mongo/mongoose, and TEXT for sequelize. *.schema.ts

  properties: {
    // !code: schema_properties
    rank: Number,
    initials: String,
    count: Number
    // !end
  },

*.mongo.ts

let moduleExports = merge({},
  // !<DEFAULT> code: model
  {
    bsonType: "object",
    additionalProperties: false,
    properties: {
      _id: {
        bsonType: "objectId"
      },
      rank: {
        bsonType: "string"
      },
      initials: {
        bsonType: "string"
      },
      count: {
        bsonType: "string"
      }
    }
  },
  // !end
  // !code: moduleExports // !end
);

*.mongoose.ts

let moduleExports = merge({},
  // !<DEFAULT> code: model
  {
    rank: String,
    initials: String,
    count: String
  },
  // !end
  // !code: moduleExports // !end
);

*.sequelize.ts

let moduleExports = merge({},
  // !<DEFAULT> code: sequelize_model
  {
    rank: {
      type: DataTypes.TEXT
    },
    initials: {
      type: DataTypes.TEXT
    },
    count: {
      type: DataTypes.TEXT
    }
  } as DefineAttributes,
  // !end
  // !code: moduleExports // !end
);

System configuration

Tell us about the applicable parts of your setup.

Module versions (especially the part that's not working):

    "@feathers-plus/test-utils": "^0.3.6",
    "@feathersjs/authentication": "^2.1.16",
    "@feathersjs/authentication-jwt": "^2.0.10",
    "@feathersjs/authentication-local": "^1.2.9",
    "@feathersjs/configuration": "^2.0.6",
    "@feathersjs/errors": "^3.3.6",
    "@feathersjs/express": "^1.3.1",
    "@feathersjs/feathers": "^3.3.1",
    "@feathersjs/socketio": "^3.2.9",
   (...)
    "mongodb-core": "^3.2.3",
    "mongoose": "^5.5.1",

NodeJS version:

λ node -v
v11.12.0

Operating System: Windows 10 Browser Version: Not relevant React Native Version: Not relevant Module Loader: Don't know / Not relevant

Madsn commented 5 years ago

Ahh sorry, I realize my mistake now.

For others who, like me, don't read the documentation closely enough, the correct syntax in .schema.ts is:

  // Fields in the model.
  properties: {
    // !code: schema_properties
    likes: { type: 'integer', required: true },
    timestamp: { type: 'integer', required: true },
    type: { type: 'string', required: true },
    initials: { type: 'string', required: true }
    // !end
  },