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 9474edb4
authored
Aug 20, 2010
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added Sequelize.BOOLEAN
1 parent
3fb4bb81
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
5 deletions
README.md
src/Sequelize.js
src/SequelizeHelper.js
src/SequelizeTable.js
test/SequelizeTableTest.js
README.md
View file @
9474edb
...
@@ -34,6 +34,14 @@ To define mappings between a class (_Stop telling me that JavaScript don't know
...
@@ -34,6 +34,14 @@ To define mappings between a class (_Stop telling me that JavaScript don't know
description: Sequelize.TEXT,
description: Sequelize.TEXT,
deadline: Sequelize.DATE
deadline: Sequelize.DATE
})
})
Sequelize currently supports the following datatypes:
Sequelize.STRING ===> VARCHAR(255)
Sequelize.TEXT ===> TEXT
Sequelize.INTEGER ===> INT
Sequelize.DATE ===> DATETIME
Sequelize.BOOLEAN ===> TINYINT(1)
## Creation and deletion of class tables ##
## Creation and deletion of class tables ##
...
...
src/Sequelize.js
View file @
9474edb
...
@@ -16,6 +16,7 @@ var classMethods = {
...
@@ -16,6 +16,7 @@ var classMethods = {
TEXT
:
'TEXT'
,
TEXT
:
'TEXT'
,
INTEGER
:
'INT'
,
INTEGER
:
'INT'
,
DATE
:
'DATETIME'
,
DATE
:
'DATETIME'
,
BOOLEAN
:
'TINYINT(1) NOT NULL'
,
sqlQueryFor
:
function
(
command
,
values
)
{
sqlQueryFor
:
function
(
command
,
values
)
{
var
query
=
null
var
query
=
null
...
...
src/SequelizeHelper.js
View file @
9474edb
...
@@ -43,7 +43,7 @@ SequelizeHelper = {
...
@@ -43,7 +43,7 @@ SequelizeHelper = {
valuesForInsertQuery
:
function
(
object
)
{
valuesForInsertQuery
:
function
(
object
)
{
var
actualValues
=
object
.
values
,
var
actualValues
=
object
.
values
,
result
=
[]
result
=
[]
SequelizeHelper
.
Hash
.
forEach
(
actualValues
,
function
(
value
,
key
)
{
SequelizeHelper
.
Hash
.
forEach
(
actualValues
,
function
(
value
,
key
)
{
var
dataType
=
object
.
table
.
attributes
[
key
]
var
dataType
=
object
.
table
.
attributes
[
key
]
result
.
push
(
SequelizeHelper
.
SQL
.
transformValueByDataType
(
value
,
dataType
))
result
.
push
(
SequelizeHelper
.
SQL
.
transformValueByDataType
(
value
,
dataType
))
...
@@ -60,6 +60,9 @@ SequelizeHelper = {
...
@@ -60,6 +60,9 @@ SequelizeHelper = {
if
((
value
==
null
)
||
(
typeof
value
==
'undefined'
))
if
((
value
==
null
)
||
(
typeof
value
==
'undefined'
))
return
"NULL"
return
"NULL"
if
(
dataType
.
indexOf
(
Sequelize
.
BOOLEAN
)
>
-
1
)
return
(
value
===
true
?
1
:
0
)
if
(
dataType
.
indexOf
(
Sequelize
.
INTEGER
)
>
-
1
)
if
(
dataType
.
indexOf
(
Sequelize
.
INTEGER
)
>
-
1
)
return
value
return
value
...
...
src/SequelizeTable.js
View file @
9474edb
...
@@ -9,8 +9,12 @@ SequelizeTable = function(sequelize, tableName, attributes) {
...
@@ -9,8 +9,12 @@ SequelizeTable = function(sequelize, tableName, attributes) {
var
table
=
function
(
values
)
{
var
table
=
function
(
values
)
{
var
self
=
this
var
self
=
this
SequelizeHelper
.
Hash
.
forEach
(
values
,
function
(
value
,
key
)
{
SequelizeHelper
.
Hash
.
forEach
(
values
,
function
(
value
,
key
)
{
if
(
attributes
[
key
])
if
(
attributes
[
key
])
{
self
[
key
]
=
value
if
(
attributes
[
key
]
==
Sequelize
.
BOOLEAN
)
{
self
[
key
]
=
((
value
==
1
)
||
(
value
==
true
))
?
true
:
false
}
else
self
[
key
]
=
value
}
})
})
this
.
id
=
null
// specify id as null to declare this object as unsaved and as not present in the database
this
.
id
=
null
// specify id as null to declare this object as unsaved and as not present in the database
this
.
table
=
table
this
.
table
=
table
...
@@ -301,7 +305,7 @@ SequelizeTable = function(sequelize, tableName, attributes) {
...
@@ -301,7 +305,7 @@ SequelizeTable = function(sequelize, tableName, attributes) {
var
self
=
this
var
self
=
this
SequelizeHelper
.
Hash
.
keys
(
table
.
attributes
).
forEach
(
function
(
attribute
)
{
SequelizeHelper
.
Hash
.
keys
(
table
.
attributes
).
forEach
(
function
(
attribute
)
{
result
[
attribute
]
=
self
[
attribute
]
||
null
result
[
attribute
]
=
(
typeof
self
[
attribute
]
==
"undefined"
)
?
null
:
self
[
attribute
]
})
})
return
result
return
result
...
@@ -331,7 +335,7 @@ SequelizeTable = function(sequelize, tableName, attributes) {
...
@@ -331,7 +335,7 @@ SequelizeTable = function(sequelize, tableName, attributes) {
updateAttributes
:
function
(
newValues
,
callback
)
{
updateAttributes
:
function
(
newValues
,
callback
)
{
var
self
=
this
var
self
=
this
SequelizeHelper
.
Hash
.
keys
(
table
.
attributes
).
forEach
(
function
(
attribute
)
{
SequelizeHelper
.
Hash
.
keys
(
table
.
attributes
).
forEach
(
function
(
attribute
)
{
if
(
newValues
[
attribute
]
)
if
(
typeof
newValues
[
attribute
]
!=
'undefined'
)
self
[
attribute
]
=
newValues
[
attribute
]
self
[
attribute
]
=
newValues
[
attribute
]
})
})
this
.
save
(
callback
)
this
.
save
(
callback
)
...
...
test/SequelizeTableTest.js
View file @
9474edb
...
@@ -301,5 +301,19 @@ module.exports = {
...
@@ -301,5 +301,19 @@ module.exports = {
assert
.
equal
(
true
,
IsAssociatedWithTestOne
.
isAssociatedWith
(
IsAssociatedWithTestTwo
,
'belongsTo'
))
assert
.
equal
(
true
,
IsAssociatedWithTestOne
.
isAssociatedWith
(
IsAssociatedWithTestTwo
,
'belongsTo'
))
assert
.
equal
(
false
,
IsAssociatedWithTestOne
.
isAssociatedWith
(
IsAssociatedWithTestTwo
,
'hasMany'
))
assert
.
equal
(
false
,
IsAssociatedWithTestOne
.
isAssociatedWith
(
IsAssociatedWithTestTwo
,
'hasMany'
))
assert
.
equal
(
false
,
IsAssociatedWithTestOne
.
isAssociatedWith
(
IsAssociatedWithTestTwo
,
'hasOne'
))
assert
.
equal
(
false
,
IsAssociatedWithTestOne
.
isAssociatedWith
(
IsAssociatedWithTestTwo
,
'hasOne'
))
},
'boolean ==> save'
:
function
(
assert
,
beforeExit
)
{
var
BooleanTest
=
s
.
define
(
"BooleanTest"
,
{
flag
:
Sequelize
.
BOOLEAN
})
var
testIsFinished
=
false
BooleanTest
.
sync
(
function
()
{
new
BooleanTest
({
flag
:
true
}).
save
(
function
(
obj
)
{
assert
.
equal
(
obj
.
flag
,
true
)
obj
.
updateAttributes
({
flag
:
false
},
function
(
obj2
)
{
assert
.
equal
(
obj2
.
flag
,
false
)
testIsFinished
=
true
})
})
})
beforeExit
(
function
()
{
assert
.
equal
(
true
,
testIsFinished
)
})
}
}
}
}
\ No newline at end of file
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