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 0d639ca8
authored
Oct 12, 2012
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed boolean to tinyint conversion for sqlite
1 parent
6dab07a8
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
13 deletions
lib/dialects/mysql/query-generator.js
lib/dialects/sqlite/query-generator.js
spec/associations/has-many.spec.js
lib/dialects/mysql/query-generator.js
View file @
0d639ca
...
...
@@ -149,7 +149,7 @@ module.exports = (function() {
}
if
(
options
.
where
)
{
options
.
where
=
QueryGenerator
.
getWhereConditions
(
options
.
where
,
tableName
)
options
.
where
=
this
.
getWhereConditions
(
options
.
where
,
tableName
)
query
+=
" WHERE <%= where %>"
}
...
...
@@ -290,10 +290,10 @@ module.exports = (function() {
if
(
Utils
.
isHash
(
smth
))
{
smth
=
Utils
.
prependTableNameToHash
(
tableName
,
smth
)
result
=
QueryGenerator
.
hashToWhereConditions
(
smth
)
result
=
this
.
hashToWhereConditions
(
smth
)
}
else
if
(
typeof
smth
===
'number'
)
{
smth
=
Utils
.
prependTableNameToHash
(
tableName
,
{
id
:
smth
})
result
=
QueryGenerator
.
hashToWhereConditions
(
smth
)
result
=
this
.
hashToWhereConditions
(
smth
)
}
else
if
(
typeof
smth
===
"string"
)
{
result
=
smth
}
else
if
(
Array
.
isArray
(
smth
))
{
...
...
lib/dialects/sqlite/query-generator.js
View file @
0d639ca
var
Utils
=
require
(
"../../utils"
)
,
util
=
require
(
"util"
)
var
MySqlQueryGenerator
=
Utils
.
_
.
extend
(
Utils
.
_
.
clone
(
require
(
"../query-generator"
)),
Utils
.
_
.
clone
(
require
(
"../mysql/query-generator"
))
)
var
hashToWhereConditions
=
MySqlQueryGenerator
.
hashToWhereConditions
var
escape
=
function
(
str
)
{
if
(
typeof
str
===
'string'
)
{
...
...
@@ -24,6 +29,7 @@ module.exports = (function() {
,
attrStr
=
[]
for
(
var
attr
in
attributes
)
{
if
(
attributes
.
hasOwnProperty
(
attr
))
{
var
dataType
=
attributes
[
attr
]
if
(
Utils
.
_
.
includes
(
dataType
,
'PRIMARY KEY'
))
{
...
...
@@ -32,6 +38,7 @@ module.exports = (function() {
attrStr
.
push
(
Utils
.
addTicks
(
attr
)
+
" "
+
dataType
)
}
}
}
var
values
=
{
table
:
Utils
.
addTicks
(
tableName
),
...
...
@@ -129,21 +136,34 @@ module.exports = (function() {
var
fields
=
[]
for
(
var
name
in
factory
.
attributes
)
{
if
(
factory
.
attributes
.
hasOwnProperty
(
name
))
{
var
definition
=
factory
.
attributes
[
name
]
if
(
definition
&&
(
definition
.
indexOf
(
'INTEGER PRIMARY KEY'
)
==
0
))
{
if
(
definition
&&
(
definition
.
indexOf
(
'INTEGER PRIMARY KEY'
)
=
==
0
))
{
fields
.
push
(
name
)
}
}
}
return
fields
},
hashToWhereConditions
:
function
(
hash
)
{
for
(
var
key
in
hash
)
{
if
(
hash
.
hasOwnProperty
(
key
))
{
var
value
=
hash
[
key
]
if
(
typeof
value
===
'boolean'
)
{
value
=
!!
value
?
1
:
0
}
hash
[
key
]
=
value
}
}
var
MySqlQueryGenerator
=
Utils
.
_
.
extend
(
Utils
.
_
.
clone
(
require
(
"../query-generator"
)),
Utils
.
_
.
clone
(
require
(
"../mysql/query-generator"
))
)
return
hashToWhereConditions
(
hash
)
}
}
return
Utils
.
_
.
extend
(
MySqlQueryGenerator
,
QueryGenerator
)
})()
spec/associations/has-many.spec.js
View file @
0d639ca
...
...
@@ -215,9 +215,9 @@ dialects.forEach(function(dialect) {
})
})
it
(
"only get objects that ful
lfi
l the options"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}
}).
success
(
function
(
john
)
{
john
.
getTasks
({
where
:
{
active
:
true
},
limit
:
10
,
order
:
'ID DESC'
}).
success
(
function
(
tasks
)
{
it
(
"only get objects that ful
fil
l the options"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}
}).
success
(
function
(
john
)
{
john
.
getTasks
({
where
:
{
active
:
true
},
limit
:
10
,
order
:
'id DESC'
}).
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
1
)
done
();
})
...
...
@@ -259,7 +259,7 @@ dialects.forEach(function(dialect) {
})
})
it
(
"only get objects that ful
lfi
l the options"
,
function
(
done
)
{
it
(
"only get objects that ful
fil
l the options"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
john
.
getTasks
({
where
:
{
active
:
true
}}).
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
1
)
...
...
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