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 1163c545
authored
Jun 05, 2013
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'comments'
2 parents
590766b7
8d086786
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
3 deletions
lib/dialects/mysql/query-generator.js
lib/dialects/postgres/query-generator.js
spec-jasmine/mysql/dao-factory.spec.js
spec-jasmine/mysql/query-generator.spec.js
spec-jasmine/postgres/query-generator.spec.js
spec/emitters/custom-event-emitter.js → spec/emitters/custom-event-emitter.spec.js
lib/dialects/mysql/query-generator.js
View file @
1163c54
...
@@ -43,7 +43,7 @@ module.exports = (function() {
...
@@ -43,7 +43,7 @@ module.exports = (function() {
charset
:
null
charset
:
null
},
options
||
{})
},
options
||
{})
var
query
=
"CREATE TABLE IF NOT EXISTS <%= table %> (<%= attributes%>) ENGINE=<%= engine %> <%= charset %>"
var
query
=
"CREATE TABLE IF NOT EXISTS <%= table %> (<%= attributes%>)
<%= comment %>
ENGINE=<%= engine %> <%= charset %>"
,
primaryKeys
=
[]
,
primaryKeys
=
[]
,
foreignKeys
=
{}
,
foreignKeys
=
{}
,
attrStr
=
[]
,
attrStr
=
[]
...
@@ -69,6 +69,7 @@ module.exports = (function() {
...
@@ -69,6 +69,7 @@ module.exports = (function() {
var
values
=
{
var
values
=
{
table
:
this
.
quoteIdentifier
(
tableName
),
table
:
this
.
quoteIdentifier
(
tableName
),
attributes
:
attrStr
.
join
(
", "
),
attributes
:
attrStr
.
join
(
", "
),
comment
:
options
.
comment
&&
Utils
.
_
.
isString
(
options
.
comment
)
?
" COMMENT "
+
this
.
escape
(
options
.
comment
)
:
""
,
engine
:
options
.
engine
,
engine
:
options
.
engine
,
charset
:
(
options
.
charset
?
"DEFAULT CHARSET="
+
options
.
charset
:
""
)
charset
:
(
options
.
charset
?
"DEFAULT CHARSET="
+
options
.
charset
:
""
)
}
}
...
@@ -504,6 +505,10 @@ module.exports = (function() {
...
@@ -504,6 +505,10 @@ module.exports = (function() {
}
}
if
(
dataType
.
comment
&&
Utils
.
_
.
isString
(
dataType
.
comment
)
&&
dataType
.
comment
.
length
)
{
template
+=
" COMMENT "
+
Utils
.
escape
(
dataType
.
comment
)
}
result
[
name
]
=
template
result
[
name
]
=
template
}
else
{
}
else
{
result
[
name
]
=
dataType
result
[
name
]
=
dataType
...
...
lib/dialects/postgres/query-generator.js
View file @
1163c54
...
@@ -48,10 +48,22 @@ module.exports = (function() {
...
@@ -48,10 +48,22 @@ module.exports = (function() {
primaryKeys
[
tableName
]
=
[]
primaryKeys
[
tableName
]
=
[]
tables
[
tableName
]
=
{}
tables
[
tableName
]
=
{}
var
query
=
"CREATE TABLE IF NOT EXISTS <%= table %> (<%= attributes%>)"
var
query
=
"CREATE TABLE IF NOT EXISTS <%= table %> (<%= attributes%>)<%= comments %>"
,
comments
=
""
,
attrStr
=
[]
,
attrStr
=
[]
,
i
if
(
options
.
comment
&&
Utils
.
_
.
isString
(
options
.
comment
))
{
comments
+=
"; COMMENT ON TABLE <%= table %> IS "
+
this
.
escape
(
options
.
comment
)
}
for
(
var
attr
in
attributes
)
{
for
(
var
attr
in
attributes
)
{
if
((
i
=
attributes
[
attr
].
indexOf
(
'COMMENT'
))
!==
-
1
)
{
// Move comment to a seperate query
comments
+=
"; "
+
attributes
[
attr
].
substring
(
i
)
attributes
[
attr
]
=
attributes
[
attr
].
substring
(
0
,
i
)
}
var
dataType
=
this
.
pgDataTypeMapping
(
tableName
,
attr
,
attributes
[
attr
])
var
dataType
=
this
.
pgDataTypeMapping
(
tableName
,
attr
,
attributes
[
attr
])
attrStr
.
push
(
this
.
quoteIdentifier
(
attr
)
+
" "
+
dataType
)
attrStr
.
push
(
this
.
quoteIdentifier
(
attr
)
+
" "
+
dataType
)
...
@@ -62,7 +74,8 @@ module.exports = (function() {
...
@@ -62,7 +74,8 @@ module.exports = (function() {
var
values
=
{
var
values
=
{
table
:
this
.
quoteIdentifiers
(
tableName
),
table
:
this
.
quoteIdentifiers
(
tableName
),
attributes
:
attrStr
.
join
(
", "
)
attributes
:
attrStr
.
join
(
", "
),
comments
:
Utils
.
_
.
template
(
comments
,
{
table
:
this
.
quoteIdentifiers
(
tableName
)})
}
}
var
pks
=
primaryKeys
[
tableName
].
map
(
function
(
pk
){
var
pks
=
primaryKeys
[
tableName
].
map
(
function
(
pk
){
...
@@ -574,7 +587,13 @@ module.exports = (function() {
...
@@ -574,7 +587,13 @@ module.exports = (function() {
template
+=
" ON UPDATE <%= onUpdateAction %>"
template
+=
" ON UPDATE <%= onUpdateAction %>"
replacements
.
onUpdateAction
=
dataType
.
onUpdate
.
toUpperCase
()
replacements
.
onUpdateAction
=
dataType
.
onUpdate
.
toUpperCase
()
}
}
}
if
(
dataType
.
comment
&&
Utils
.
_
.
isString
(
dataType
.
comment
))
{
template
+=
" COMMENT ON COLUMN <%= tableName %>.<%= columnName %> IS <%= comment %>"
replacements
.
columnName
=
this
.
quoteIdentifier
(
name
)
replacements
.
tableName
=
'<%= table %>'
// Hacky, table name will be inserted by create table
replacements
.
comment
=
this
.
escape
(
dataType
.
comment
)
}
}
result
[
name
]
=
Utils
.
_
.
template
(
template
)(
replacements
)
result
[
name
]
=
Utils
.
_
.
template
(
template
)(
replacements
)
...
...
spec-jasmine/mysql/dao-factory.spec.js
View file @
1163c54
...
@@ -31,6 +31,13 @@ describe('DAOFactory', function() {
...
@@ -31,6 +31,13 @@ describe('DAOFactory', function() {
expect
(
User
.
attributes
).
toEqual
({
username
:
"VARCHAR(255) NOT NULL"
,
id
:
"INTEGER NOT NULL auto_increment PRIMARY KEY"
})
expect
(
User
.
attributes
).
toEqual
({
username
:
"VARCHAR(255) NOT NULL"
,
id
:
"INTEGER NOT NULL auto_increment PRIMARY KEY"
})
})
})
it
(
"handles extended attributes (comment)"
,
function
()
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
username
:
{
type
:
Sequelize
.
STRING
,
comment
:
'This be\'s a comment'
}
},
{
timestamps
:
false
})
expect
(
User
.
attributes
).
toEqual
({
username
:
"VARCHAR(255) COMMENT 'This be\\'s a comment'"
,
id
:
"INTEGER NOT NULL auto_increment PRIMARY KEY"
})
})
it
(
"handles extended attributes (primaryKey)"
,
function
()
{
it
(
"handles extended attributes (primaryKey)"
,
function
()
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
username
:
{
type
:
Sequelize
.
STRING
,
primaryKey
:
true
}
username
:
{
type
:
Sequelize
.
STRING
,
primaryKey
:
true
}
...
...
spec-jasmine/mysql/query-generator.spec.js
View file @
1163c54
...
@@ -45,6 +45,10 @@ describe('QueryGenerator', function() {
...
@@ -45,6 +45,10 @@ describe('QueryGenerator', function() {
expectation
:
{
id
:
'INTEGER UNIQUE'
}
expectation
:
{
id
:
'INTEGER UNIQUE'
}
},
},
{
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
comment
:
"I'm a comment!"
}}],
expectation
:
{
id
:
"INTEGER COMMENT 'I\\'m a comment!'"
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
references
:
'Bar'
}}],
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
references
:
'Bar'
}}],
expectation
:
{
id
:
'INTEGER REFERENCES `Bar` (`id`)'
}
expectation
:
{
id
:
'INTEGER REFERENCES `Bar` (`id`)'
}
},
},
...
@@ -72,6 +76,14 @@ describe('QueryGenerator', function() {
...
@@ -72,6 +76,14 @@ describe('QueryGenerator', function() {
expectation
:
"CREATE TABLE IF NOT EXISTS `myTable` (`title` VARCHAR(255), `name` VARCHAR(255)) ENGINE=InnoDB;"
expectation
:
"CREATE TABLE IF NOT EXISTS `myTable` (`title` VARCHAR(255), `name` VARCHAR(255)) ENGINE=InnoDB;"
},
},
{
{
arguments
:
[
'myTable'
,
{
title
:
"INTEGER COMMENT 'I\\'m a comment!'"
}],
expectation
:
"CREATE TABLE IF NOT EXISTS `myTable` (`title` INTEGER COMMENT 'I\\'m a comment!') ENGINE=InnoDB;"
,
},
{
arguments
:
[
'myTable'
,
{
title
:
"INTEGER"
},
{
comment
:
"I'm a comment!"
}],
expectation
:
"CREATE TABLE IF NOT EXISTS `myTable` (`title` INTEGER) COMMENT 'I\\'m a comment!' ENGINE=InnoDB;"
,
},
{
arguments
:
[
'myTable'
,
{
title
:
'VARCHAR(255)'
,
name
:
'VARCHAR(255)'
},
{
engine
:
'MyISAM'
}],
arguments
:
[
'myTable'
,
{
title
:
'VARCHAR(255)'
,
name
:
'VARCHAR(255)'
},
{
engine
:
'MyISAM'
}],
expectation
:
"CREATE TABLE IF NOT EXISTS `myTable` (`title` VARCHAR(255), `name` VARCHAR(255)) ENGINE=MyISAM;"
expectation
:
"CREATE TABLE IF NOT EXISTS `myTable` (`title` VARCHAR(255), `name` VARCHAR(255)) ENGINE=MyISAM;"
},
},
...
...
spec-jasmine/postgres/query-generator.spec.js
View file @
1163c54
...
@@ -49,6 +49,10 @@ describe('QueryGenerator', function() {
...
@@ -49,6 +49,10 @@ describe('QueryGenerator', function() {
expectation
:
{
id
:
'INTEGER UNIQUE'
}
expectation
:
{
id
:
'INTEGER UNIQUE'
}
},
},
{
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
comment
:
"I'm a comment!"
}}],
expectation
:
{
id
:
"INTEGER COMMENT ON COLUMN <%= table %>.\"id\" IS 'I''m a comment!'"
}
},
{
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
references
:
'Bar'
}}],
arguments
:
[{
id
:
{
type
:
'INTEGER'
,
references
:
'Bar'
}}],
expectation
:
{
id
:
'INTEGER REFERENCES "Bar" ("id")'
}
expectation
:
{
id
:
'INTEGER REFERENCES "Bar" ("id")'
}
},
},
...
@@ -104,6 +108,14 @@ describe('QueryGenerator', function() {
...
@@ -104,6 +108,14 @@ describe('QueryGenerator', function() {
expectation
:
"CREATE TABLE IF NOT EXISTS \"myTable\" (\"title\" VARCHAR(255), \"name\" VARCHAR(255));"
,
expectation
:
"CREATE TABLE IF NOT EXISTS \"myTable\" (\"title\" VARCHAR(255), \"name\" VARCHAR(255));"
,
},
},
{
{
arguments
:
[
'myTable'
,
{
title
:
"INTEGER COMMENT ON COLUMN <%= table %>.\"title\" IS 'I''m a comment!'"
}],
expectation
:
"CREATE TABLE IF NOT EXISTS \"myTable\" (\"title\" INTEGER ); COMMENT ON COLUMN \"myTable\".\"title\" IS 'I''m a comment!';"
,
},
{
arguments
:
[
'myTable'
,
{
title
:
"INTEGER"
},
{
comment
:
"I'm a comment!"
}],
expectation
:
"CREATE TABLE IF NOT EXISTS \"myTable\" (\"title\" INTEGER); COMMENT ON TABLE \"myTable\" IS 'I''m a comment!';"
,
},
{
arguments
:
[
'mySchema.myTable'
,
{
title
:
'VARCHAR(255)'
,
name
:
'VARCHAR(255)'
}],
arguments
:
[
'mySchema.myTable'
,
{
title
:
'VARCHAR(255)'
,
name
:
'VARCHAR(255)'
}],
expectation
:
"CREATE TABLE IF NOT EXISTS \"mySchema\".\"myTable\" (\"title\" VARCHAR(255), \"name\" VARCHAR(255));"
expectation
:
"CREATE TABLE IF NOT EXISTS \"mySchema\".\"myTable\" (\"title\" VARCHAR(255), \"name\" VARCHAR(255));"
},
},
...
...
spec/emitters/custom-event-emitter.js
→
spec/emitters/custom-event-emitter.
spec.
js
View file @
1163c54
File moved
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