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 c28aef7a
authored
Jun 15, 2014
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support for bit fields as boolean storage. Closes #1896
1 parent
6fa8afe9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
0 deletions
lib/instance.js
test/dao-factory/find.test.js
lib/instance.js
View file @
c28aef7
...
@@ -305,6 +305,10 @@ module.exports = (function() {
...
@@ -305,6 +305,10 @@ module.exports = (function() {
// Convert boolean-ish values to booleans
// Convert boolean-ish values to booleans
if
(
this
.
Model
.
_hasBooleanAttributes
&&
this
.
Model
.
_isBooleanAttribute
(
key
)
&&
value
!==
null
&&
value
!==
undefined
&&
!
value
.
_isSequelizeMethod
)
{
if
(
this
.
Model
.
_hasBooleanAttributes
&&
this
.
Model
.
_isBooleanAttribute
(
key
)
&&
value
!==
null
&&
value
!==
undefined
&&
!
value
.
_isSequelizeMethod
)
{
if
(
Buffer
.
isBuffer
(
value
)
&&
value
.
length
===
1
)
{
// Bit fields are returned as buffers
value
=
value
[
0
];
}
value
=
!!
value
;
value
=
!!
value
;
}
}
...
...
test/dao-factory/find.test.js
View file @
c28aef7
...
@@ -73,6 +73,40 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -73,6 +73,40 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})
})
if
(
Support
.
dialectIsMySQL
())
{
// Bit fields interpreted as boolean need conversion from buffer / bool.
// Sqlite returns the inserted value as is, and postgres really should the built in bool type instead
it
(
'allows bit fields as booleans'
,
function
()
{
var
self
=
this
,
bitUser
=
this
.
sequelize
.
define
(
'bituser'
,
{
bool
:
'BIT(1)'
},
{
timestamps
:
false
});
// First use a custom data type def to create the bit field
return
bitUser
.
sync
({
force
:
true
}).
then
(
function
()
{
// Then change the definition to BOOLEAN
bitUser
=
self
.
sequelize
.
define
(
'bituser'
,
{
bool
:
DataTypes
.
BOOLEAN
},
{
timestamps
:
false
});
return
bitUser
.
bulkCreate
([
{
bool
:
0
},
{
bool
:
1
}
]);
}).
then
(
function
()
{
return
bitUser
.
findAll
();
}).
then
(
function
(
bitUsers
)
{
expect
(
bitUsers
[
0
].
bool
).
not
.
to
.
be
.
ok
;
expect
(
bitUsers
[
1
].
bool
).
to
.
be
.
ok
;
});
});
}
it
(
'does not modify the passed arguments'
,
function
(
done
)
{
it
(
'does not modify the passed arguments'
,
function
(
done
)
{
var
options
=
{
where
:
[
'specialkey = ?'
,
'awesome'
]}
var
options
=
{
where
:
[
'specialkey = ?'
,
'awesome'
]}
...
...
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