不要怂,就是干,撸起袖子干!

Commit f6d2b478 by Justin Kalland Committed by Sushant

feat(sqlite): CITEXT datatype (#10036)

1 parent 198cb52d
......@@ -120,7 +120,7 @@ Sequelize.STRING(1234) // VARCHAR(1234)
Sequelize.STRING.BINARY // VARCHAR BINARY
Sequelize.TEXT // TEXT
Sequelize.TEXT('tiny') // TINYTEXT
Sequelize.CITEXT // CITEXT PostgreSQL only.
Sequelize.CITEXT // CITEXT PostgreSQL and SQLite only.
Sequelize.INTEGER // INTEGER
Sequelize.BIGINT // BIGINT
......
......@@ -143,7 +143,7 @@ TEXT.prototype.validate = function validate(value) {
/**
* An unlimited length case-insensitive text column.
* Original case is preserved but acts case-insensitive when comparing values (such as when finding or unique constraints).
* Only available in Postgres.
* Only available in Postgres and SQLite.
*
* @namespace DataTypes.CITEXT
*/
......
......@@ -108,6 +108,16 @@ module.exports = BaseTypes => {
return 'TEXT';
};
function CITEXT() {
if (!(this instanceof CITEXT)) return new CITEXT();
BaseTypes.CITEXT.apply(this, arguments);
}
inherits(CITEXT, BaseTypes.CITEXT);
CITEXT.prototype.toSql = function toSql() {
return 'TEXT COLLATE NOCASE';
};
function CHAR(length, binary) {
if (!(this instanceof CHAR)) return new CHAR(length, binary);
BaseTypes.CHAR.apply(this, arguments);
......@@ -280,7 +290,8 @@ module.exports = BaseTypes => {
BIGINT,
TEXT,
ENUM,
JSON: JSONTYPE
JSON: JSONTYPE,
CITEXT
};
_.forIn(exports, (DataType, key) => {
......
......@@ -346,7 +346,7 @@ class InstanceValidator {
}
}
if (rawAttribute.type instanceof DataTypes.STRING || rawAttribute.type instanceof DataTypes.TEXT) {
if (rawAttribute.type instanceof DataTypes.STRING || rawAttribute.type instanceof DataTypes.TEXT || rawAttribute.type instanceof DataTypes.CITEXT) {
if (Array.isArray(value) || _.isObject(value) && !(value instanceof Utils.SequelizeMethod) && !Buffer.isBuffer(value)) {
this.errors.push(new sequelizeError.ValidationErrorItem(
`${field} cannot be an array or an object`,
......
......@@ -285,6 +285,11 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => {
it('calls parse and stringify for CITEXT', () => {
const Type = new Sequelize.CITEXT();
if (dialect === 'sqlite') {
// The "field type" sqlite returns is TEXT so is covered under TEXT test above
return;
}
if (dialect === 'postgres') {
return testSuccess(Type, 'foobar');
} else {
......
......@@ -998,7 +998,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
if (dialect === 'postgres') {
if (dialect === 'postgres' || dialect === 'sqlite') {
it("doesn't allow case-insensitive duplicated records using CITEXT", function () {
const User = this.sequelize.define('UserWithUniqueCITEXT', {
username: {type: Sequelize.CITEXT, unique: true}
......
......@@ -475,7 +475,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
if (dialect === 'postgres') {
if (dialect === 'postgres' || dialect === 'sqlite') {
it('should be able to find multiple users with case-insensitive on CITEXT type', function() {
const User = this.sequelize.define('UsersWithCaseInsensitiveName', {
username: Sequelize.CITEXT
......
......@@ -288,7 +288,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
if (dialect === 'postgres') {
if (dialect === 'postgres' || dialect === 'sqlite') {
it('should allow case-insensitive find on CITEXT type', function() {
const User = this.sequelize.define('UserWithCaseInsensitiveName', {
username: Sequelize.CITEXT
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!