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
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
21 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() {
...
@@ -149,7 +149,7 @@ module.exports = (function() {
}
}
if
(
options
.
where
)
{
if
(
options
.
where
)
{
options
.
where
=
QueryGenerator
.
getWhereConditions
(
options
.
where
,
tableName
)
options
.
where
=
this
.
getWhereConditions
(
options
.
where
,
tableName
)
query
+=
" WHERE <%= where %>"
query
+=
" WHERE <%= where %>"
}
}
...
@@ -290,10 +290,10 @@ module.exports = (function() {
...
@@ -290,10 +290,10 @@ module.exports = (function() {
if
(
Utils
.
isHash
(
smth
))
{
if
(
Utils
.
isHash
(
smth
))
{
smth
=
Utils
.
prependTableNameToHash
(
tableName
,
smth
)
smth
=
Utils
.
prependTableNameToHash
(
tableName
,
smth
)
result
=
QueryGenerator
.
hashToWhereConditions
(
smth
)
result
=
this
.
hashToWhereConditions
(
smth
)
}
else
if
(
typeof
smth
===
'number'
)
{
}
else
if
(
typeof
smth
===
'number'
)
{
smth
=
Utils
.
prependTableNameToHash
(
tableName
,
{
id
:
smth
})
smth
=
Utils
.
prependTableNameToHash
(
tableName
,
{
id
:
smth
})
result
=
QueryGenerator
.
hashToWhereConditions
(
smth
)
result
=
this
.
hashToWhereConditions
(
smth
)
}
else
if
(
typeof
smth
===
"string"
)
{
}
else
if
(
typeof
smth
===
"string"
)
{
result
=
smth
result
=
smth
}
else
if
(
Array
.
isArray
(
smth
))
{
}
else
if
(
Array
.
isArray
(
smth
))
{
...
...
lib/dialects/sqlite/query-generator.js
View file @
0d639ca
var
Utils
=
require
(
"../../utils"
)
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
)
{
var
escape
=
function
(
str
)
{
if
(
typeof
str
===
'string'
)
{
if
(
typeof
str
===
'string'
)
{
...
@@ -24,12 +29,14 @@ module.exports = (function() {
...
@@ -24,12 +29,14 @@ module.exports = (function() {
,
attrStr
=
[]
,
attrStr
=
[]
for
(
var
attr
in
attributes
)
{
for
(
var
attr
in
attributes
)
{
var
dataType
=
attributes
[
attr
]
if
(
attributes
.
hasOwnProperty
(
attr
))
{
var
dataType
=
attributes
[
attr
]
if
(
Utils
.
_
.
includes
(
dataType
,
'PRIMARY KEY'
))
{
if
(
Utils
.
_
.
includes
(
dataType
,
'PRIMARY KEY'
))
{
attrStr
.
push
(
Utils
.
addTicks
(
attr
)
+
" "
+
dataType
)
attrStr
.
push
(
Utils
.
addTicks
(
attr
)
+
" "
+
dataType
)
}
else
{
}
else
{
attrStr
.
push
(
Utils
.
addTicks
(
attr
)
+
" "
+
dataType
)
attrStr
.
push
(
Utils
.
addTicks
(
attr
)
+
" "
+
dataType
)
}
}
}
}
}
...
@@ -129,21 +136,34 @@ module.exports = (function() {
...
@@ -129,21 +136,34 @@ module.exports = (function() {
var
fields
=
[]
var
fields
=
[]
for
(
var
name
in
factory
.
attributes
)
{
for
(
var
name
in
factory
.
attributes
)
{
var
definition
=
factory
.
attributes
[
name
]
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
)
fields
.
push
(
name
)
}
}
}
}
}
return
fields
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
}
}
return
hashToWhereConditions
(
hash
)
}
}
}
}
var
MySqlQueryGenerator
=
Utils
.
_
.
extend
(
Utils
.
_
.
clone
(
require
(
"../query-generator"
)),
Utils
.
_
.
clone
(
require
(
"../mysql/query-generator"
))
)
return
Utils
.
_
.
extend
(
MySqlQueryGenerator
,
QueryGenerator
)
return
Utils
.
_
.
extend
(
MySqlQueryGenerator
,
QueryGenerator
)
})()
})()
spec/associations/has-many.spec.js
View file @
0d639ca
...
@@ -215,9 +215,9 @@ dialects.forEach(function(dialect) {
...
@@ -215,9 +215,9 @@ 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
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}
}).
success
(
function
(
john
)
{
john
.
getTasks
({
where
:
{
active
:
true
},
limit
:
10
,
order
:
'ID DESC'
}).
success
(
function
(
tasks
)
{
john
.
getTasks
({
where
:
{
active
:
true
},
limit
:
10
,
order
:
'id DESC'
}).
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
1
)
expect
(
tasks
.
length
).
toEqual
(
1
)
done
();
done
();
})
})
...
@@ -259,7 +259,7 @@ dialects.forEach(function(dialect) {
...
@@ -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
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
john
.
getTasks
({
where
:
{
active
:
true
}}).
success
(
function
(
tasks
)
{
john
.
getTasks
({
where
:
{
active
:
true
}}).
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
1
)
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