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 4bbd0aab
authored
Jan 31, 2014
by
Michael Schonfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
throw error for psql, and test for it
1 parent
52f5e51e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
19 deletions
lib/dialects/postgres/query-generator.js
test/dao-factory/create.test.js
lib/dialects/postgres/query-generator.js
View file @
4bbd0aa
...
...
@@ -267,7 +267,11 @@ module.exports = (function() {
})
},
bulkInsertQuery
:
function
(
tableName
,
attrValueHashes
)
{
bulkInsertQuery
:
function
(
tableName
,
attrValueHashes
,
options
)
{
if
(
options
&&
options
.
ignoreDuplicates
)
{
throw
new
Error
(
"Postgres does not support the 'ignoreDuplicates' option."
)
}
var
query
=
"INSERT INTO <%= table %> (<%= attributes %>) VALUES <%= tuples %> RETURNING *;"
,
tuples
=
[]
,
serials
=
[]
...
...
test/dao-factory/create.test.js
View file @
4bbd0aa
...
...
@@ -991,27 +991,43 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
it
(
"should support the insert ignoreDuplicates option"
,
function
(
done
)
{
var
self
=
this
,
data
=
[{
uniqueName
:
'Peter'
,
secretValue
:
'42'
},
{
uniqueName
:
'Paul'
,
secretValue
:
'23'
}]
this
.
User
.
bulkCreate
(
data
,
{
fields
:
[
'uniqueName'
,
'secretValue'
]
}).
success
(
function
()
{
data
.
push
({
uniqueName
:
'Michael'
,
secretValue
:
'26'
});
self
.
User
.
bulkCreate
(
data
,
{
fields
:
[
'uniqueName'
,
'secretValue'
],
ignoreDuplicates
:
true
}).
success
(
function
()
{
self
.
User
.
findAll
({
order
:
'id'
}).
success
(
function
(
users
)
{
expect
(
users
.
length
).
to
.
equal
(
3
)
expect
(
users
[
0
].
uniqueName
).
to
.
equal
(
"Peter"
)
expect
(
users
[
0
].
secretValue
).
to
.
equal
(
"42"
);
expect
(
users
[
1
].
uniqueName
).
to
.
equal
(
"Paul"
)
expect
(
users
[
1
].
secretValue
).
to
.
equal
(
"23"
);
expect
(
users
[
2
].
uniqueName
).
to
.
equal
(
"Michael"
)
expect
(
users
[
2
].
secretValue
).
to
.
equal
(
"26"
);
if
(
Support
.
getTestDialect
()
!==
'postgres'
)
{
it
(
"should support the ignoreDuplicates option"
,
function
(
done
)
{
var
self
=
this
,
data
=
[{
uniqueName
:
'Peter'
,
secretValue
:
'42'
},
{
uniqueName
:
'Paul'
,
secretValue
:
'23'
}]
this
.
User
.
bulkCreate
(
data
,
{
fields
:
[
'uniqueName'
,
'secretValue'
]
}).
success
(
function
()
{
data
.
push
({
uniqueName
:
'Michael'
,
secretValue
:
'26'
});
self
.
User
.
bulkCreate
(
data
,
{
fields
:
[
'uniqueName'
,
'secretValue'
],
ignoreDuplicates
:
true
}).
success
(
function
()
{
self
.
User
.
findAll
({
order
:
'id'
}).
success
(
function
(
users
)
{
expect
(
users
.
length
).
to
.
equal
(
3
)
expect
(
users
[
0
].
uniqueName
).
to
.
equal
(
"Peter"
)
expect
(
users
[
0
].
secretValue
).
to
.
equal
(
"42"
);
expect
(
users
[
1
].
uniqueName
).
to
.
equal
(
"Paul"
)
expect
(
users
[
1
].
secretValue
).
to
.
equal
(
"23"
);
expect
(
users
[
2
].
uniqueName
).
to
.
equal
(
"Michael"
)
expect
(
users
[
2
].
secretValue
).
to
.
equal
(
"26"
);
done
()
});
});
})
})
}
else
{
it
(
"should throw an error when the ignoreDuplicates option is passed"
,
function
(
done
)
{
var
self
=
this
,
data
=
[{
uniqueName
:
'Peter'
,
secretValue
:
'42'
},
{
uniqueName
:
'Paul'
,
secretValue
:
'23'
}]
this
.
User
.
bulkCreate
(
data
,
{
fields
:
[
'uniqueName'
,
'secretValue'
]
}).
success
(
function
()
{
data
.
push
({
uniqueName
:
'Michael'
,
secretValue
:
'26'
});
self
.
User
.
bulkCreate
(
data
,
{
fields
:
[
'uniqueName'
,
'secretValue'
],
ignoreDuplicates
:
true
}).
success
(
function
()
{
expect
(
err
.
message
).
to
.
match
(
/Postgres does not support the 'ignoreDuplicates' option./
);
done
()
});
})
;
})
})
}
)
}
describe
(
'enums'
,
function
()
{
it
(
'correctly restores enum values'
,
function
(
done
)
{
...
...
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