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 1b7be3e8
authored
Dec 29, 2013
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix blank bulkCreates in postgres
1 parent
022cf04a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
3 deletions
lib/dialects/postgres/query-generator.js
test/associations/has-many.test.js
test/dao-factory/create.test.js
lib/dialects/postgres/query-generator.js
View file @
1b7be3e
...
@@ -295,11 +295,24 @@ module.exports = (function() {
...
@@ -295,11 +295,24 @@ module.exports = (function() {
bulkInsertQuery
:
function
(
tableName
,
attrValueHashes
)
{
bulkInsertQuery
:
function
(
tableName
,
attrValueHashes
)
{
var
query
=
"INSERT INTO <%= table %> (<%= attributes %>) VALUES <%= tuples %> RETURNING *;"
var
query
=
"INSERT INTO <%= table %> (<%= attributes %>) VALUES <%= tuples %> RETURNING *;"
,
tuples
=
[]
,
tuples
=
[]
,
serials
=
[]
Utils
.
_
.
forEach
(
attrValueHashes
,
function
(
attrValueHash
,
i
)
{
if
(
i
===
0
)
{
Utils
.
_
.
forEach
(
attrValueHash
,
function
(
value
,
key
,
hash
)
{
if
(
tables
[
tableName
]
&&
tables
[
tableName
][
key
])
{
if
([
'bigserial'
,
'serial'
].
indexOf
(
tables
[
tableName
][
key
])
!==
-
1
)
{
serials
.
push
(
key
)
}
}
})
}
Utils
.
_
.
forEach
(
attrValueHashes
,
function
(
attrValueHash
)
{
removeSerialsFromHash
(
tableName
,
attrValueHash
)
tuples
.
push
(
"("
+
tuples
.
push
(
"("
+
Utils
.
_
.
values
(
attrValueHash
).
map
(
function
(
value
){
Utils
.
_
.
map
(
attrValueHash
,
function
(
value
,
key
){
if
(
serials
.
indexOf
(
key
)
!==
-
1
)
{
return
'DEFAULT'
;
}
return
this
.
escape
(
value
)
return
this
.
escape
(
value
)
}.
bind
(
this
)).
join
(
","
)
+
}.
bind
(
this
)).
join
(
","
)
+
")"
)
")"
)
...
...
test/associations/has-many.test.js
View file @
1b7be3e
...
@@ -915,6 +915,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -915,6 +915,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
})
})
})
})
})
})
}).
on
(
'sql'
,
function
(
sql
)
{
console
.
log
(
sql
)
})
})
})
})
})
})
...
...
test/dao-factory/create.test.js
View file @
1b7be3e
...
@@ -883,6 +883,17 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -883,6 +883,17 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})
})
it
(
'should allow blank creates (with timestamps: false)'
,
function
(
done
)
{
var
Worker
=
this
.
sequelize
.
define
(
'Worker'
,
{},
{
timestamps
:
false
})
Worker
.
sync
().
done
(
function
(
err
)
{
Worker
.
bulkCreate
([{},
{}]).
done
(
function
(
err
,
workers
)
{
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
workers
).
to
.
be
.
ok
done
()
})
})
})
describe
(
'enums'
,
function
()
{
describe
(
'enums'
,
function
()
{
it
(
'correctly restores enum values'
,
function
(
done
)
{
it
(
'correctly restores enum values'
,
function
(
done
)
{
var
self
=
this
var
self
=
this
...
...
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