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 2ad55a62
authored
Dec 04, 2013
by
mulderr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add uuid data type with uuidv1 and uuidv4 as possible default values
1 parent
d03d3c88
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 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 @
2ad55a6
...
...
@@ -188,6 +188,9 @@ module.exports = {
FLOAT
:
FLOAT
,
NOW
:
'NOW'
,
BLOB
:
BLOB
,
UUID
:
'CHAR(36)'
,
UUIDV1
:
'UUIDV1'
,
UUIDV4
:
'UUIDV4'
,
get
ENUM
()
{
var
result
=
function
()
{
...
...
lib/utils.js
View file @
2ad55a6
...
...
@@ -3,6 +3,7 @@ var util = require("util")
,
SqlString
=
require
(
"./sql-string"
)
,
lodash
=
require
(
"lodash"
)
,
_string
=
require
(
'underscore.string'
)
,
uuid
=
require
(
'node-uuid'
)
var
Utils
=
module
.
exports
=
{
_
:
(
function
()
{
...
...
@@ -375,8 +376,14 @@ var Utils = module.exports = {
toDefaultValue
:
function
(
value
)
{
if
(
lodash
.
isFunction
(
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
{
return
(
value
===
DataTypes
.
NOW
)
?
Utils
.
now
()
:
value
return
value
}
},
...
...
@@ -488,7 +495,6 @@ var Utils = module.exports = {
return
stack
;
},
now
:
function
(
dialect
)
{
var
now
=
new
Date
()
if
(
dialect
!=
"postgres"
)
now
.
setMilliseconds
(
0
)
...
...
package.json
View file @
2ad55a6
...
...
@@ -46,7 +46,8 @@
"toposort-class"
:
"~0.2.0"
,
"generic-pool"
:
"2.0.4"
,
"promise"
:
"~3.2.0"
,
"sql"
:
"~0.28.0"
"sql"
:
"~0.28.0"
,
"node-uuid"
:
"~1.4.1"
},
"devDependencies"
:
{
"sqlite3"
:
"~2.1.12"
,
...
...
test/dao.test.js
View file @
2ad55a6
...
...
@@ -7,6 +7,7 @@ var chai = require('chai')
,
config
=
require
(
__dirname
+
"/config/config"
)
,
sinon
=
require
(
'sinon'
)
,
datetime
=
require
(
'chai-datetime'
)
,
uuid
=
require
(
'node-uuid'
)
,
_
=
require
(
'lodash'
)
chai
.
use
(
datetime
)
...
...
@@ -16,6 +17,8 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
beforeEach
(
function
(
done
)
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
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
},
aNumber
:
{
type
:
DataTypes
.
INTEGER
},
bNumber
:
{
type
:
DataTypes
.
INTEGER
},
...
...
@@ -568,6 +571,26 @@ describe(Support.getTestDialectTeaser("DAO"), 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
()
{
it
(
'should store a date in touchedAt'
,
function
(
done
)
{
var
user
=
this
.
User
.
build
({
username
:
'a user'
})
...
...
test/data-types.test.js
View file @
2ad55a6
...
...
@@ -25,6 +25,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() {
[
Sequelize
.
TEXT
,
'TEXT'
,
'TEXT'
],
[
Sequelize
.
DATE
,
'DATE'
,
'DATETIME'
],
[
Sequelize
.
NOW
,
'NOW'
,
'NOW'
],
[
Sequelize
.
UUID
,
'UUID'
,
'CHAR(36)'
],
[
Sequelize
.
BOOLEAN
,
'BOOLEAN'
,
'TINYINT(1)'
],
[
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