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 2987d03c
authored
Dec 05, 2013
by
Mick Hansen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1105 from mulderr/features/uuid
Features/uuid
2 parents
d03d3c88
86c55eb4
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
3 deletions
lib/data-types.js
lib/utils.js
package.json
test/dao.test.js
test/data-types.test.js
lib/data-types.js
View file @
2987d03
...
@@ -188,6 +188,9 @@ module.exports = {
...
@@ -188,6 +188,9 @@ module.exports = {
FLOAT
:
FLOAT
,
FLOAT
:
FLOAT
,
NOW
:
'NOW'
,
NOW
:
'NOW'
,
BLOB
:
BLOB
,
BLOB
:
BLOB
,
UUID
:
'CHAR(36)'
,
UUIDV1
:
'UUIDV1'
,
UUIDV4
:
'UUIDV4'
,
get
ENUM
()
{
get
ENUM
()
{
var
result
=
function
()
{
var
result
=
function
()
{
...
...
lib/utils.js
View file @
2987d03
...
@@ -3,6 +3,7 @@ var util = require("util")
...
@@ -3,6 +3,7 @@ var util = require("util")
,
SqlString
=
require
(
"./sql-string"
)
,
SqlString
=
require
(
"./sql-string"
)
,
lodash
=
require
(
"lodash"
)
,
lodash
=
require
(
"lodash"
)
,
_string
=
require
(
'underscore.string'
)
,
_string
=
require
(
'underscore.string'
)
,
uuid
=
require
(
'node-uuid'
)
var
Utils
=
module
.
exports
=
{
var
Utils
=
module
.
exports
=
{
_
:
(
function
()
{
_
:
(
function
()
{
...
@@ -375,8 +376,14 @@ var Utils = module.exports = {
...
@@ -375,8 +376,14 @@ var Utils = module.exports = {
toDefaultValue
:
function
(
value
)
{
toDefaultValue
:
function
(
value
)
{
if
(
lodash
.
isFunction
(
value
))
{
if
(
lodash
.
isFunction
(
value
))
{
return
value
()
return
value
()
}
else
if
(
value
===
DataTypes
.
UUIDV1
)
{
return
uuid
.
v1
()
}
else
if
(
value
===
DataTypes
.
UUIDV4
)
{
return
uuid
.
v4
()
}
else
if
(
value
===
DataTypes
.
NOW
)
{
return
Utils
.
now
()
}
else
{
}
else
{
return
(
value
===
DataTypes
.
NOW
)
?
Utils
.
now
()
:
value
return
value
}
}
},
},
...
@@ -394,6 +401,8 @@ var Utils = module.exports = {
...
@@ -394,6 +401,8 @@ var Utils = module.exports = {
// have been normalized for this case
// have been normalized for this case
if
(
value
===
DataTypes
.
NOW
)
{
return
false
}
if
(
value
===
DataTypes
.
NOW
)
{
return
false
}
if
(
value
===
DataTypes
.
UUIDV1
||
value
===
DataTypes
.
UUIDV4
)
{
return
false
}
if
(
lodash
.
isFunction
(
value
))
{
if
(
lodash
.
isFunction
(
value
))
{
return
false
return
false
}
}
...
@@ -488,7 +497,6 @@ var Utils = module.exports = {
...
@@ -488,7 +497,6 @@ var Utils = module.exports = {
return
stack
;
return
stack
;
},
},
now
:
function
(
dialect
)
{
now
:
function
(
dialect
)
{
var
now
=
new
Date
()
var
now
=
new
Date
()
if
(
dialect
!=
"postgres"
)
now
.
setMilliseconds
(
0
)
if
(
dialect
!=
"postgres"
)
now
.
setMilliseconds
(
0
)
...
...
package.json
View file @
2987d03
...
@@ -46,7 +46,8 @@
...
@@ -46,7 +46,8 @@
"toposort-class"
:
"~0.2.0"
,
"toposort-class"
:
"~0.2.0"
,
"generic-pool"
:
"2.0.4"
,
"generic-pool"
:
"2.0.4"
,
"promise"
:
"~3.2.0"
,
"promise"
:
"~3.2.0"
,
"sql"
:
"~0.28.0"
"sql"
:
"~0.28.0"
,
"node-uuid"
:
"~1.4.1"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
"sqlite3"
:
"~2.1.12"
,
"sqlite3"
:
"~2.1.12"
,
...
...
test/dao.test.js
View file @
2987d03
...
@@ -7,6 +7,7 @@ var chai = require('chai')
...
@@ -7,6 +7,7 @@ var chai = require('chai')
,
config
=
require
(
__dirname
+
"/config/config"
)
,
config
=
require
(
__dirname
+
"/config/config"
)
,
sinon
=
require
(
'sinon'
)
,
sinon
=
require
(
'sinon'
)
,
datetime
=
require
(
'chai-datetime'
)
,
datetime
=
require
(
'chai-datetime'
)
,
uuid
=
require
(
'node-uuid'
)
,
_
=
require
(
'lodash'
)
,
_
=
require
(
'lodash'
)
chai
.
use
(
datetime
)
chai
.
use
(
datetime
)
...
@@ -16,6 +17,8 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
...
@@ -16,6 +17,8 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
beforeEach
(
function
(
done
)
{
beforeEach
(
function
(
done
)
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
{
type
:
DataTypes
.
STRING
},
username
:
{
type
:
DataTypes
.
STRING
},
uuidv1
:
{
type
:
DataTypes
.
UUID
,
defaultValue
:
DataTypes
.
UUIDV1
},
uuidv4
:
{
type
:
DataTypes
.
UUID
,
defaultValue
:
DataTypes
.
UUIDV4
},
touchedAt
:
{
type
:
DataTypes
.
DATE
,
defaultValue
:
DataTypes
.
NOW
},
touchedAt
:
{
type
:
DataTypes
.
DATE
,
defaultValue
:
DataTypes
.
NOW
},
aNumber
:
{
type
:
DataTypes
.
INTEGER
},
aNumber
:
{
type
:
DataTypes
.
INTEGER
},
bNumber
:
{
type
:
DataTypes
.
INTEGER
},
bNumber
:
{
type
:
DataTypes
.
INTEGER
},
...
@@ -568,6 +571,26 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
...
@@ -568,6 +571,26 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
})
})
describe
(
'default values'
,
function
()
{
describe
(
'default values'
,
function
()
{
describe
(
'uuid'
,
function
()
{
it
(
'should store a string in uuidv1 and uuidv4'
,
function
(
done
)
{
var
user
=
this
.
User
.
build
({
username
:
'a user'
})
expect
(
user
.
uuidv1
).
to
.
be
.
a
(
'string'
)
expect
(
user
.
uuidv4
).
to
.
be
.
a
(
'string'
)
done
()
})
it
(
'should store a string of length 36 in uuidv1 and uuidv4'
,
function
(
done
)
{
var
user
=
this
.
User
.
build
({
username
:
'a user'
})
expect
(
user
.
uuidv1
).
to
.
have
.
length
(
36
)
expect
(
user
.
uuidv4
).
to
.
have
.
length
(
36
)
done
()
})
it
(
'should store a valid uuid in uuidv1 and uuidv4 that can be parsed to something of length 16'
,
function
(
done
)
{
var
user
=
this
.
User
.
build
({
username
:
'a user'
})
expect
(
uuid
.
parse
(
user
.
uuidv1
)).
to
.
have
.
length
(
16
)
expect
(
uuid
.
parse
(
user
.
uuidv4
)).
to
.
have
.
length
(
16
)
done
()
})
})
describe
(
'current date'
,
function
()
{
describe
(
'current date'
,
function
()
{
it
(
'should store a date in touchedAt'
,
function
(
done
)
{
it
(
'should store a date in touchedAt'
,
function
(
done
)
{
var
user
=
this
.
User
.
build
({
username
:
'a user'
})
var
user
=
this
.
User
.
build
({
username
:
'a user'
})
...
...
test/data-types.test.js
View file @
2987d03
...
@@ -25,6 +25,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() {
...
@@ -25,6 +25,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() {
[
Sequelize
.
TEXT
,
'TEXT'
,
'TEXT'
],
[
Sequelize
.
TEXT
,
'TEXT'
,
'TEXT'
],
[
Sequelize
.
DATE
,
'DATE'
,
'DATETIME'
],
[
Sequelize
.
DATE
,
'DATE'
,
'DATETIME'
],
[
Sequelize
.
NOW
,
'NOW'
,
'NOW'
],
[
Sequelize
.
NOW
,
'NOW'
,
'NOW'
],
[
Sequelize
.
UUID
,
'UUID'
,
'CHAR(36)'
],
[
Sequelize
.
BOOLEAN
,
'BOOLEAN'
,
'TINYINT(1)'
],
[
Sequelize
.
BOOLEAN
,
'BOOLEAN'
,
'TINYINT(1)'
],
[
Sequelize
.
BLOB
,
'BLOB'
,
'BLOB'
],
[
Sequelize
.
BLOB
,
'BLOB'
,
'BLOB'
],
...
...
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