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

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