Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit f6d2b478
authored
Oct 15, 2018
by
Justin Kalland
Committed by
Sushant
Oct 16, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(sqlite): CITEXT datatype (#10036)
1 parent
198cb52d
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
23 additions
and
7 deletions
docs/models-definition.md
lib/data-types.js
lib/dialects/sqlite/data-types.js
lib/instance-validator.js
test/integration/data-types.test.js
test/integration/model/create.test.js
test/integration/model/findAll.test.js
test/integration/model/findOne.test.js
docs/models-definition.md
View file @
f6d2b47
...
...
@@ -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
...
...
lib/data-types.js
View file @
f6d2b47
...
...
@@ -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
*/
...
...
lib/dialects/sqlite/data-types.js
View file @
f6d2b47
...
...
@@ -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
)
=>
{
...
...
lib/instance-validator.js
View file @
f6d2b47
...
...
@@ -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`
,
...
...
test/integration/data-types.test.js
View file @
f6d2b47
...
...
@@ -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
{
...
...
test/integration/model/create.test.js
View file @
f6d2b47
...
...
@@ -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
}
...
...
test/integration/model/findAll.test.js
View file @
f6d2b47
...
...
@@ -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
...
...
test/integration/model/findOne.test.js
View file @
f6d2b47
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment