Reputation: 3225
I would like to know how can i define a bigint type in a waterline model using sails-mysql? Couldn't find any proper documentation about it. Seems like it doesn't support bigint types however i really need it. Trying to dig over the sourcecode i found something liek this: https://github.com/balderdashy/sails-mysql/blob/987f4674785970951bc52becdfdb479864106da1/helpers/private/schema/build-schema.js#L29 But it's still not working.
module.exports = {
attributes: {
userId: {
type: 'bigint',
autoIncrement: true,
primaryKey: true,
unique: true,
},
}
};
This one still keeps creating an integer field in the database.
Upvotes: 3
Views: 1338
Reputation: 2038
Edit: I hadn't tested this thoroughly. It isn't working, after all.
The property size
isn't allowed for model attributes in Sails v1.0+, but this seems to work. I pulled it from the definition of the createdAt
attribute in the waterline library (line 485, as of this writing).
module.exports = {
attributes: {
timeOfDay: {
type: 'number',
autoMigrations: { columnType: '_numbertimestamp' }
}
}
};
Upvotes: -1
Reputation: 567
Another way is to use the following attributes:
{
type: 'string',
columnType: 'bigint'
}
This ignores Waterline data types and forces Postgres/MySQL column data type directly.
Upvotes: -1
Reputation: 3225
Ok after digging through the source code a bit more i figured that i have to set an extra property called size for the field. Setting it to 64 will cause waterline to create a BIGINT field.
module.exports = {
attributes: {
userId: {
type: 'integer',
size: 64, // waterline will translate this as bigint
autoIncrement: true,
primaryKey: true,
unique: true,
},
}
};
Upvotes: 5